Version Description
= 0.6.0 = Much improved translation interface engine = 0.5.7 = Fix for critical bug in 0.5.6 = 0.5.6 = Support pluggable widgets = 0.5.5 = Support for buddypress URLs = 0.5.3 = Support URL translation = 0.5.2 = Improved lang attribute support, changed default language translation option = 0.5.1 = Improved speed and database structure = 0.5.0 = Ability to translate all content, backup service for human translations = 0.4.3 = Minor bug fixes, more compatability = 0.4.2 = This version provides Haitian support, auto translate with bing support = 0.4.0 = This version provides integration with google-sitemaps-xml and wp-super-cache = 0.3.9 = This version allows sorting of languages within the widget
Download this release
Release Info
Developer | oferwald |
Plugin | Transposh WordPress Translation |
Version | 0.6.2 |
Comparing to | |
See all releases |
Code changes from version 0.6.1 to 0.6.2
- core/constants.php +80 -80
- core/parser.php +36 -33
- core/utils.php +318 -317
- js/lazy.js +10 -0
- js/transposh.js +14 -4
- js/transposhadmin.js +18 -8
- js/transposhcontrol.js +15 -4
- js/transposhedit.js +11 -1
- readme.txt +16 -1
- transposh.php +110 -153
- widgets/dropdown/tpw_image_dropdown.php +9 -15
- widgets/flags/tpw_flags.php +10 -16
- widgets/flags/tpw_flags_css.php +10 -16
- widgets/flagslist/tpw_list_with_flags.php +10 -16
- widgets/flagslist/tpw_list_with_flags_css.php +10 -16
- widgets/tpw_default.php +9 -15
- wp/transposh_3rdparty.php +190 -0
- wp/transposh_admin.php +25 -24
- wp/transposh_ajax.php +23 -58
- wp/transposh_backup.php +83 -73
- wp/transposh_db.php +67 -17
- wp/transposh_options.php +123 -125
- wp/transposh_postpublish.php +12 -19
- wp/transposh_widget.php +16 -22
core/constants.php
CHANGED
@@ -1,20 +1,14 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
|
|
|
|
4 |
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
-
* (at your option) any later version.
|
9 |
*
|
10 |
-
*
|
11 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
* GNU General Public License for more details.
|
14 |
-
*
|
15 |
-
* You should have received a copy of the GNU General Public License
|
16 |
-
* along with this program; if not, write to the Free Software
|
17 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
19 |
|
20 |
//Language indicator in URL. i.e. lang=en
|
@@ -31,88 +25,94 @@ define('NO_TRANSLATE_CLASS', 'no_translate');
|
|
31 |
define('NO_TRANSLATE_CLASS_GOOGLE', 'notranslate');
|
32 |
define('ONLY_THISLANGUAGE_CLASS', 'only_thislanguage');
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
//Supported languages, new languages can be added here
|
35 |
//the array directs from language code to - English Name, Native name, flag
|
36 |
-
$languages = array(
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
);
|
96 |
-
|
97 |
//Language which are read from right to left (rtl)
|
98 |
-
$rtl_languages = array('ar', 'he', 'fa', 'ur', 'yi');
|
99 |
-
|
100 |
//Google supported languages
|
101 |
//(got using - var langs =''; jQuery.each(google.language.Languages,function(){if (google.language.isTranslatable(this)) {langs += this +'|'}}); console.log(langs); - fixed for our codes)
|
102 |
//@updated 2010-Jul-01 (hy,az,eu,ka,ur)
|
103 |
//$google_languages = array('en', 'af', 'sq', 'ar', 'hy', 'az', 'eu', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'ka', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'ur', 'vi', 'cy', 'yi');
|
104 |
-
$google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi');
|
105 |
-
$google_proxied_languages = array('hy','az','eu','ka','ur');
|
106 |
//Bing supported languages
|
107 |
//(got this using Microsoft.Translator.GetLanguages() - fixed to match our codes)
|
108 |
//@updated 2010-Jun-30
|
109 |
-
$bing_languages = array('en', 'ar', 'bg', 'zh', 'zh-tw', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'de', 'el', 'ht', 'he', 'hu', 'it', 'ja', 'ko', 'lv', 'lt', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'es', 'sv', 'th', 'tr');
|
|
|
|
|
|
|
110 |
|
111 |
//Define the new capability that will be assigned to roles - translator
|
112 |
define('TRANSLATOR', 'translator');
|
113 |
|
114 |
//Define for transposh plugin version
|
115 |
-
define('TRANSPOSH_PLUGIN_VER', '0.6.
|
116 |
|
117 |
//Define segment id prefix, will be included in span tag. also used as class identifier
|
118 |
define('SPAN_PREFIX', 'tr_');
|
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
|
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 |
+
*/
|
31 |
+
class transposh_consts {
|
32 |
+
|
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');
|
|
|
97 |
//Google supported languages
|
98 |
//(got using - var langs =''; jQuery.each(google.language.Languages,function(){if (google.language.isTranslatable(this)) {langs += this +'|'}}); console.log(langs); - fixed for our codes)
|
99 |
//@updated 2010-Jul-01 (hy,az,eu,ka,ur)
|
100 |
//$google_languages = array('en', 'af', 'sq', 'ar', 'hy', 'az', 'eu', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'ka', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'ur', 'vi', 'cy', 'yi');
|
101 |
+
public static $google_languages = array('en', 'af', 'sq', 'ar', 'be', 'bg', 'ca', 'zh', 'zh-tw', 'hr', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'gl', 'de', 'el', 'ht', 'he', 'hi', 'hu', 'id', 'it', 'is', 'ga', 'ja', 'ko', 'lv', 'lt', 'mk', 'ms', 'mt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'sl', 'es', 'sw', 'sv', 'tl', 'th', 'tr', 'uk', 'vi', 'cy', 'yi');
|
102 |
+
public static $google_proxied_languages = array('hy', 'az', 'eu', 'ka', 'ur');
|
103 |
//Bing supported languages
|
104 |
//(got this using Microsoft.Translator.GetLanguages() - fixed to match our codes)
|
105 |
//@updated 2010-Jun-30
|
106 |
+
public static $bing_languages = array('en', 'ar', 'bg', 'zh', 'zh-tw', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'de', 'el', 'ht', 'he', 'hu', 'it', 'ja', 'ko', 'lv', 'lt', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'es', 'sv', 'th', 'tr');
|
107 |
+
|
108 |
+
|
109 |
+
}
|
110 |
|
111 |
//Define the new capability that will be assigned to roles - translator
|
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_');
|
core/parser.php
CHANGED
@@ -1,20 +1,14 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
|
|
|
|
4 |
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
-
* (at your option) any later version.
|
9 |
*
|
10 |
-
*
|
11 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
* GNU General Public License for more details.
|
14 |
-
*
|
15 |
-
* You should have received a copy of the GNU General Public License
|
16 |
-
* along with this program; if not, write to the Free Software
|
17 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
19 |
|
20 |
require_once("shd/simple_html_dom.php");
|
@@ -152,9 +146,9 @@ class parser {
|
|
152 |
* @return int length of entity
|
153 |
*/
|
154 |
function is_html_entity($string, $position) {
|
155 |
-
if ($string[$position] ==
|
156 |
$end_pos = $position + 1;
|
157 |
-
while ($string[$end_pos] ==
|
158 |
++$end_pos;
|
159 |
if ($string[$end_pos] == ';') return $end_pos - $position + 1;
|
160 |
}
|
@@ -279,9 +273,9 @@ class parser {
|
|
279 |
}
|
280 |
|
281 |
/**
|
282 |
-
* Create a
|
283 |
-
* @param int $start - beginning of
|
284 |
-
* @param int $end - end of
|
285 |
*/
|
286 |
function tag_phrase($string, $start, $end) {
|
287 |
$phrase = trim(substr($string, $start, $end - $start));
|
@@ -376,12 +370,21 @@ class parser {
|
|
376 |
* it currently also rewrites urls, and should consider if this is smart
|
377 |
* @param simple_html_dom_node $node
|
378 |
*/
|
379 |
-
function translate_tagging($node, $level = 0) {
|
380 |
$this->currentnode = $node;
|
381 |
// we don't want to translate non-translatable classes
|
382 |
-
if (stripos($node->class, NO_TRANSLATE_CLASS) !== false ||
|
383 |
-
|
384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
|
386 |
if ($this->inselect && $level <= $this->inselect)
|
387 |
$this->inselect = false;
|
@@ -398,7 +401,7 @@ class parser {
|
|
398 |
$this->inbody = true;
|
399 |
}
|
400 |
// this again should be here, the different behaviour on select and textarea
|
401 |
-
elseif ($node->tag == 'select' || $node->tag == 'textarea') {
|
402 |
$this->inselect = $level;
|
403 |
}
|
404 |
|
@@ -472,15 +475,15 @@ class parser {
|
|
472 |
function create_edit_span($original_text, $translated_text, $source, $for_hidden_element = false) {
|
473 |
// Use base64 encoding to make that when the page is translated (i.e. update_translation) we
|
474 |
// get back exactlly the same string without having the client decode/encode it in anyway.
|
475 |
-
$span = '<span class ="' . SPAN_PREFIX . '" id="' . SPAN_PREFIX . $this->segment_id . '" data-token="' . base64_url_encode($original_text) . "
|
476 |
// those are needed for on the fly image creation / hidden elements translations
|
477 |
if ($this->is_edit_mode || $for_hidden_element) {
|
478 |
-
$span .=
|
479 |
if ($for_hidden_element) {
|
480 |
$span.= ' data-hidden="y"';
|
481 |
// hidden elements currently have issues figuring what they translated in the JS
|
482 |
if ($translated_text != null) {
|
483 |
-
$span.=
|
484 |
}
|
485 |
}
|
486 |
}
|
@@ -498,7 +501,7 @@ class parser {
|
|
498 |
$publoc = strpos($value, 'pub-');
|
499 |
$sufloc = strpos($value, '"', $publoc);
|
500 |
if (!$sufloc) $sufloc = strpos($value, "'", $publoc);
|
501 |
-
echo $publoc .
|
502 |
if ($publoc && $sufloc)
|
503 |
$this->html->noise[$key] = substr($value, 0, $publoc) . 'pub-7523823497771676' . substr($value, $sufloc);
|
504 |
}
|
@@ -519,8 +522,8 @@ class parser {
|
|
519 |
$this->translate_tagging($this->html->root);
|
520 |
|
521 |
// first fix the html tag itself - we might need to to the same for all such attributes with flipping
|
522 |
-
if ($this->dir_rtl) $this->html->find('html', 0)->dir =
|
523 |
-
else $this->html->find('html', 0)->dir =
|
524 |
|
525 |
if ($this->lang) {
|
526 |
$this->html->find('html', 0)->lang = $this->lang;
|
@@ -599,7 +602,7 @@ class parser {
|
|
599 |
if ($source == 0) $this->stats->human_translated_phrases++;
|
600 |
}
|
601 |
if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null))/* && $ep->inbody */) {
|
602 |
-
$spanend =
|
603 |
if ($ep->inselect || !$ep->inbody) {
|
604 |
$savedspan .= $this->create_edit_span($ep->phrase, $translated_text, $source, true) . $spanend;
|
605 |
$span = '';
|
@@ -627,7 +630,7 @@ class parser {
|
|
627 |
// hmm?
|
628 |
if (!$ep->inselect && $savedspan && $ep->inbody) {
|
629 |
$e->outertext = $savedspan . $e->outertext;
|
630 |
-
$savedspan =
|
631 |
}
|
632 |
}
|
633 |
|
@@ -661,11 +664,11 @@ class parser {
|
|
661 |
}
|
662 |
if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null)) && $ep->inbody) {
|
663 |
// prevent duplicate translation (title = text)
|
664 |
-
if (strpos($e->innertext, base64_url_encode($ep->phrase)) === false) {
|
665 |
//no need to translate span the same hidden phrase more than once
|
666 |
if (!in_array($ep->phrase, $hidden_phrases)) {
|
667 |
$this->stats->hidden_translateable_phrases++;
|
668 |
-
$span .= $this->create_edit_span($ep->phrase, $translated_text, $source, true) .
|
669 |
//
|
670 |
$hidden_phrases[] = $ep->phrase;
|
671 |
}
|
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");
|
146 |
* @return int length of entity
|
147 |
*/
|
148 |
function is_html_entity($string, $position) {
|
149 |
+
if ($string[$position] == '&') {
|
150 |
$end_pos = $position + 1;
|
151 |
+
while ($string[$end_pos] == '#' || $this->is_digit($string[$end_pos]) || $this->is_a_to_z_character($string[$end_pos]))
|
152 |
++$end_pos;
|
153 |
if ($string[$end_pos] == ';') return $end_pos - $position + 1;
|
154 |
}
|
273 |
}
|
274 |
|
275 |
/**
|
276 |
+
* Create a phrase tag in the html dom tree
|
277 |
+
* @param int $start - beginning of phrase in element
|
278 |
+
* @param int $end - end of phrase in element
|
279 |
*/
|
280 |
function tag_phrase($string, $start, $end) {
|
281 |
$phrase = trim(substr($string, $start, $end - $start));
|
370 |
* it currently also rewrites urls, and should consider if this is smart
|
371 |
* @param simple_html_dom_node $node
|
372 |
*/
|
373 |
+
function translate_tagging($node, $level = 0, $lang = null) {
|
374 |
$this->currentnode = $node;
|
375 |
// we don't want to translate non-translatable classes
|
376 |
+
if (stripos($node->class, NO_TRANSLATE_CLASS) !== false || stripos($node->class, NO_TRANSLATE_CLASS_GOOGLE) !== false)
|
377 |
+
return;
|
378 |
+
|
379 |
+
// the node lang is the current node lang or its parent lang
|
380 |
+
$lang = $node->lang ? $node->lang : $lang;
|
381 |
+
// we avoid processing if the node lang is the target lang, however - we recurse with that lang
|
382 |
+
if (strtolower($lang) === $this->lang) {
|
383 |
+
foreach ($node->nodes as $c) {
|
384 |
+
$this->translate_tagging($c, $level + 1, $lang);
|
385 |
+
}
|
386 |
+
return;
|
387 |
+
}
|
388 |
|
389 |
if ($this->inselect && $level <= $this->inselect)
|
390 |
$this->inselect = false;
|
401 |
$this->inbody = true;
|
402 |
}
|
403 |
// this again should be here, the different behaviour on select and textarea
|
404 |
+
elseif ($node->tag == 'select' || $node->tag == 'textarea' || $node->tag == 'noscript') {
|
405 |
$this->inselect = $level;
|
406 |
}
|
407 |
|
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 . '"';
|
482 |
if ($for_hidden_element) {
|
483 |
$span.= ' data-hidden="y"';
|
484 |
// hidden elements currently have issues figuring what they translated in the JS
|
485 |
if ($translated_text != null) {
|
486 |
+
$span.= ' data-trans="' . $translated_text . '"';
|
487 |
}
|
488 |
}
|
489 |
}
|
501 |
$publoc = strpos($value, 'pub-');
|
502 |
$sufloc = strpos($value, '"', $publoc);
|
503 |
if (!$sufloc) $sufloc = strpos($value, "'", $publoc);
|
504 |
+
echo $publoc . ' ' . $sufloc;
|
505 |
if ($publoc && $sufloc)
|
506 |
$this->html->noise[$key] = substr($value, 0, $publoc) . 'pub-7523823497771676' . substr($value, $sufloc);
|
507 |
}
|
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
|
525 |
+
if ($this->dir_rtl) $this->html->find('html', 0)->dir = 'rtl';
|
526 |
+
else $this->html->find('html', 0)->dir = 'ltr';
|
527 |
|
528 |
if ($this->lang) {
|
529 |
$this->html->find('html', 0)->lang = $this->lang;
|
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 = '';
|
630 |
// hmm?
|
631 |
if (!$ep->inselect && $savedspan && $ep->inbody) {
|
632 |
$e->outertext = $savedspan . $e->outertext;
|
633 |
+
$savedspan = '';
|
634 |
}
|
635 |
}
|
636 |
|
664 |
}
|
665 |
if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null)) && $ep->inbody) {
|
666 |
// prevent duplicate translation (title = text)
|
667 |
+
if (strpos($e->innertext, transposh_utils::base64_url_encode($ep->phrase)) === false) {
|
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 |
}
|
core/utils.php
CHANGED
@@ -1,20 +1,14 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
|
|
|
|
4 |
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
-
* (at your option) any later version.
|
9 |
*
|
10 |
-
*
|
11 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
* GNU General Public License for more details.
|
14 |
-
*
|
15 |
-
* You should have received a copy of the GNU General Public License
|
16 |
-
* along with this program; if not, write to the Free Software
|
17 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
19 |
|
20 |
/**
|
@@ -26,369 +20,376 @@ require_once("constants.php");
|
|
26 |
|
27 |
|
28 |
/**
|
29 |
-
*
|
30 |
-
* Return the scrubed url
|
31 |
*/
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
}
|
43 |
-
}
|
44 |
-
// clean the query
|
45 |
-
unset($parsedurl['query']);
|
46 |
-
if (isset($params) && $params) {
|
47 |
-
$parsedurl['query'] = implode('&', $params);
|
48 |
-
}
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
|
55 |
|
56 |
-
$
|
57 |
-
$gluebackhome = true;
|
58 |
-
}
|
59 |
-
|
60 |
-
if (strlen($parsedurl['path']) > 2) {
|
61 |
-
$secondslashpos = strpos($parsedurl['path'], "/", 1);
|
62 |
-
if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
|
63 |
-
$prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1);
|
64 |
-
if (isset($GLOBALS['languages'][$prevlang])) {
|
65 |
|
66 |
-
$parsedurl['path'] = substr($parsedurl['path'], $
|
|
|
67 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
}
|
69 |
-
if ($gluebackhome) $parsedurl['path'] = $home_path . $parsedurl['path'];
|
70 |
-
if ($remove_host) {
|
71 |
-
unset($parsedurl['scheme']);
|
72 |
-
unset($parsedurl['host']);
|
73 |
-
}
|
74 |
-
$url = glue_url($parsedurl);
|
75 |
-
if (!$url) return '/';
|
76 |
-
return $url;
|
77 |
-
}
|
78 |
|
79 |
-
/**
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
// Should send a transposh interface to here TODO - enable permalinks rewrite
|
87 |
// TODO - Should be able to not write default language for url (done with empty lang?)
|
88 |
-
function rewrite_url_lang_param($url, $home_url, $enable_permalinks_rewrite, $lang, $is_edit, $use_params_only=FALSE) {
|
89 |
-
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
106 |
}
|
107 |
-
|
108 |
-
|
109 |
-
unset($parsedurl['query']);
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
|
115 |
|
116 |
-
$
|
117 |
-
$gluebackhome = true;
|
118 |
-
}
|
119 |
-
if (strlen($parsedurl['path']) > 2) {
|
120 |
-
$secondslashpos = strpos($parsedurl['path'], "/", 1);
|
121 |
-
if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
|
122 |
-
$prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1);
|
123 |
-
if (isset($GLOBALS['languages'][$prevlang])) {
|
124 |
|
125 |
-
$parsedurl['path'] = substr($parsedurl['path'], $
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
}
|
127 |
-
}
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
}
|
146 |
-
}
|
147 |
-
if ($gluebackhome) $parsedurl['path'] = $home_path . $parsedurl['path'];
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
152 |
|
|
|
153 |
}
|
154 |
|
155 |
-
|
156 |
-
//$url = preg_replace("/&$/", "", $url);
|
157 |
-
//$url = preg_replace("/\?$/", "", $url);
|
158 |
-
// $url = htmlentities($url, ENT_NOQUOTES);
|
159 |
-
$url = glue_url($parsedurl);
|
160 |
-
|
161 |
-
return $url;
|
162 |
-
}
|
163 |
-
|
164 |
-
function get_language_from_url($url, $home_url) {
|
165 |
|
166 |
-
|
167 |
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
|
|
175 |
}
|
176 |
}
|
177 |
-
}
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
//
|
184 |
-
|
185 |
//
|
186 |
-
|
187 |
// $gluebackhome = true;
|
188 |
-
}
|
189 |
-
|
190 |
-
if (strlen($parsedurl['path']) > 2) {
|
191 |
-
$secondslashpos = strpos($parsedurl['path'], "/", 1);
|
192 |
-
if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
|
193 |
-
$prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1);
|
194 |
-
if (isset($GLOBALS['languages'][$prevlang])) {
|
195 |
-
//
|
196 |
-
//$parsedurl['path'] = substr($parsedurl['path'],$secondslashpos);
|
197 |
-
return $prevlang;
|
198 |
}
|
199 |
-
}
|
200 |
-
return false;
|
201 |
-
}
|
202 |
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
|
|
|
|
|
|
210 |
return false;
|
211 |
}
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
-
|
219 |
-
$uri .= (
|
220 |
-
|
221 |
-
|
222 |
|
223 |
-
|
224 |
-
|
|
|
|
|
225 |
|
226 |
-
|
227 |
-
|
228 |
|
229 |
-
|
230 |
-
|
231 |
-
* in uri, e.g. + is interpeted as a space.
|
232 |
-
*/
|
233 |
-
function base64_url_encode($input) {
|
234 |
-
return strtr(base64_encode($input), '+/=', '-_,');
|
235 |
-
}
|
236 |
|
237 |
-
/**
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
|
|
243 |
|
244 |
-
/**
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
* @param string $target_language
|
250 |
-
* @param function $fetch_translation_func
|
251 |
-
* @return string translated url permalink
|
252 |
-
*/
|
253 |
-
function translate_url($href, $home_url, $target_language, $fetch_translation_func) {
|
254 |
-
// todo - check query part... sanitize
|
255 |
-
if (strpos($href, '?') !== false) {
|
256 |
-
list ($href, $querypart) = explode('?', $href);
|
257 |
-
$querypart = '?' . $querypart;
|
258 |
}
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
if ($translated_text)
|
271 |
$url .= '/' . str_replace(' ', '-', $translated_text);
|
272 |
-
else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
}
|
|
|
|
|
274 |
}
|
275 |
-
if (substr($href, strlen($href) - 1) == '/') $url.='/';
|
276 |
-
return $home_url . $url . $querypart;
|
277 |
-
}
|
278 |
|
279 |
-
/**
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
function get_original_url($href, $home_url, $target_language, $fetch_translation_func) {
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
|
|
306 |
}
|
|
|
|
|
|
|
|
|
307 |
}
|
308 |
-
//
|
309 |
-
|
310 |
-
|
311 |
-
|
|
|
|
|
|
|
|
|
|
|
312 |
}
|
313 |
-
// TODO: Consider sanitize_title_with_dashes
|
314 |
-
// TODO : need to handle params....
|
315 |
-
//
|
316 |
-
//if (substr($url,strlen($url)-1) == '/') $url2 .= '/';
|
317 |
-
//$url2 = rtrim($url2,'/');
|
318 |
-
//
|
319 |
-
//$href = $this->home_url.$url2;
|
320 |
-
if (substr($href, strlen($href) - 1) == '/') $url2.='/';
|
321 |
-
return $home_url . $url2;
|
322 |
-
}
|
323 |
|
324 |
-
/**
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
function display_flag($path, $flag, $language, $css = false) {
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
|
|
337 |
}
|
338 |
-
}
|
339 |
|
340 |
-
/**
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
function prefered_language($available_languages, $default_lang="auto", $http_accept_language="auto") {
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
|
|
390 |
}
|
|
|
391 |
}
|
392 |
-
|
393 |
}
|
394 |
?>
|
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 |
/**
|
20 |
|
21 |
|
22 |
/**
|
23 |
+
* This is a static class to reduce chance of namespace collisions with other plugins
|
|
|
24 |
*/
|
25 |
+
class transposh_utils {
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Remove from url any language (or editing) params that were added for our use.
|
29 |
+
* Return the scrubed url
|
30 |
+
*/
|
31 |
+
public static function cleanup_url($url, $home_url, $remove_host = false) {
|
32 |
+
|
33 |
+
$parsedurl = @parse_url($url);
|
34 |
+
//cleanup previous lang & edit parameter from url
|
35 |
+
|
36 |
+
if (isset($parsedurl['query'])) {
|
37 |
+
$params = explode('&', $parsedurl['query']);
|
38 |
+
foreach ($params as $key => $param) {
|
39 |
+
if (stripos($param, LANG_PARAM) === 0) unset($params[$key]);
|
40 |
+
if (stripos($param, EDIT_PARAM) === 0) unset($params[$key]);
|
41 |
+
}
|
42 |
+
}
|
43 |
+
// clean the query
|
44 |
+
unset($parsedurl['query']);
|
45 |
+
if (isset($params) && $params) {
|
46 |
+
$parsedurl['query'] = implode('&', $params);
|
47 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
+
//cleanup lang identifier in permalinks
|
50 |
+
//remove the language from the url permalink (if in start of path, and is a defined language)
|
51 |
+
$home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/");
|
|
|
|
|
52 |
|
53 |
+
if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
$parsedurl['path'] = substr($parsedurl['path'], strlen($home_path));
|
56 |
+
$gluebackhome = true;
|
57 |
}
|
58 |
+
|
59 |
+
if (strlen($parsedurl['path']) > 2) {
|
60 |
+
$secondslashpos = strpos($parsedurl['path'], "/", 1);
|
61 |
+
if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
|
62 |
+
$prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1);
|
63 |
+
if (isset(transposh_consts::$languages[$prevlang])) {
|
64 |
+
|
65 |
+
$parsedurl['path'] = substr($parsedurl['path'], $secondslashpos);
|
66 |
+
}
|
67 |
+
}
|
68 |
+
if ($gluebackhome) $parsedurl['path'] = $home_path . $parsedurl['path'];
|
69 |
+
if ($remove_host) {
|
70 |
+
unset($parsedurl['scheme']);
|
71 |
+
unset($parsedurl['host']);
|
72 |
+
}
|
73 |
+
$url = transposh_utils::glue_url($parsedurl);
|
74 |
+
if (!$url) return '/';
|
75 |
+
return $url;
|
76 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
+
/**
|
79 |
+
* Update the given url to include language params.
|
80 |
+
* @param string $url - Original URL to rewrite
|
81 |
+
* @param string $lang - Target language code
|
82 |
+
* @param boolean $is_edit - should url indicate editing
|
83 |
+
* @param boolean $use_params_only - only use paramaters and avoid permalinks
|
84 |
+
*/
|
85 |
// Should send a transposh interface to here TODO - enable permalinks rewrite
|
86 |
// TODO - Should be able to not write default language for url (done with empty lang?)
|
87 |
+
public static function rewrite_url_lang_param($url, $home_url, $enable_permalinks_rewrite, $lang, $is_edit, $use_params_only=FALSE) {
|
88 |
+
|
89 |
|
90 |
+
$newurl = str_replace('&', '&', $url);
|
91 |
+
$newurl = html_entity_decode($newurl, ENT_NOQUOTES);
|
92 |
+
$parsedurl = parse_url($newurl);
|
93 |
|
94 |
+
// if we are dealing with some other url, we won't touch it!
|
95 |
+
if (isset($parsedurl['host']) && !($parsedurl['host'] == parse_url($home_url, PHP_URL_HOST))) {
|
96 |
+
return $url;
|
97 |
+
}
|
98 |
|
99 |
+
//remove prev lang and edit params - from query string - reserve other params
|
100 |
+
if (isset($parsedurl['query'])) {
|
101 |
+
$params = explode('&', $parsedurl['query']);
|
102 |
+
foreach ($params as $key => $param) {
|
103 |
+
if (stripos($param, LANG_PARAM) === 0) unset($params[$key]);
|
104 |
+
if (stripos($param, EDIT_PARAM) === 0) unset($params[$key]);
|
105 |
+
}
|
106 |
}
|
107 |
+
// clean the query
|
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) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
+
$parsedurl['path'] = substr($parsedurl['path'], strlen($home_path));
|
116 |
+
$gluebackhome = true;
|
117 |
+
}
|
118 |
+
if (strlen($parsedurl['path']) > 2) {
|
119 |
+
$secondslashpos = strpos($parsedurl['path'], "/", 1);
|
120 |
+
if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
|
121 |
+
$prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1);
|
122 |
+
if (isset(transposh_consts::$languages[$prevlang])) {
|
123 |
+
|
124 |
+
$parsedurl['path'] = substr($parsedurl['path'], $secondslashpos);
|
125 |
+
}
|
126 |
}
|
|
|
127 |
|
128 |
+
// override the use only params - admin configured system to not touch permalinks
|
129 |
+
if (!$enable_permalinks_rewrite) {
|
130 |
+
$use_params_only = TRUE;
|
131 |
+
}
|
132 |
|
133 |
+
//$params ="";
|
134 |
+
if ($is_edit) {
|
135 |
+
$params[edit] = EDIT_PARAM . '=1';
|
136 |
+
}
|
137 |
|
138 |
+
if ($use_params_only && $lang) {
|
139 |
+
$params['lang'] = LANG_PARAM . "=$lang";
|
140 |
+
} else {
|
141 |
+
if ($lang) {
|
142 |
+
if (!$parsedurl['path']) $parsedurl['path'] = "/";
|
143 |
+
$parsedurl['path'] = "/" . $lang . $parsedurl['path'];
|
144 |
+
}
|
145 |
+
}
|
146 |
+
if ($gluebackhome) $parsedurl['path'] = $home_path . $parsedurl['path'];
|
147 |
+
|
148 |
+
// insert params to url
|
149 |
+
if (isset($params) && $params) {
|
150 |
+
$parsedurl['query'] = implode('&', $params);
|
151 |
+
|
152 |
}
|
|
|
|
|
153 |
|
154 |
+
// more cleanups
|
155 |
+
//$url = preg_replace("/&$/", "", $url);
|
156 |
+
//$url = preg_replace("/\?$/", "", $url);
|
157 |
+
// $url = htmlentities($url, ENT_NOQUOTES);
|
158 |
+
$url = transposh_utils::glue_url($parsedurl);
|
159 |
|
160 |
+
return $url;
|
161 |
}
|
162 |
|
163 |
+
public static function get_language_from_url($url, $home_url) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
+
$parsedurl = @parse_url($url);
|
166 |
|
167 |
+
//option 1, lanaguage is in the query ?lang=xx
|
168 |
+
if (isset($parsedurl['query'])) {
|
169 |
+
$params = explode('&', $parsedurl['query']);
|
170 |
+
foreach ($params as $key => $param) {
|
171 |
+
if (stripos($param, LANG_PARAM) === 0) {
|
172 |
+
$langa = explode("=", $params[$key]);
|
173 |
+
return ($langa[1]);
|
174 |
+
}
|
175 |
}
|
176 |
}
|
|
|
177 |
|
178 |
+
// option 2, language is in permalink
|
179 |
+
// cleanup lang identifier in permalinks
|
180 |
+
// remove the language from the url permalink (if in start of path, and is a defined language)
|
181 |
+
$home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/");
|
182 |
//
|
183 |
+
if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
|
184 |
//
|
185 |
+
$parsedurl['path'] = substr($parsedurl['path'], strlen($home_path));
|
186 |
// $gluebackhome = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
}
|
|
|
|
|
|
|
188 |
|
189 |
+
if (strlen($parsedurl['path']) > 2) {
|
190 |
+
$secondslashpos = strpos($parsedurl['path'], "/", 1);
|
191 |
+
if (!$secondslashpos) $secondslashpos = strlen($parsedurl['path']);
|
192 |
+
$prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1);
|
193 |
+
if (isset(transposh_consts::$languages[$prevlang])) {
|
194 |
+
//
|
195 |
+
//$parsedurl['path'] = substr($parsedurl['path'],$secondslashpos);
|
196 |
+
return $prevlang;
|
197 |
+
}
|
198 |
+
}
|
199 |
return false;
|
200 |
}
|
201 |
|
202 |
+
/**
|
203 |
+
* glue a parse_url array back to a url
|
204 |
+
* @param array $parsed url_parse style array
|
205 |
+
* @return combined url
|
206 |
+
*/
|
207 |
+
public static function glue_url($parsed) {
|
208 |
+
if (!is_array($parsed)) {
|
209 |
+
return false;
|
210 |
+
}
|
211 |
|
212 |
+
$uri = isset($parsed['scheme']) ? $parsed['scheme'] . ':' . ((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : '';
|
213 |
+
$uri .= isset($parsed['user']) ? $parsed['user'] . (isset($parsed['pass']) ? ':' . $parsed['pass'] : '') . '@' : '';
|
214 |
+
$uri .= isset($parsed['host']) ? $parsed['host'] : '';
|
215 |
+
$uri .= isset($parsed['port']) ? ':' . $parsed['port'] : '';
|
216 |
|
217 |
+
if (isset($parsed['path'])) {
|
218 |
+
$uri .= ( substr($parsed['path'], 0, 1) == '/') ?
|
219 |
+
$parsed['path'] : ((!empty($uri) ? '/' : '' ) . $parsed['path']);
|
220 |
+
}
|
221 |
|
222 |
+
$uri .= isset($parsed['query']) ? '?' . $parsed['query'] : '';
|
223 |
+
$uri .= isset($parsed['fragment']) ? '#' . $parsed['fragment'] : '';
|
224 |
|
225 |
+
return $uri;
|
226 |
+
}
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
+
/**
|
229 |
+
* Encode a string as base 64 while avoiding characters which should be avoided
|
230 |
+
* in uri, e.g. + is interpeted as a space.
|
231 |
+
*/
|
232 |
+
public static function base64_url_encode($input) {
|
233 |
+
return strtr(base64_encode($input), '+/=', '-_,');
|
234 |
+
}
|
235 |
|
236 |
+
/**
|
237 |
+
* Decode a string previously decoded with base64_url_encode
|
238 |
+
*/
|
239 |
+
public static function base64_url_decode($input) {
|
240 |
+
return base64_decode(strtr($input, '-_,', '+/='));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Function to translate a given url permalink to a target language
|
245 |
+
* TODO - check params
|
246 |
+
* @param string $href
|
247 |
+
* @param string $home_url
|
248 |
+
* @param string $target_language
|
249 |
+
* @param function $fetch_translation_func
|
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);
|
256 |
+
$querypart = '?' . $querypart;
|
257 |
+
}
|
258 |
+
$href = substr($href, strlen($home_url));
|
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);
|
271 |
+
else $url .= '/' . $part;
|
272 |
+
}
|
273 |
}
|
274 |
+
if (substr($href, strlen($href) - 1) == '/') $url.='/';
|
275 |
+
return $home_url . $url . $querypart;
|
276 |
}
|
|
|
|
|
|
|
277 |
|
278 |
+
/**
|
279 |
+
* From a given translated url, tries to get the original URL
|
280 |
+
* @param string $href
|
281 |
+
* @param string $home_url
|
282 |
+
* @param string $target_language
|
283 |
+
* @param function $fetch_translation_func
|
284 |
+
* @return string
|
285 |
+
*/
|
286 |
+
public static function get_original_url($href, $home_url, $target_language, $fetch_translation_func) {
|
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;
|
293 |
+
// don't attempt for lang or numbers
|
294 |
+
if ($part == $target_language || is_numeric($part)) {
|
295 |
+
$url2 .= '/' . $part;
|
296 |
+
continue;
|
297 |
+
}
|
298 |
|
299 |
+
// we attempt to find an original text
|
300 |
+
$original_text = call_user_func_array($fetch_translation_func, array($part, $target_language));
|
301 |
+
if (!$original_text) {
|
302 |
+
// if the part has dashes we attempt to resolve original without them
|
303 |
+
if ($part != str_replace('-', ' ', $part)) {
|
304 |
+
$original_text = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language));
|
305 |
+
}
|
306 |
}
|
307 |
+
// we'll add it if we have it
|
308 |
+
if ($original_text)
|
309 |
+
$url2 .= '/' . strtolower(str_replace(' ', '-', $original_text));
|
310 |
+
else $url2 .= '/' . $part;
|
311 |
}
|
312 |
+
// TODO: Consider sanitize_title_with_dashes
|
313 |
+
// TODO : need to handle params....
|
314 |
+
//
|
315 |
+
//if (substr($url,strlen($url)-1) == '/') $url2 .= '/';
|
316 |
+
//$url2 = rtrim($url2,'/');
|
317 |
+
//
|
318 |
+
//$href = $this->home_url.$url2;
|
319 |
+
if (substr($href, strlen($href) - 1) == '/') $url2.='/';
|
320 |
+
return $home_url . $url2;
|
321 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
|
323 |
+
/**
|
324 |
+
* Function to display a flag
|
325 |
+
* @param string $path path to flag images
|
326 |
+
* @param string $flag the flag (normally iso code)
|
327 |
+
* @param string $language the name of the lanaguage
|
328 |
+
* @param boolean $css using css code?
|
329 |
+
* @return string Html with flag
|
330 |
+
*/
|
331 |
+
public static function display_flag($path, $flag, $language, $css = false) {
|
332 |
+
if (!$css) {
|
333 |
+
return "<img src=\"$path/$flag.png\" title=\"$language\" alt=\"$language\"/>";
|
334 |
+
} else {
|
335 |
+
return "<span title=\"$language\" class=\"trf trf-{$flag}\"></span>";
|
336 |
+
}
|
337 |
}
|
|
|
338 |
|
339 |
+
/**
|
340 |
+
* determine which language out of an available set the user prefers most
|
341 |
+
* adapted from php documentation page
|
342 |
+
* @param array $available_languages array with language-tag-strings (must be lowercase) that are available
|
343 |
+
* @param string $default_lang Language that will be default (first in available languages if not provided)
|
344 |
+
* @param string $http_accept_language a HTTP_ACCEPT_LANGUAGE string (read from $_SERVER['HTTP_ACCEPT_LANGUAGE'] if left out)
|
345 |
+
* @return string
|
346 |
+
*/
|
347 |
+
public static function prefered_language($available_languages, $default_lang="auto", $http_accept_language="auto") {
|
348 |
+
// if $http_accept_language was left out, read it from the HTTP-Header
|
349 |
+
if ($http_accept_language == "auto")
|
350 |
+
$http_accept_language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
351 |
+
|
352 |
+
// standard for HTTP_ACCEPT_LANGUAGE is defined under
|
353 |
+
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
|
354 |
+
// pattern to find is therefore something like this:
|
355 |
+
// 1#( language-range [ ";" "q" "=" qvalue ] )
|
356 |
+
// where:
|
357 |
+
// language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
|
358 |
+
// qvalue = ( "0" [ "." 0*3DIGIT ] )
|
359 |
+
// | ( "1" [ "." 0*3("0") ] )
|
360 |
+
preg_match_all("/([[:alpha:]]{1,8})(-([[:alpha:]|-]{1,8}))?" .
|
361 |
+
"(\s*;\s*q\s*=\s*(1\.0{0,3}|0\.\d{0,3}))?\s*(,|$)/i",
|
362 |
+
$http_accept_language, $hits, PREG_SET_ORDER);
|
363 |
+
|
364 |
+
// default language (in case of no hits) is the first in the array
|
365 |
+
if ($default_lang == 'auto') $bestlang = $available_languages[0]; else
|
366 |
+
$bestlang = $default_lang;
|
367 |
+
$bestqval = 0;
|
368 |
+
|
369 |
+
foreach ($hits as $arr) {
|
370 |
+
// read data from the array of this hit
|
371 |
+
$langprefix = strtolower($arr[1]);
|
372 |
+
if (!empty($arr[3])) {
|
373 |
+
$langrange = strtolower($arr[3]);
|
374 |
+
$language = $langprefix . "-" . $langrange;
|
375 |
+
}
|
376 |
+
else $language = $langprefix;
|
377 |
+
$qvalue = 1.0;
|
378 |
+
if (!empty($arr[5])) $qvalue = floatval($arr[5]);
|
379 |
+
|
380 |
+
// find q-maximal language
|
381 |
+
if (in_array($language, $available_languages) && ($qvalue > $bestqval)) {
|
382 |
+
$bestlang = $language;
|
383 |
+
$bestqval = $qvalue;
|
384 |
+
}
|
385 |
+
// if no direct hit, try the prefix only but decrease q-value by 10% (as http_negotiate_language does)
|
386 |
+
else if (in_array($languageprefix, $available_languages) && (($qvalue * 0.9) > $bestqval)) {
|
387 |
+
$bestlang = $languageprefix;
|
388 |
+
$bestqval = $qvalue * 0.9;
|
389 |
+
}
|
390 |
}
|
391 |
+
return $bestlang;
|
392 |
}
|
393 |
+
|
394 |
}
|
395 |
?>
|
js/lazy.js
CHANGED
@@ -1,3 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
(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};
|
2 |
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");
|
3 |
e.setAttribute("type","text/javascript");e.setAttribute("src",a);e.setAttribute("id",d);e.setAttribute("pending",1);e.onerror=q;b(e).bind("scriptload",function(){b(this).removeAttr("pending");c();setTimeout(function(){b(e).unbind("scriptload")},10)});var r=false;e.onload=e.onreadystatechange=function(){if(!r&&(!this.readyState||/loaded|complete/.test(this.readyState))){r=true;e.onload=e.onreadystatechange=null;b(e).trigger("scriptload")}};m.appendChild(e)}};this.css=function(a,c,d){if(b('link[href*="'+
|
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");
|
13 |
e.setAttribute("type","text/javascript");e.setAttribute("src",a);e.setAttribute("id",d);e.setAttribute("pending",1);e.onerror=q;b(e).bind("scriptload",function(){b(this).removeAttr("pending");c();setTimeout(function(){b(e).unbind("scriptload")},10)});var r=false;e.onload=e.onreadystatechange=function(){if(!r&&(!this.readyState||/loaded|complete/.test(this.readyState))){r=true;e.onload=e.onreadystatechange=null;b(e).trigger("scriptload")}};m.appendChild(e)}};this.css=function(a,c,d){if(b('link[href*="'+
|
js/transposh.js
CHANGED
@@ -1,7 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
(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=
|
2 |
{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="+
|
3 |
-
|
4 |
-
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[0].trans&&l(c,b.sentences[0].trans)})}function r(c,d){if(t_jp.msn&&t_jp.preferred==="2")z(c,
|
5 |
-
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=
|
6 |
-
"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",
|
7 |
success:function(){a("#"+f+"credit").css({overflow:"auto"}).append('<div style="float: left;width: 90%;height: 10px" id="'+m+'"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="'+k+'"/>');a("#"+m).progressbar({value:0});a("#"+k).progressbar({value:0});a("#"+k+" > div").css({background:"#28F828",border:"#08A908 1px solid"});s()}})};typeof a.xLazyLoader==="function"?c():a.getScript(t_jp.plugin_url+"/js/lazy.js",c)}else s();t_jp.edit&&a.getScript(t_jp.plugin_url+"/js/transposhedit.js")})})(jQuery);
|
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",
|
17 |
success:function(){a("#"+f+"credit").css({overflow:"auto"}).append('<div style="float: left;width: 90%;height: 10px" id="'+m+'"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="'+k+'"/>');a("#"+m).progressbar({value:0});a("#"+k).progressbar({value:0});a("#"+k+" > div").css({background:"#28F828",border:"#08A908 1px solid"});s()}})};typeof a.xLazyLoader==="function"?c():a.getScript(t_jp.plugin_url+"/js/lazy.js",c)}else s();t_jp.edit&&a.getScript(t_jp.plugin_url+"/js/transposhedit.js")})})(jQuery);
|
js/transposhadmin.js
CHANGED
@@ -1,8 +1,18 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)})})}
|
16 |
+
function translate_post(e){var b="",c=[],d=[],f,a,h,i,m=0,j=[],k=[],l;jQuery("#tr_loading").data("done",false);jQuery.getJSON(t_jp.post_url+"?tr_phrases_post=y&post="+e+"&random="+Math.random(),function(g){jQuery("#tr_translate_title").html("Translating post: "+g.posttitle);if(g.length===undefined){jQuery("#tr_loading").html("Nothing left to translate");jQuery("#tr_loading").data("done",true)}else{curr_pair=pair_count=0;for(h in g.p)pair_count+=g.p[h].l.length;jQuery("#tr_loading").html('<br/>Translation: <span id="p"></span><div id="progress_bar"/>');
|
17 |
+
jQuery("#progress_bar").progressbar({value:0});if(t_jp.preferred==="2")for(f in t_jp.m_langs){b=t_jp.m_langs[f];d=[];c=[];for(h in g.p){i=g.p[h];if(i.l.indexOf(b)!==-1){d.push(unescape(h));c.push(i.t);i.l.splice(i.l.indexOf(b),1);if(i.l.length===0){g.length-=1;delete g.p[h]}}}if(d.length){for(a in d){l=d[a];if(m+l.length>BATCH_SIZE){do_mass_ms_invoker(k,j,b);m=0;j=[];k=[]}m+=l.length;k.push(c[a]);j.push(l)}do_mass_ms_invoker(k,j,b)}}for(h in g.p){i=g.p[h];do_mass_google_invoker_l(i.t,unescape(h),
|
18 |
+
i.l)}}})}jQuery(document).ready(function(){t_jp.post&&translate_post(t_jp.post)});
|
js/transposhcontrol.js
CHANGED
@@ -1,9 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
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)})}});
|
2 |
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");
|
3 |
else if(jQuery(this).hasClass("active")){jQuery(this).removeClass("active");jQuery(this).addClass("translateable")}else jQuery(this).hasClass("translateable")?jQuery(this).removeClass("translateable"):jQuery(this).addClass("active");jQuery("input",this).val(jQuery(this).attr("id")+(jQuery(this).hasClass("active")?",v":",")+(jQuery(this).hasClass("translateable")?",t":","))}};jQuery(".languages").dblclick(clickfunction).click(clickfunction);jQuery("#default_lang").droppable({accept:".languages",activeClass:"highlight_default",
|
4 |
drop:function(b,a){jQuery("#default_list").empty();jQuery(a.draggable.clone().removeAttr("style").removeClass("active").removeClass("translateable")).appendTo("#default_list").show("slow");jQuery("#default_list .logoicon").remove();jQuery("#sortable").find("#"+a.draggable.attr("id")).addClass("active")}});jQuery("#sortiso").click(function(){jQuery("#sortable li").sort(function(b,a){if(jQuery(b).attr("id")==jQuery("#default_list li").attr("id"))return-1;if(jQuery(a).attr("id")==jQuery("#default_list li").attr("id"))return 1;
|
5 |
return jQuery(b).attr("id")>jQuery(a).attr("id")?1:-1}).remove().appendTo("#sortable").dblclick(clickfunction).click(clickfunction);return false});jQuery("#sortname").click(function(){jQuery("#sortable li").sort(function(b,a){langa=jQuery(".langname",b).filter(function(){return!jQuery(this).hasClass("hidden")}).text();langb=jQuery(".langname",a).filter(function(){return!jQuery(this).hasClass("hidden")}).text();langdef=jQuery(".langname","#default_list li").filter(function(){return!jQuery(this).hasClass("hidden")}).text();
|
6 |
-
if(langa==langdef)return-1;if(langb==langdef)return 1;return langa>langb?1:-1}).remove().appendTo("#sortable").dblclick(clickfunction).click(clickfunction);return false});backupclick=function(){jQuery("#transposh-backup").click(function(){return false}).text("Backup In Progress");jQuery.get(t_jp.post_url+"?backup
|
7 |
-
jQuery("#transposh-backup").click(backupclick);
|
8 |
-
|
9 |
-
jQuery("#transposh-translate").
|
|
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");
|
13 |
else if(jQuery(this).hasClass("active")){jQuery(this).removeClass("active");jQuery(this).addClass("translateable")}else jQuery(this).hasClass("translateable")?jQuery(this).removeClass("translateable"):jQuery(this).addClass("active");jQuery("input",this).val(jQuery(this).attr("id")+(jQuery(this).hasClass("active")?",v":",")+(jQuery(this).hasClass("translateable")?",t":","))}};jQuery(".languages").dblclick(clickfunction).click(clickfunction);jQuery("#default_lang").droppable({accept:".languages",activeClass:"highlight_default",
|
14 |
drop:function(b,a){jQuery("#default_list").empty();jQuery(a.draggable.clone().removeAttr("style").removeClass("active").removeClass("translateable")).appendTo("#default_list").show("slow");jQuery("#default_list .logoicon").remove();jQuery("#sortable").find("#"+a.draggable.attr("id")).addClass("active")}});jQuery("#sortiso").click(function(){jQuery("#sortable li").sort(function(b,a){if(jQuery(b).attr("id")==jQuery("#default_list li").attr("id"))return-1;if(jQuery(a).attr("id")==jQuery("#default_list li").attr("id"))return 1;
|
15 |
return jQuery(b).attr("id")>jQuery(a).attr("id")?1:-1}).remove().appendTo("#sortable").dblclick(clickfunction).click(clickfunction);return false});jQuery("#sortname").click(function(){jQuery("#sortable li").sort(function(b,a){langa=jQuery(".langname",b).filter(function(){return!jQuery(this).hasClass("hidden")}).text();langb=jQuery(".langname",a).filter(function(){return!jQuery(this).hasClass("hidden")}).text();langdef=jQuery(".langname","#default_list li").filter(function(){return!jQuery(this).hasClass("hidden")}).text();
|
16 |
+
if(langa==langdef)return-1;if(langb==langdef)return 1;return langa>langb?1:-1}).remove().appendTo("#sortable").dblclick(clickfunction).click(clickfunction);return false});jQuery.ajaxSetup({cache:false});backupclick=function(){jQuery("#transposh-backup").unbind("click").click(function(){return false}).text("Backup In Progress");jQuery.get(t_jp.post_url+"?backup",function(b){var a="red";if(b[0]=="2")a="green";jQuery("#backup_result").html(b).css("color",a);jQuery("#transposh-backup").unbind("click").click(backupclick).text("Do Backup Now")});
|
17 |
+
return false};jQuery("#transposh-backup").click(backupclick);cleanautoclick=function(b,a){if(!confirm("Are you sure you want to do this?"))return false;if(b==0&&!confirm("Are you REALLY sure you want to do this?"))return false;var c=a.text();a.unbind("click").click(function(){return false}).text("Cleanup in progress");jQuery.get(t_jp.post_url+"?nonce="+a.attr("nonce")+"&days="+b+"&cleanup",function(){a.unbind("click").click(function(){cleanautoclick(b,a);return false}).text(c)});return false};jQuery("#transposh-clean-auto").click(function(){cleanautoclick(0,
|
18 |
+
jQuery(this));return false});jQuery("#transposh-clean-auto14").click(function(){cleanautoclick(14,jQuery(this));return false});do_translate_all=function(){jQuery("#progress_bar_all").progressbar({value:0});stop_translate_var=false;jQuery("#tr_loading").data("done",true);jQuery.ajaxSetup({cache:false});jQuery.getJSON(t_jp.post_url,{translate_all:"y"},function(b){dotimer=function(a){clearTimeout(timer2);if(jQuery("#tr_loading").data("done")||jQuery("#tr_loading").data("attempt")>4){jQuery("#progress_bar_all").progressbar("value",
|
19 |
+
(a+1)/b.length*100);jQuery("#tr_loading").data("attempt",0);translate_post(b[a]);if(b[a]&&!stop_translate_var)timer2=setTimeout(function(){dotimer(a+1)},1E3)}else{jQuery("#tr_loading").data("attempt",jQuery("#tr_loading").data("attempt")+1);timer2=setTimeout(function(){dotimer(a)},6E4)}};timer2=setTimeout(function(){dotimer(0)},0)});jQuery("#transposh-translate").text("Stop translate");jQuery("#transposh-translate").unbind("click").click(stop_translate);return false};stop_translate=function(){clearTimeout(timer2);
|
20 |
+
stop_translate_var=true;jQuery("#transposh-translate").text("Translate All Now");jQuery("#transposh-translate").unbind("click").click(do_translate_all);return false};jQuery("#transposh-translate").click(do_translate_all)});
|
js/transposhedit.js
CHANGED
@@ -1,5 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
(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,
|
2 |
-
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="+
|
3 |
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",
|
4 |
"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,
|
5 |
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");
|
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");
|
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.
|
8 |
|
9 |
Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
|
10 |
|
@@ -146,6 +146,11 @@ change the .css from transparent background to your page background color. And l
|
|
146 |
|
147 |
You can wrap the element with the "no_translate" class, or add a span similar to `<span class="no_translate">`
|
148 |
|
|
|
|
|
|
|
|
|
|
|
149 |
= Can I make different images appear in different languages in my themes? =
|
150 |
|
151 |
Yes, although a bit tricky - you can use the `$my_transposh_plugin->target_language` as part of the image descriptor, this will load different
|
@@ -186,6 +191,16 @@ This version provides integration with google-sitemaps-xml and wp-super-cache
|
|
186 |
This version allows sorting of languages within the widget
|
187 |
|
188 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
= 2010/08/01 - 0.6.1 =
|
190 |
* Makes themes that support RTL actually use that support
|
191 |
* Deeper integration with buddypress, support activity stream
|
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 |
|
146 |
|
147 |
You can wrap the element with the "no_translate" class, or add a span similar to `<span class="no_translate">`
|
148 |
|
149 |
+
= How to mark a post with a different than default language? =
|
150 |
+
|
151 |
+
Using the wordpress editing, add a custom field called tp_language and insert the two letter code of the language used in that post, so if
|
152 |
+
your blog is in English and you have a post in Spanish just add tp_language es as a custom field.
|
153 |
+
|
154 |
= Can I make different images appear in different languages in my themes? =
|
155 |
|
156 |
Yes, although a bit tricky - you can use the `$my_transposh_plugin->target_language` as part of the image descriptor, this will load different
|
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)
|
197 |
+
* Allow parser processing of nested lang tags
|
198 |
+
* Treat the noscript tag as hidden, fixes bug with buddypress (thanks [Terence](http://virtualcrowds.org))
|
199 |
+
* Fixes to translate with non latin chars (thanks [Martin](http://www.maskaran.com))
|
200 |
+
* Fixes to mass translate with bing translator for Chinese and Taiwanese
|
201 |
+
* Moved functions and constants to static classes to reduce collisions (Such as with "WordPress MU Domain Mapping" plugin)
|
202 |
+
* Added functions to remove automated translations from the database, either all or those older than 14 days
|
203 |
+
* Shortened copyright notice in source files, and made it a bit more informative
|
204 |
= 2010/08/01 - 0.6.1 =
|
205 |
* Makes themes that support RTL actually use that support
|
206 |
* Deeper integration with buddypress, support activity stream
|
transposh.php
CHANGED
@@ -5,26 +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.
|
9 |
Author URI: http://transposh.org/
|
10 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
*/
|
12 |
|
13 |
-
/*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
* it under the terms of the GNU General Public License as published by
|
17 |
-
* the Free Software Foundation; either version 2 of the License, or
|
18 |
-
* (at your option) any later version.
|
19 |
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
* GNU General Public License for more details.
|
24 |
*
|
25 |
-
*
|
26 |
-
* along with this program; if not, write to the Free Software
|
27 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
*/
|
29 |
|
30 |
//avoid direct calls to this file where wp core files not present
|
@@ -45,6 +39,7 @@ require_once("wp/transposh_admin.php");
|
|
45 |
require_once("wp/transposh_options.php");
|
46 |
require_once("wp/transposh_postpublish.php");
|
47 |
require_once("wp/transposh_backup.php");
|
|
|
48 |
|
49 |
/**
|
50 |
* This class represents the complete plugin
|
@@ -62,6 +57,8 @@ class transposh_plugin {
|
|
62 |
public $database;
|
63 |
/** @var transposh_postpublish Happens after editing */
|
64 |
public $postpublish;
|
|
|
|
|
65 |
|
66 |
// list of properties
|
67 |
/** @var string The site url */
|
@@ -95,6 +92,7 @@ class transposh_plugin {
|
|
95 |
$this->admin = new transposh_plugin_admin($this);
|
96 |
$this->widget = new transposh_plugin_widget($this);
|
97 |
$this->postpublish = new transposh_postpublish($this);
|
|
|
98 |
|
99 |
// "global" vars
|
100 |
$this->home_url = get_option('home');
|
@@ -131,18 +129,22 @@ class transposh_plugin {
|
|
131 |
add_action('wp_print_styles', array(&$this, 'add_transposh_css'));
|
132 |
add_action('wp_print_scripts', array(&$this, 'add_transposh_js'));
|
133 |
// add_action('wp_head', array(&$this,'add_transposh_async'));
|
134 |
-
add_action("sm_addurl", array(&$this, 'add_sm_transposh_urls'));
|
135 |
add_action('transposh_backup_event', array(&$this, 'run_backup'));
|
136 |
add_action('comment_post', array(&$this, 'add_comment_meta_settings'), 1);
|
137 |
|
138 |
-
//
|
139 |
-
add_filter('
|
140 |
-
add_filter('
|
141 |
-
|
142 |
-
add_action('
|
|
|
143 |
|
144 |
//TODO add_action('manage_comments_nav', array(&$this,'manage_comments_nav'));
|
145 |
//TODO comment_row_actions (filter)
|
|
|
|
|
|
|
|
|
146 |
|
147 |
register_activation_hook(__FILE__, array(&$this, 'plugin_activate'));
|
148 |
register_deactivation_hook(__FILE__, array(&$this, 'plugin_deactivate'));
|
@@ -165,7 +167,7 @@ class transposh_plugin {
|
|
165 |
* @return string Modified page buffer
|
166 |
*/
|
167 |
function process_page(&$buffer) {
|
168 |
-
|
169 |
$start_time = microtime(TRUE);
|
170 |
|
171 |
// Refrain from touching the administrative interface and important pages
|
@@ -190,7 +192,7 @@ class transposh_plugin {
|
|
190 |
$parse->fetch_translate_func = array(&$this->database, 'fetch_translation');
|
191 |
$parse->prefetch_translate_func = array(&$this->database, 'prefetch_translations');
|
192 |
$parse->url_rewrite_func = array(&$this, 'rewrite_url');
|
193 |
-
$parse->dir_rtl = (in_array($this->target_language,
|
194 |
$parse->lang = $this->target_language;
|
195 |
$parse->default_lang = $this->options->is_default_language($this->target_language);
|
196 |
$parse->is_edit_mode = $this->edit_mode;
|
@@ -226,6 +228,13 @@ class transposh_plugin {
|
|
226 |
}
|
227 |
}
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
//set the callback for translating the page when it's done
|
230 |
ob_start(array(&$this, "process_page"));
|
231 |
}
|
@@ -317,7 +326,7 @@ class transposh_plugin {
|
|
317 |
|
318 |
|
319 |
// make themes that support rtl - go rtl http://wordpress.tv/2010/05/01/yoav-farhi-right-to-left-themes-sf10
|
320 |
-
if (in_array($this->target_language,
|
321 |
global $wp_locale;
|
322 |
$wp_locale->text_direction = 'rtl';
|
323 |
}
|
@@ -335,20 +344,20 @@ class transposh_plugin {
|
|
335 |
// redirect according to stored lng cookie, and than according to detection
|
336 |
if (isset($_COOKIE['TR_LNG']) && $this->options->get_widget_allow_set_default_language()) {
|
337 |
if ($_COOKIE['TR_LNG'] != $this->target_language) {
|
338 |
-
$url = rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, $_COOKIE['TR_LNG'], $this->edit_mode);
|
339 |
if ($this->options->is_default_language($_COOKIE['TR_LNG']))
|
340 |
-
$url = cleanup_url($_SERVER["REQUEST_URI"], $this->home_url);
|
341 |
|
342 |
wp_redirect($url);
|
343 |
exit;
|
344 |
}
|
345 |
} else {
|
346 |
-
$bestlang = prefered_language(explode(',', $this->options->get_viewable_langs()), $this->options->get_default_language());
|
347 |
// we won't redirect if we should not, or this is a presumable bot
|
348 |
if ($bestlang && $bestlang != $this->target_language && $this->options->get_enable_detect_language() && !(preg_match("#(bot|yandex|validator|google|jeeves|spider|crawler|slurp)#si", $_SERVER['HTTP_USER_AGENT']))) {
|
349 |
-
$url = rewrite_url_lang_param($_SERVER['REQUEST_URI'], $this->home_url, $this->enable_permalinks_rewrite, $bestlang, $this->edit_mode);
|
350 |
if ($this->options->is_default_language($bestlang))
|
351 |
-
$url = cleanup_url($_SERVER['REQUEST_URI'], $this->home_url);
|
352 |
|
353 |
wp_redirect($url);
|
354 |
exit;
|
@@ -365,8 +374,8 @@ class transposh_plugin {
|
|
365 |
add_action('pre_get_posts', array(&$this, 'pre_post_search'));
|
366 |
add_action('posts_where_request', array(&$this, 'posts_where_request'));
|
367 |
}
|
368 |
-
if (get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url) && !get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url)) {
|
369 |
-
wp_redirect(rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), false)); //."&stop=y");
|
370 |
exit;
|
371 |
}
|
372 |
}
|
@@ -530,20 +539,19 @@ class transposh_plugin {
|
|
530 |
// those two options show if the script can support said engines
|
531 |
'prefix' => SPAN_PREFIX,
|
532 |
'preferred' => $this->options->get_preferred_translator()
|
533 |
-
|
534 |
-
if ($this->edit_mode)
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
$script_params['tgp'] = 1;
|
542 |
if ($this->options->get_widget_progressbar())
|
543 |
-
|
544 |
if (!$this->options->get_enable_auto_translate())
|
545 |
-
|
546 |
-
|
547 |
// 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
|
548 |
wp_localize_script('transposh', 't_jp', $script_params);
|
549 |
|
@@ -612,9 +620,9 @@ class transposh_plugin {
|
|
612 |
// some hackery needed for url translations
|
613 |
// first cut home
|
614 |
if ($this->options->get_enable_url_translate()) {
|
615 |
-
$href = translate_url($href, $this->home_url, $this->target_language, array(&$this->database, 'fetch_translation'));
|
616 |
}
|
617 |
-
$href = rewrite_url_lang_param($href, $this->home_url, $this->enable_permalinks_rewrite, $this->target_language, $this->edit_mode, $use_params);
|
618 |
|
619 |
return $href;
|
620 |
}
|
@@ -695,41 +703,21 @@ class transposh_plugin {
|
|
695 |
}
|
696 |
|
697 |
/**
|
698 |
-
*
|
699 |
-
* Also - priority is reduced by 0.2
|
700 |
-
* And this requires the following line at the sitemap-core.php, add-url function (line 1509 at version 3.2.2)
|
701 |
-
* do_action('sm_addurl', &$page);
|
702 |
-
* @param GoogleSitemapGeneratorPage $sm_page Object containing the page information
|
703 |
*/
|
704 |
-
function
|
705 |
-
|
706 |
-
|
707 |
-
$
|
708 |
-
// we reduce the priorty by 0.2, but not below zero
|
709 |
-
$sm_page->SetProprity(max($sm_page->GetPriority() - 0.2, 0));
|
710 |
-
|
711 |
-
$viewable_langs = explode(',', $this->options->get_viewable_langs());
|
712 |
-
$orig_url = $sm_page->GetUrl();
|
713 |
-
foreach ($viewable_langs as $lang) {
|
714 |
-
if (!$this->options->is_default_language($lang)) {
|
715 |
-
$newloc = $orig_url;
|
716 |
-
if ($this->options->get_enable_url_translate()) {
|
717 |
-
$newloc = translate_url($newloc, $this->home_url, $lang, array(&$this->database, 'fetch_translation'));
|
718 |
-
}
|
719 |
-
$newloc = rewrite_url_lang_param($newloc, $this->home_url, $this->enable_permalinks_rewrite, $lang, false);
|
720 |
-
$sm_page->SetUrl($newloc);
|
721 |
-
$generatorObject->AddElement($sm_page);
|
722 |
-
}
|
723 |
-
}
|
724 |
}
|
725 |
|
726 |
/**
|
727 |
-
* Runs a
|
728 |
*/
|
729 |
-
function
|
730 |
|
731 |
$my_transposh_backup = new transposh_backup($this);
|
732 |
-
$my_transposh_backup->
|
733 |
}
|
734 |
|
735 |
/**
|
@@ -738,8 +726,8 @@ class transposh_plugin {
|
|
738 |
* @param int $post_id
|
739 |
*/
|
740 |
function add_comment_meta_settings($post_id) {
|
741 |
-
if (get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url))
|
742 |
-
add_comment_meta($post_id, 'tp_language', get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), true);
|
743 |
}
|
744 |
|
745 |
/**
|
@@ -749,101 +737,60 @@ class transposh_plugin {
|
|
749 |
* @return string fixed url
|
750 |
*/
|
751 |
function comment_post_redirect_filter($url) {
|
752 |
-
$lang = get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url);
|
753 |
if ($lang) {
|
754 |
-
$url = rewrite_url_lang_param($url, $this->home_url, $this->enable_permalinks_rewrite, $lang, $this->edit_mode);
|
755 |
}
|
756 |
return $url;
|
757 |
}
|
758 |
|
759 |
/**
|
760 |
-
*
|
761 |
-
* @param string $
|
762 |
-
* @return string
|
763 |
*/
|
764 |
-
function
|
765 |
-
$
|
766 |
-
|
767 |
-
|
768 |
-
$uri = get_original_url($uri, '', $lang, array($this->database, 'fetch_original'));
|
769 |
}
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
/**
|
774 |
-
* After saving action, makes sure activity has proper language
|
775 |
-
* @param BP_Activity_Activity $params
|
776 |
-
*/
|
777 |
-
function bp_activity_after_save($params) {
|
778 |
-
// we don't need to modify our own activity stream
|
779 |
-
if ($params->type == 'new_translation') return;
|
780 |
-
if (get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url))
|
781 |
-
bp_activity_update_meta($params->id, 'tp_language', get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url));
|
782 |
}
|
783 |
|
784 |
/**
|
785 |
-
*
|
786 |
-
* @
|
787 |
-
* @param
|
788 |
-
* @return string
|
789 |
*/
|
790 |
-
function
|
791 |
-
$
|
792 |
-
if ($
|
793 |
-
$
|
794 |
}
|
795 |
-
return $
|
796 |
-
}
|
797 |
-
|
798 |
-
/**
|
799 |
-
* Add an item to the activity string upon translation
|
800 |
-
* @global object $bp the global buddypress
|
801 |
-
* @param string $translation
|
802 |
-
* @param string $original
|
803 |
-
* @param string $lang
|
804 |
-
*/
|
805 |
-
function transposh_buddypress_stream($translation, $original, $lang) {
|
806 |
-
global $bp;
|
807 |
-
|
808 |
-
// we must have buddypress...
|
809 |
-
if (!function_exists('bp_activity_add')) return false;
|
810 |
-
|
811 |
-
// we only log translation for logged on users
|
812 |
-
if (!$bp->loggedin_user->id) return;
|
813 |
-
|
814 |
-
/* Because blog, comment, and blog post code execution happens before anything else
|
815 |
-
we may need to manually instantiate the activity component globals */
|
816 |
-
if (!$bp->activity && function_exists('bp_activity_setup_globals'))
|
817 |
-
bp_activity_setup_globals();
|
818 |
-
|
819 |
-
// just got this from buddypress, changed action and content
|
820 |
-
$values = array(
|
821 |
-
'user_id' => $bp->loggedin_user->id,
|
822 |
-
'action' => sprintf(__('%s translated a pharse to %s with transposh:', 'buddypress'), bp_core_get_userlink($bp->loggedin_user->id), substr($GLOBALS['languages'][$lang], 0, strpos($GLOBALS['languages'][$lang], ','))),
|
823 |
-
'content' => "Original: <span class=\"no_translate\">$original</span>\nTranslation: <span class=\"no_translate\">$translation</span>",
|
824 |
-
'primary_link' => '',
|
825 |
-
'component' => $bp->blogs->id,
|
826 |
-
'type' => 'new_translation',
|
827 |
-
'item_id' => false,
|
828 |
-
'secondary_item_id' => false,
|
829 |
-
'recorded_time' => gmdate("Y-m-d H:i:s"),
|
830 |
-
'hide_sitewide' => false
|
831 |
-
);
|
832 |
-
|
833 |
-
return bp_activity_add($values);
|
834 |
}
|
835 |
|
836 |
/**
|
837 |
-
* Modify
|
838 |
-
* @param string $text
|
839 |
-
* @return string
|
840 |
*/
|
841 |
-
function
|
842 |
-
$
|
843 |
-
if (
|
844 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
845 |
}
|
846 |
-
|
847 |
return $text;
|
848 |
}
|
849 |
|
@@ -856,12 +803,12 @@ class transposh_plugin {
|
|
856 |
function request_filter($query) {
|
857 |
//We only do this once, and if we have a lang
|
858 |
$requri = $_SERVER['REQUEST_URI'];
|
859 |
-
$lang = get_language_from_url($requri, $this->home_url);
|
860 |
if ($lang && !$this->got_request) {
|
861 |
|
862 |
$this->got_request = true;
|
863 |
// the trick is to replace the URI and put it back afterwards
|
864 |
-
$_SERVER['REQUEST_URI'] = get_original_url($requri, '', $lang, array($this->database, 'fetch_original'));
|
865 |
global $wp;
|
866 |
$wp->parse_request();
|
867 |
$query = $wp->query_vars;
|
@@ -872,6 +819,16 @@ class transposh_plugin {
|
|
872 |
return $query;
|
873 |
}
|
874 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
875 |
}
|
876 |
|
877 |
$my_transposh_plugin = new transposh_plugin();
|
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
|
39 |
require_once("wp/transposh_options.php");
|
40 |
require_once("wp/transposh_postpublish.php");
|
41 |
require_once("wp/transposh_backup.php");
|
42 |
+
require_once("wp/transposh_3rdparty.php");
|
43 |
|
44 |
/**
|
45 |
* This class represents the complete plugin
|
57 |
public $database;
|
58 |
/** @var transposh_postpublish Happens after editing */
|
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 */
|
92 |
$this->admin = new transposh_plugin_admin($this);
|
93 |
$this->widget = new transposh_plugin_widget($this);
|
94 |
$this->postpublish = new transposh_postpublish($this);
|
95 |
+
$this->third_party = new transposh_3rdparty($this);
|
96 |
|
97 |
// "global" vars
|
98 |
$this->home_url = get_option('home');
|
129 |
add_action('wp_print_styles', array(&$this, 'add_transposh_css'));
|
130 |
add_action('wp_print_scripts', array(&$this, 'add_transposh_js'));
|
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'));
|
167 |
* @return string Modified page buffer
|
168 |
*/
|
169 |
function process_page(&$buffer) {
|
170 |
+
|
171 |
$start_time = microtime(TRUE);
|
172 |
|
173 |
// Refrain from touching the administrative interface and important pages
|
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;
|
228 |
}
|
229 |
}
|
230 |
|
231 |
+
// this is an ajax special case, currently crafted and tested on buddy press, lets hope this won't make hell break loose.
|
232 |
+
// it basically sets language based on referred when accessing wp-load.php (which is the way bp does ajax)
|
233 |
+
|
234 |
+
if (substr($_SERVER['SCRIPT_FILENAME'], -11) == 'wp-load.php') {
|
235 |
+
$this->target_language = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url);
|
236 |
+
}
|
237 |
+
|
238 |
//set the callback for translating the page when it's done
|
239 |
ob_start(array(&$this, "process_page"));
|
240 |
}
|
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;
|
331 |
$wp_locale->text_direction = 'rtl';
|
332 |
}
|
344 |
// redirect according to stored lng cookie, and than according to detection
|
345 |
if (isset($_COOKIE['TR_LNG']) && $this->options->get_widget_allow_set_default_language()) {
|
346 |
if ($_COOKIE['TR_LNG'] != $this->target_language) {
|
347 |
+
$url = transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, $_COOKIE['TR_LNG'], $this->edit_mode);
|
348 |
if ($this->options->is_default_language($_COOKIE['TR_LNG']))
|
349 |
+
$url = transposh_utils::cleanup_url($_SERVER["REQUEST_URI"], $this->home_url);
|
350 |
|
351 |
wp_redirect($url);
|
352 |
exit;
|
353 |
}
|
354 |
} else {
|
355 |
+
$bestlang = transposh_utils::prefered_language(explode(',', $this->options->get_viewable_langs()), $this->options->get_default_language());
|
356 |
// we won't redirect if we should not, or this is a presumable bot
|
357 |
if ($bestlang && $bestlang != $this->target_language && $this->options->get_enable_detect_language() && !(preg_match("#(bot|yandex|validator|google|jeeves|spider|crawler|slurp)#si", $_SERVER['HTTP_USER_AGENT']))) {
|
358 |
+
$url = transposh_utils::rewrite_url_lang_param($_SERVER['REQUEST_URI'], $this->home_url, $this->enable_permalinks_rewrite, $bestlang, $this->edit_mode);
|
359 |
if ($this->options->is_default_language($bestlang))
|
360 |
+
$url = transposh_utils::cleanup_url($_SERVER['REQUEST_URI'], $this->home_url);
|
361 |
|
362 |
wp_redirect($url);
|
363 |
exit;
|
374 |
add_action('pre_get_posts', array(&$this, 'pre_post_search'));
|
375 |
add_action('posts_where_request', array(&$this, 'posts_where_request'));
|
376 |
}
|
377 |
+
if (transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url) && !transposh_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url)) {
|
378 |
+
wp_redirect(transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), false)); //."&stop=y");
|
379 |
exit;
|
380 |
}
|
381 |
}
|
539 |
// those two options show if the script can support said engines
|
540 |
'prefix' => SPAN_PREFIX,
|
541 |
'preferred' => $this->options->get_preferred_translator()
|
542 |
+
);
|
543 |
+
if ($this->edit_mode) $script_params['edit'] = 1;
|
544 |
+
if (in_array($this->target_language, transposh_consts::$bing_languages))
|
545 |
+
$script_params['msn'] = 1;
|
546 |
+
if (in_array($this->target_language, transposh_consts::$google_languages))
|
547 |
+
$script_params['google'] = 1;
|
548 |
+
if (function_exists('curl_init') && in_array($this->target_language, transposh_consts::$google_proxied_languages))
|
549 |
+
$script_params['tgp'] = 1;
|
|
|
550 |
if ($this->options->get_widget_progressbar())
|
551 |
+
$script_params['progress'] = 1;
|
552 |
if (!$this->options->get_enable_auto_translate())
|
553 |
+
$script_params['noauto'] = 1;
|
554 |
+
|
555 |
// 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
|
556 |
wp_localize_script('transposh', 't_jp', $script_params);
|
557 |
|
620 |
// some hackery needed for url translations
|
621 |
// first cut home
|
622 |
if ($this->options->get_enable_url_translate()) {
|
623 |
+
$href = transposh_utils::translate_url($href, $this->home_url, $this->target_language, array(&$this->database, 'fetch_translation'));
|
624 |
}
|
625 |
+
$href = transposh_utils::rewrite_url_lang_param($href, $this->home_url, $this->enable_permalinks_rewrite, $this->target_language, $this->edit_mode, $use_params);
|
626 |
|
627 |
return $href;
|
628 |
}
|
703 |
}
|
704 |
|
705 |
/**
|
706 |
+
* Runs a scheduled backup
|
|
|
|
|
|
|
|
|
707 |
*/
|
708 |
+
function run_backup() {
|
709 |
+
|
710 |
+
$my_transposh_backup = new transposh_backup($this);
|
711 |
+
$my_transposh_backup->do_backup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
712 |
}
|
713 |
|
714 |
/**
|
715 |
+
* Runs a restore
|
716 |
*/
|
717 |
+
function run_restore() {
|
718 |
|
719 |
$my_transposh_backup = new transposh_backup($this);
|
720 |
+
$my_transposh_backup->do_restore();
|
721 |
}
|
722 |
|
723 |
/**
|
726 |
* @param int $post_id
|
727 |
*/
|
728 |
function add_comment_meta_settings($post_id) {
|
729 |
+
if (transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url))
|
730 |
+
add_comment_meta($post_id, 'tp_language', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), true);
|
731 |
}
|
732 |
|
733 |
/**
|
737 |
* @return string fixed url
|
738 |
*/
|
739 |
function comment_post_redirect_filter($url) {
|
740 |
+
$lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url);
|
741 |
if ($lang) {
|
742 |
+
$url = transposh_utils::rewrite_url_lang_param($url, $this->home_url, $this->enable_permalinks_rewrite, $lang, $this->edit_mode);
|
743 |
}
|
744 |
return $url;
|
745 |
}
|
746 |
|
747 |
/**
|
748 |
+
* Modify comments to include the relevant language span
|
749 |
+
* @param string $text
|
750 |
+
* @return string
|
751 |
*/
|
752 |
+
function comment_text_wrap($text) {
|
753 |
+
$comment_lang = get_comment_meta(get_comment_ID(), 'tp_language', true);
|
754 |
+
if ($comment_lang) {
|
755 |
+
$text = "<span lang =\"$comment_lang\">" . $text . "</span>";
|
|
|
756 |
}
|
757 |
+
|
758 |
+
return $text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
759 |
}
|
760 |
|
761 |
/**
|
762 |
+
* Modify posts to have language wrapping
|
763 |
+
* @global int $id the post id
|
764 |
+
* @param string $text the post text (or title text)
|
765 |
+
* @return string wrapped text
|
766 |
*/
|
767 |
+
function post_content_wrap($text) {
|
768 |
+
$lang = get_post_meta($GLOBALS['id'], 'tp_language', true);
|
769 |
+
if ($lang) {
|
770 |
+
$text = "<span lang =\"$lang\">" . $text . "</span>";
|
771 |
}
|
772 |
+
return $text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
773 |
}
|
774 |
|
775 |
/**
|
776 |
+
* Modify post title to have language wrapping
|
777 |
+
* @param string $text the post title text
|
778 |
+
* @return string wrapped text
|
779 |
*/
|
780 |
+
function post_wrap($text, $id = 0) {
|
781 |
+
$id = (is_object($id)) ? $id->ID : $id;
|
782 |
+
if (!$id) return $text;
|
783 |
+
$lang = get_post_meta($id, 'tp_language', true);
|
784 |
+
if ($lang) {
|
785 |
+
if (strpos($_SERVER['REQUEST_URI'], 'wp-admin/edit') !== false) {
|
786 |
+
|
787 |
+
$plugpath = parse_url($this->transposh_plugin_url, PHP_URL_PATH);
|
788 |
+
list($langeng, $langorig, $langflag) = explode(',', transposh_consts::$languages[$lang]);
|
789 |
+
$text = transposh_utils::display_flag("$plugpath/img/flags", $langflag, $langorig, false) . ' ' . $text;
|
790 |
+
} else {
|
791 |
+
$text = "<span lang =\"$lang\">" . $text . "</span>";
|
792 |
+
}
|
793 |
}
|
|
|
794 |
return $text;
|
795 |
}
|
796 |
|
803 |
function request_filter($query) {
|
804 |
//We only do this once, and if we have a lang
|
805 |
$requri = $_SERVER['REQUEST_URI'];
|
806 |
+
$lang = transposh_utils::get_language_from_url($requri, $this->home_url);
|
807 |
if ($lang && !$this->got_request) {
|
808 |
|
809 |
$this->got_request = true;
|
810 |
// the trick is to replace the URI and put it back afterwards
|
811 |
+
$_SERVER['REQUEST_URI'] = transposh_utils::get_original_url($requri, '', $lang, array($this->database, 'fetch_original'));
|
812 |
global $wp;
|
813 |
$wp->parse_request();
|
814 |
$query = $wp->query_vars;
|
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 |
+
|
832 |
}
|
833 |
|
834 |
$my_transposh_plugin = new transposh_plugin();
|
widgets/dropdown/tpw_image_dropdown.php
CHANGED
@@ -10,21 +10,15 @@
|
|
10 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
*/
|
12 |
|
13 |
-
/*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
* it under the terms of the GNU General Public License as published by
|
17 |
-
* the Free Software Foundation; either version 2 of the License, or
|
18 |
-
* (at your option) any later version.
|
19 |
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
* GNU General Public License for more details.
|
24 |
*
|
25 |
-
*
|
26 |
-
* along with this program; if not, write to the Free Software
|
27 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
*/
|
29 |
|
30 |
/**
|
@@ -53,8 +47,8 @@ function tp_widget_do($args) {
|
|
53 |
echo '<dt><a href="#"><span>Select language</span></a></dt><dd><ul>';
|
54 |
|
55 |
foreach ($args as $langrecord) {
|
56 |
-
|
57 |
-
|
58 |
}
|
59 |
|
60 |
echo '</ul></dd></dl>';
|
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 |
echo '<dt><a href="#"><span>Select language</span></a></dt><dd><ul>';
|
48 |
|
49 |
foreach ($args as $langrecord) {
|
50 |
+
$is_selected = $langrecord['active'] ? " selected=\"selected\"" : "";
|
51 |
+
echo '<li><a href="#"><img class="flag" src="' . "$plugpath/img/flags/{$langrecord['flag']}" . '.png" alt="' . $langrecord['langorig'] . '"/> ' . $langrecord['langorig'] . '<span class="value">' . $langrecord['isocode'] . '</span></a></li>';
|
52 |
}
|
53 |
|
54 |
echo '</ul></dd></dl>';
|
widgets/flags/tpw_flags.php
CHANGED
@@ -10,21 +10,15 @@
|
|
10 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
*/
|
12 |
|
13 |
-
/*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
* it under the terms of the GNU General Public License as published by
|
17 |
-
* the Free Software Foundation; either version 2 of the License, or
|
18 |
-
* (at your option) any later version.
|
19 |
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
* GNU General Public License for more details.
|
24 |
*
|
25 |
-
*
|
26 |
-
* along with this program; if not, write to the Free Software
|
27 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
*/
|
29 |
|
30 |
/**
|
@@ -47,9 +41,9 @@ function tp_widget_do($args) {
|
|
47 |
|
48 |
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
49 |
foreach ($args as $langrecord) {
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
}
|
54 |
echo "</div>";
|
55 |
}
|
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 |
/**
|
41 |
|
42 |
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
43 |
foreach ($args as $langrecord) {
|
44 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .
|
45 |
+
transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) .
|
46 |
+
"</a>";
|
47 |
}
|
48 |
echo "</div>";
|
49 |
}
|
widgets/flags/tpw_flags_css.php
CHANGED
@@ -10,21 +10,15 @@
|
|
10 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
*/
|
12 |
|
13 |
-
/*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
* it under the terms of the GNU General Public License as published by
|
17 |
-
* the Free Software Foundation; either version 2 of the License, or
|
18 |
-
* (at your option) any later version.
|
19 |
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
* GNU General Public License for more details.
|
24 |
*
|
25 |
-
*
|
26 |
-
* along with this program; if not, write to the Free Software
|
27 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
*/
|
29 |
|
30 |
/**
|
@@ -42,9 +36,9 @@ function tp_widget_needs_post_url() {
|
|
42 |
function tp_widget_do($args) {
|
43 |
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
44 |
foreach ($args as $langrecord) {
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
}
|
49 |
echo "</div>";
|
50 |
}
|
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 |
/**
|
36 |
function tp_widget_do($args) {
|
37 |
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
38 |
foreach ($args as $langrecord) {
|
39 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .
|
40 |
+
transposh_utils::display_flag("", $langrecord['flag'], $langrecord['langorig'], true) .
|
41 |
+
"</a>";
|
42 |
}
|
43 |
echo "</div>";
|
44 |
}
|
widgets/flagslist/tpw_list_with_flags.php
CHANGED
@@ -10,21 +10,15 @@
|
|
10 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
*/
|
12 |
|
13 |
-
/*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
* it under the terms of the GNU General Public License as published by
|
17 |
-
* the Free Software Foundation; either version 2 of the License, or
|
18 |
-
* (at your option) any later version.
|
19 |
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
* GNU General Public License for more details.
|
24 |
*
|
25 |
-
*
|
26 |
-
* along with this program; if not, write to the Free Software
|
27 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
*/
|
29 |
|
30 |
/**
|
@@ -56,9 +50,9 @@ function tp_widget_do($args) {
|
|
56 |
|
57 |
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
58 |
foreach ($args as $langrecord) {
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
}
|
63 |
echo "</div>";
|
64 |
}
|
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 |
/**
|
50 |
|
51 |
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
52 |
foreach ($args as $langrecord) {
|
53 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .
|
54 |
+
transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . "</a>";
|
55 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>";
|
56 |
}
|
57 |
echo "</div>";
|
58 |
}
|
widgets/flagslist/tpw_list_with_flags_css.php
CHANGED
@@ -10,21 +10,15 @@
|
|
10 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
*/
|
12 |
|
13 |
-
/*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
* it under the terms of the GNU General Public License as published by
|
17 |
-
* the Free Software Foundation; either version 2 of the License, or
|
18 |
-
* (at your option) any later version.
|
19 |
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
* GNU General Public License for more details.
|
24 |
*
|
25 |
-
*
|
26 |
-
* along with this program; if not, write to the Free Software
|
27 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
*/
|
29 |
|
30 |
/**
|
@@ -52,9 +46,9 @@ function tp_widget_css() {
|
|
52 |
function tp_widget_do($args) {
|
53 |
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
54 |
foreach ($args as $langrecord) {
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
}
|
59 |
echo "</div>";
|
60 |
}
|
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 |
/**
|
46 |
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>";
|
54 |
}
|
widgets/tpw_default.php
CHANGED
@@ -10,21 +10,15 @@
|
|
10 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
*/
|
12 |
|
13 |
-
/*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
* it under the terms of the GNU General Public License as published by
|
17 |
-
* the Free Software Foundation; either version 2 of the License, or
|
18 |
-
* (at your option) any later version.
|
19 |
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
* GNU General Public License for more details.
|
24 |
*
|
25 |
-
*
|
26 |
-
* along with this program; if not, write to the Free Software
|
27 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
*/
|
29 |
|
30 |
/*
|
@@ -44,8 +38,8 @@ function tp_widget_do($args) {
|
|
44 |
echo '<select name="lang" id="lang" onchange="Javascript:this.form.submit();">'; // this is a select box which posts on change
|
45 |
echo '<option value="none">[Language]</option>';
|
46 |
foreach ($args as $langrecord) {
|
47 |
-
|
48 |
-
|
49 |
}
|
50 |
echo "</select><br/>";
|
51 |
echo "</span>";
|
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 |
/*
|
38 |
echo '<select name="lang" id="lang" onchange="Javascript:this.form.submit();">'; // this is a select box which posts on change
|
39 |
echo '<option value="none">[Language]</option>';
|
40 |
foreach ($args as $langrecord) {
|
41 |
+
$is_selected = $langrecord['active'] ? " selected=\"selected\"" : "";
|
42 |
+
echo "<option value=\"{$langrecord['isocode']}\"{$is_selected}>{$langrecord['langorig']}</option>";
|
43 |
}
|
44 |
echo "</select><br/>";
|
45 |
echo "</span>";
|
wp/transposh_3rdparty.php
ADDED
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
/*
|
15 |
+
* This file handles functions relevant to specific third party plugins
|
16 |
+
*/
|
17 |
+
|
18 |
+
class transposh_3rdparty {
|
19 |
+
|
20 |
+
/** @var transposh_plugin Container class */
|
21 |
+
private $transposh;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Construct our class
|
25 |
+
* @param transposh_plugin $transposh
|
26 |
+
*/
|
27 |
+
function transposh_3rdparty(&$transposh) {
|
28 |
+
$this->transposh = &$transposh;
|
29 |
+
|
30 |
+
// supercache invalidation of pages - first lets find if supercache is here
|
31 |
+
if (function_exists('wp_super_cache_init')) {
|
32 |
+
add_action('transposh_translation_posted', array(&$this, 'super_cache_invalidate'));
|
33 |
+
}
|
34 |
+
|
35 |
+
// buddypress compatability
|
36 |
+
add_filter('bp_uri', array(&$this, 'bp_uri_filter'));
|
37 |
+
add_filter('bp_get_activity_content_body', array(&$this, 'bp_get_activity_content_body'), 10, 2);
|
38 |
+
add_action('bp_activity_after_save', array(&$this, 'bp_activity_after_save'));
|
39 |
+
add_action('transposh_human_translation', array(&$this, 'transposh_buddypress_stream'), 10, 3);
|
40 |
+
|
41 |
+
// google xml sitemaps - with patch
|
42 |
+
add_action("sm_addurl", array(&$this, 'add_sm_transposh_urls'));
|
43 |
+
}
|
44 |
+
|
45 |
+
function super_cache_invalidate() {
|
46 |
+
//Now, we are actually using the referrer and not the request, with some precautions
|
47 |
+
$GLOBALS['wp_cache_request_uri'] = substr($_SERVER['HTTP_REFERER'], stripos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) + strlen($_SERVER[''] . $_SERVER['HTTP_HOST']));
|
48 |
+
$GLOBALS['wp_cache_request_uri'] = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\?.*)?$/", '', $GLOBALS['wp_cache_request_uri']))));
|
49 |
+
// get some supercache variables
|
50 |
+
extract(wp_super_cache_init());
|
51 |
+
|
52 |
+
// this is hackery for logged in users, a cookie is added to the request somehow and gzip is not correctly set, so we forcefully fix this
|
53 |
+
if (!$cache_file) {
|
54 |
+
$GLOBALS['wp_cache_gzip_encoding'] = gzip_accepted();
|
55 |
+
unset($_COOKIE[key($_COOKIE)]);
|
56 |
+
extract(wp_super_cache_init());
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
$dir = get_current_url_supercache_dir();
|
61 |
+
// delete possible files that we can figure out, not deleting files for other cookies for example, but will do the trick in most cases
|
62 |
+
$cache_fname = "{$dir}index.html";
|
63 |
+
|
64 |
+
@unlink($cache_fname);
|
65 |
+
$cache_fname = "{$dir}index.html.gz";
|
66 |
+
|
67 |
+
@unlink($cache_fname);
|
68 |
+
|
69 |
+
@unlink($cache_file);
|
70 |
+
|
71 |
+
@unlink($meta_pathname);
|
72 |
+
|
73 |
+
// go at edit pages too
|
74 |
+
$GLOBALS['wp_cache_request_uri'] .="?edit=1";
|
75 |
+
extract(wp_super_cache_init());
|
76 |
+
|
77 |
+
|
78 |
+
@unlink($cache_file);
|
79 |
+
|
80 |
+
@unlink($meta_pathname);
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* This filter method helps buddypress understand the transposh generated URLs
|
85 |
+
* @param string $uri The url that was originally received
|
86 |
+
* @return string The url that buddypress should see
|
87 |
+
*/
|
88 |
+
function bp_uri_filter($uri) {
|
89 |
+
$lang = transposh_utils::get_language_from_url($uri, $this->transposh->home_url);
|
90 |
+
$uri = transposh_utils::cleanup_url($uri, $this->transposh->home_url);
|
91 |
+
if ($this->transposh->options->get_enable_url_translate()) {
|
92 |
+
$uri = transposh_utils::get_original_url($uri, '', $lang, array($this->transposh->database, 'fetch_original'));
|
93 |
+
}
|
94 |
+
return $uri;
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* After saving action, makes sure activity has proper language
|
99 |
+
* @param BP_Activity_Activity $params
|
100 |
+
*/
|
101 |
+
function bp_activity_after_save($params) {
|
102 |
+
// we don't need to modify our own activity stream
|
103 |
+
if ($params->type == 'new_translation') return;
|
104 |
+
if (transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url))
|
105 |
+
bp_activity_update_meta($params->id, 'tp_language', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url));
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Change the display of activity content using the transposh meta
|
110 |
+
* @param string $content
|
111 |
+
* @param BP_Activity_Activity $activity
|
112 |
+
* @return string modified content
|
113 |
+
*/
|
114 |
+
function bp_get_activity_content_body($content, $activity) {
|
115 |
+
$activity_lang = bp_activity_get_meta($activity->id, 'tp_language');
|
116 |
+
if ($activity_lang) {
|
117 |
+
$content = "<span lang =\"$activity_lang\">" . $content . "</span>";
|
118 |
+
}
|
119 |
+
return $content;
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Add an item to the activity string upon translation
|
124 |
+
* @global object $bp the global buddypress
|
125 |
+
* @param string $translation
|
126 |
+
* @param string $original
|
127 |
+
* @param string $lang
|
128 |
+
*/
|
129 |
+
function transposh_buddypress_stream($translation, $original, $lang) {
|
130 |
+
global $bp;
|
131 |
+
|
132 |
+
// we must have buddypress...
|
133 |
+
if (!function_exists('bp_activity_add')) return false;
|
134 |
+
|
135 |
+
// we only log translation for logged on users
|
136 |
+
if (!$bp->loggedin_user->id) return;
|
137 |
+
|
138 |
+
/* Because blog, comment, and blog post code execution happens before anything else
|
139 |
+
we may need to manually instantiate the activity component globals */
|
140 |
+
if (!$bp->activity && function_exists('bp_activity_setup_globals'))
|
141 |
+
bp_activity_setup_globals();
|
142 |
+
|
143 |
+
// just got this from buddypress, changed action and content
|
144 |
+
$values = array(
|
145 |
+
'user_id' => $bp->loggedin_user->id,
|
146 |
+
'action' => sprintf(__('%s translated a phrase to %s with transposh:', 'buddypress'), bp_core_get_userlink($bp->loggedin_user->id), substr(transposh_consts::$languages[$lang], 0, strpos(transposh_consts::$languages[$lang], ','))),
|
147 |
+
'content' => "Original: <span class=\"no_translate\">$original</span>\nTranslation: <span class=\"no_translate\">$translation</span>",
|
148 |
+
'primary_link' => '',
|
149 |
+
'component' => $bp->blogs->id,
|
150 |
+
'type' => 'new_translation',
|
151 |
+
'item_id' => false,
|
152 |
+
'secondary_item_id' => false,
|
153 |
+
'recorded_time' => gmdate("Y-m-d H:i:s"),
|
154 |
+
'hide_sitewide' => false
|
155 |
+
);
|
156 |
+
|
157 |
+
return bp_activity_add($values);
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* This function integrates with google sitemap generator, and adds for each viewable language, the rest of the languages url
|
162 |
+
* Also - priority is reduced by 0.2
|
163 |
+
* And this requires the following line at the sitemap-core.php, add-url function (line 1509 at version 3.2.2)
|
164 |
+
* do_action('sm_addurl', &$page);
|
165 |
+
* @param GoogleSitemapGeneratorPage $sm_page Object containing the page information
|
166 |
+
*/
|
167 |
+
function add_sm_transposh_urls(&$sm_page) {
|
168 |
+
|
169 |
+
// we need the generator object (we know it must exist...)
|
170 |
+
$generatorObject = &GoogleSitemapGenerator::GetInstance();
|
171 |
+
// we reduce the priorty by 0.2, but not below zero
|
172 |
+
$sm_page->SetProprity(max($sm_page->GetPriority() - 0.2, 0));
|
173 |
+
|
174 |
+
$viewable_langs = explode(',', $this->transposh->options->get_viewable_langs());
|
175 |
+
$orig_url = $sm_page->GetUrl();
|
176 |
+
foreach ($viewable_langs as $lang) {
|
177 |
+
if (!$this->transposh->options->is_default_language($lang)) {
|
178 |
+
$newloc = $orig_url;
|
179 |
+
if ($this->transposh->options->get_enable_url_translate()) {
|
180 |
+
$newloc = transposh_utils::translate_url($newloc, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation'));
|
181 |
+
}
|
182 |
+
$newloc = transposh_utils::rewrite_url_lang_param($newloc, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, false);
|
183 |
+
$sm_page->SetUrl($newloc);
|
184 |
+
$generatorObject->AddElement($sm_page);
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
}
|
190 |
+
?>
|
wp/transposh_admin.php
CHANGED
@@ -1,27 +1,21 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* it under the terms of the GNU General Public License as published by
|
7 |
-
* the Free Software Foundation; either version 2 of the License, or
|
8 |
-
* (at your option) any later version.
|
9 |
-
*
|
10 |
-
* This program is distributed in the hope that it will be useful,
|
11 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
* GNU General Public License for more details.
|
14 |
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*
|
18 |
*
|
19 |
-
*
|
20 |
*/
|
21 |
|
22 |
/*
|
23 |
* Provide the admin page for configuring the translation options. eg. what languages ?
|
24 |
* who is allowed to translate ?
|
|
|
|
|
25 |
*/
|
26 |
|
27 |
define('TR_NONCE', "transposh_nonce");
|
@@ -171,10 +165,8 @@ class transposh_plugin_admin {
|
|
171 |
wp_enqueue_script('transposh_control', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhcontrol.js', array(), TRANSPOSH_PLUGIN_VER, true);
|
172 |
wp_localize_script('transposh_control', 't_jp', array(
|
173 |
'post_url' => $this->transposh->post_url,
|
174 |
-
//'msn_langs' => json_encode($GLOBALS['bing_languages']),
|
175 |
-
//'google_lang' => json_encode($GLOBALS['google_languages']),
|
176 |
'preferred' => $this->transposh->options->get_preferred_translator(),
|
177 |
-
'l10n_print_after' => 't_jp.g_langs = ' . json_encode(
|
178 |
/* ,
|
179 |
'plugin_url' => $this->transposh_plugin_url,
|
180 |
'edit' => ($this->edit_mode? '1' : ''),
|
@@ -203,6 +195,7 @@ class transposh_plugin_admin {
|
|
203 |
add_meta_box('transposh-contentbox-translation', 'Translation settings', array(&$this, 'on_contentbox_translation_content'), $this->pagehook, 'normal', 'core');
|
204 |
add_meta_box('transposh-contentbox-autotranslation', 'Automatic translation settings', array(&$this, 'on_contentbox_auto_translation_content'), $this->pagehook, 'normal', 'core');
|
205 |
add_meta_box('transposh-contentbox-general', 'Generic settings', array(&$this, 'on_contentbox_generic_content'), $this->pagehook, 'normal', 'core');
|
|
|
206 |
}
|
207 |
|
208 |
//executed to show the plugins complete admin page
|
@@ -387,10 +380,10 @@ class transposh_plugin_admin {
|
|
387 |
</style>';
|
388 |
|
389 |
// this is the default language location
|
390 |
-
list ($langname, $langorigname, $flag) = explode(",",
|
391 |
echo '<div id="default_lang" style="overflow:auto;padding-bottom:10px;">Default Language (drag another language here to make it default)';
|
392 |
echo '<ul id="default_list"><li id="' . $this->transposh->options->get_default_language() . '" class="languages">'
|
393 |
-
. display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, $langorigname, false/* $this->transposh->options->get_widget_css_flags() */)
|
394 |
. '<input type="hidden" name="languages[]" value="' . $this->transposh->options->get_default_language() . '" />'
|
395 |
. ' <span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></li>';
|
396 |
echo '</ul></div>';
|
@@ -401,14 +394,14 @@ class transposh_plugin_admin {
|
|
401 |
list ($langname, $langorigname, $flag) = explode(",", $langrecord);
|
402 |
echo '<li id="' . $langcode . '" class="languages ' . ($this->transposh->options->is_viewable_language($langcode) || $this->transposh->options->is_default_language($langcode) ? "active" : "")
|
403 |
. (!$this->transposh->options->is_viewable_language($langcode) && $this->transposh->options->is_editable_language($langcode) ? "translateable" : "") . '"><div style="float:left">'
|
404 |
-
. display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, false /* $langorigname,$this->transposh->options->get_widget_css_flags() */)
|
405 |
. '<input type="hidden" name="languages[]" value="' . $langcode . ($this->transposh->options->is_viewable_language($langcode) ? ",v" : ",") . ($this->transposh->options->is_viewable_language($langcode) ? ",t" : ",") . '" />'
|
406 |
. ' <span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></div>';
|
407 |
-
if (in_array($langcode,
|
408 |
echo '<img width="16" height="16" alt="g" class="logoicon" title="Language supported by google translate" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/googleicon.png"/>';
|
409 |
-
if (in_array($langcode,
|
410 |
echo '<img width="16" height="16" alt="b" class="logoicon" title="Language supported by bing translate" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/bingicon.png"/>';
|
411 |
-
if (in_array($langcode,
|
412 |
echo '<img width="16" height="16" alt="r" class="logoicon" title="Language is written from right to left" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/rtlicon.png"/>';
|
413 |
echo '</li>';
|
414 |
}
|
@@ -536,6 +529,14 @@ class transposh_plugin_admin {
|
|
536 |
echo '<a href="http://transposh.org/services/index.php?flags='.$flags.'">Gen sprites</a>'; */
|
537 |
}
|
538 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
539 |
function on_contentbox_community_content($data) {
|
540 |
echo '<h4>Backup service for human translation</h4>';
|
541 |
echo '<input type="radio" value="1" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 1) . '/>Enable daily backup<br/>';
|
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 |
/*
|
15 |
* Provide the admin page for configuring the translation options. eg. what languages ?
|
16 |
* who is allowed to translate ?
|
17 |
+
*
|
18 |
+
* adapted metabox sample code from http://www.code-styling.de/
|
19 |
*/
|
20 |
|
21 |
define('TR_NONCE', "transposh_nonce");
|
165 |
wp_enqueue_script('transposh_control', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhcontrol.js', array(), TRANSPOSH_PLUGIN_VER, true);
|
166 |
wp_localize_script('transposh_control', 't_jp', array(
|
167 |
'post_url' => $this->transposh->post_url,
|
|
|
|
|
168 |
'preferred' => $this->transposh->options->get_preferred_translator(),
|
169 |
+
'l10n_print_after' => 't_jp.g_langs = ' . json_encode(transposh_consts::$google_languages) . '; t_jp.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';'/*
|
170 |
/* ,
|
171 |
'plugin_url' => $this->transposh_plugin_url,
|
172 |
'edit' => ($this->edit_mode? '1' : ''),
|
195 |
add_meta_box('transposh-contentbox-translation', 'Translation settings', array(&$this, 'on_contentbox_translation_content'), $this->pagehook, 'normal', 'core');
|
196 |
add_meta_box('transposh-contentbox-autotranslation', 'Automatic translation settings', array(&$this, 'on_contentbox_auto_translation_content'), $this->pagehook, 'normal', 'core');
|
197 |
add_meta_box('transposh-contentbox-general', 'Generic settings', array(&$this, 'on_contentbox_generic_content'), $this->pagehook, 'normal', 'core');
|
198 |
+
add_meta_box('transposh-contentbox-database', 'Database maintenance', array(&$this, 'on_contentbox_database_content'), $this->pagehook, 'normal', 'core');
|
199 |
}
|
200 |
|
201 |
//executed to show the plugins complete admin page
|
380 |
</style>';
|
381 |
|
382 |
// this is the default language location
|
383 |
+
list ($langname, $langorigname, $flag) = explode(",", transposh_consts::$languages[$this->transposh->options->get_default_language()]);
|
384 |
echo '<div id="default_lang" style="overflow:auto;padding-bottom:10px;">Default Language (drag another language here to make it default)';
|
385 |
echo '<ul id="default_list"><li id="' . $this->transposh->options->get_default_language() . '" class="languages">'
|
386 |
+
. transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, $langorigname, false/* $this->transposh->options->get_widget_css_flags() */)
|
387 |
. '<input type="hidden" name="languages[]" value="' . $this->transposh->options->get_default_language() . '" />'
|
388 |
. ' <span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></li>';
|
389 |
echo '</ul></div>';
|
394 |
list ($langname, $langorigname, $flag) = explode(",", $langrecord);
|
395 |
echo '<li id="' . $langcode . '" class="languages ' . ($this->transposh->options->is_viewable_language($langcode) || $this->transposh->options->is_default_language($langcode) ? "active" : "")
|
396 |
. (!$this->transposh->options->is_viewable_language($langcode) && $this->transposh->options->is_editable_language($langcode) ? "translateable" : "") . '"><div style="float:left">'
|
397 |
+
. transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, false /* $langorigname,$this->transposh->options->get_widget_css_flags() */)
|
398 |
. '<input type="hidden" name="languages[]" value="' . $langcode . ($this->transposh->options->is_viewable_language($langcode) ? ",v" : ",") . ($this->transposh->options->is_viewable_language($langcode) ? ",t" : ",") . '" />'
|
399 |
. ' <span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></div>';
|
400 |
+
if (in_array($langcode, transposh_consts::$google_languages))
|
401 |
echo '<img width="16" height="16" alt="g" class="logoicon" title="Language supported by google translate" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/googleicon.png"/>';
|
402 |
+
if (in_array($langcode, transposh_consts::$bing_languages))
|
403 |
echo '<img width="16" height="16" alt="b" class="logoicon" title="Language supported by bing translate" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/bingicon.png"/>';
|
404 |
+
if (in_array($langcode, transposh_consts::$rtl_languages))
|
405 |
echo '<img width="16" height="16" alt="r" class="logoicon" title="Language is written from right to left" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/rtlicon.png"/>';
|
406 |
echo '</li>';
|
407 |
}
|
529 |
echo '<a href="http://transposh.org/services/index.php?flags='.$flags.'">Gen sprites</a>'; */
|
530 |
}
|
531 |
|
532 |
+
function on_contentbox_database_content($data) {
|
533 |
+
/*
|
534 |
+
* Insert two buttons allowing removal of automated translations from database
|
535 |
+
*/
|
536 |
+
echo '<div style="margin:10px 0"><a id="transposh-clean-auto" href="#" nonce="'. wp_create_nonce('transposh-clean').'" class="button">Clean all automated translations</a></div>';
|
537 |
+
echo '<div style="margin:10px 0"><a id="transposh-clean-auto14" href="#" nonce="'. wp_create_nonce('transposh-clean').'" class="button">Clean automated translations older than 14 days</a></div>';
|
538 |
+
}
|
539 |
+
|
540 |
function on_contentbox_community_content($data) {
|
541 |
echo '<h4>Backup service for human translation</h4>';
|
542 |
echo '<input type="radio" value="1" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 1) . '/>Enable daily backup<br/>';
|
wp/transposh_ajax.php
CHANGED
@@ -1,20 +1,14 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* it under the terms of the GNU General Public License as published by
|
7 |
-
* the Free Software Foundation; either version 2 of the License, or
|
8 |
-
* (at your option) any later version.
|
9 |
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
-
* GNU General Public License for more details.
|
14 |
*
|
15 |
-
*
|
16 |
-
* along with this program; if not, write to the Free Software
|
17 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
19 |
|
20 |
/*
|
@@ -45,48 +39,8 @@ if (file_exists($root . $self . '/wp-load.php')) {
|
|
45 |
}
|
46 |
// the case of posted translation
|
47 |
if (isset($_POST['translation_posted'])) {
|
48 |
-
|
49 |
-
|
50 |
-
//Now, we are actually using the referrer and not the request, with some precautions
|
51 |
-
$GLOBALS['wp_cache_request_uri'] = substr($_SERVER['HTTP_REFERER'], stripos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) + strlen($_SERVER[''] . $_SERVER['HTTP_HOST']));
|
52 |
-
$GLOBALS['wp_cache_request_uri'] = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\?.*)?$/", '', $GLOBALS['wp_cache_request_uri']))));
|
53 |
-
// get some supercache variables
|
54 |
-
extract(wp_super_cache_init());
|
55 |
-
|
56 |
-
// this is hackery for logged in users, a cookie is added to the request somehow and gzip is not correctly set, so we forcefully fix this
|
57 |
-
if (!$cache_file) {
|
58 |
-
$GLOBALS['wp_cache_gzip_encoding'] = gzip_accepted();
|
59 |
-
unset($_COOKIE[key($_COOKIE)]);
|
60 |
-
extract(wp_super_cache_init());
|
61 |
-
|
62 |
-
}
|
63 |
-
|
64 |
-
$dir = get_current_url_supercache_dir();
|
65 |
-
// delete possible files that we can figure out, not deleting files for other cookies for example, but will do the trick in most cases
|
66 |
-
$cache_fname = "{$dir}index.html";
|
67 |
-
|
68 |
-
@unlink($cache_fname);
|
69 |
-
$cache_fname = "{$dir}index.html.gz";
|
70 |
-
|
71 |
-
@unlink($cache_fname);
|
72 |
-
|
73 |
-
@unlink($cache_file);
|
74 |
-
|
75 |
-
@unlink($meta_pathname);
|
76 |
-
|
77 |
-
// go at edit pages too
|
78 |
-
$GLOBALS['wp_cache_request_uri'] .="?edit=1";
|
79 |
-
extract(wp_super_cache_init());
|
80 |
-
|
81 |
-
|
82 |
-
@unlink($cache_file);
|
83 |
-
|
84 |
-
@unlink($meta_pathname);
|
85 |
-
}
|
86 |
-
|
87 |
-
if ($_POST['translation_posted'] == 2) {
|
88 |
-
$my_transposh_plugin->database->update_translation();
|
89 |
-
}
|
90 |
}
|
91 |
// getting translation history
|
92 |
elseif (isset($_GET['tr_token_hist'])) {
|
@@ -98,12 +52,12 @@ elseif (isset($_GET['tr_phrases_post'])) {
|
|
98 |
}
|
99 |
// set the cookie with ajax, no redirect needed
|
100 |
elseif (isset($_GET['tr_cookie'])) {
|
101 |
-
setcookie('TR_LNG', get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN);
|
102 |
|
103 |
}
|
104 |
// Set our cookie and return (if no js works - or we are in the default language)
|
105 |
elseif (isset($_GET['tr_cookie_bck'])) {
|
106 |
-
setcookie('TR_LNG', get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN);
|
107 |
if ($_SERVER['HTTP_REFERER']) {
|
108 |
wp_redirect($_SERVER['HTTP_REFERER']);
|
109 |
} else {
|
@@ -123,7 +77,8 @@ elseif (isset($_GET['tgp'])) {
|
|
123 |
// we need curl for this proxy
|
124 |
if (!function_exists('curl_init')) return;
|
125 |
// we want to avoid unneeded work or dos attacks on languages we don't support
|
126 |
-
if (!in_array($_GET['tgl'],
|
|
|
127 |
$url = 'http://translate.google.com/translate_a/t?client=a&text=' . urlencode($_GET['tgp']) . '&tl=' . $_GET['tgl'] . '&sl=auto';
|
128 |
$ch = curl_init();
|
129 |
curl_setopt($ch, CURLOPT_URL, $url);
|
@@ -139,4 +94,14 @@ elseif (isset($_GET['tgp'])) {
|
|
139 |
elseif (isset($_GET['backup'])) {
|
140 |
$my_transposh_plugin->run_backup();
|
141 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
?>
|
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 |
/*
|
39 |
}
|
40 |
// the case of posted translation
|
41 |
if (isset($_POST['translation_posted'])) {
|
42 |
+
do_action('transposh_translation_posted');
|
43 |
+
$my_transposh_plugin->database->update_translation();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
// getting translation history
|
46 |
elseif (isset($_GET['tr_token_hist'])) {
|
52 |
}
|
53 |
// set the cookie with ajax, no redirect needed
|
54 |
elseif (isset($_GET['tr_cookie'])) {
|
55 |
+
setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN);
|
56 |
|
57 |
}
|
58 |
// Set our cookie and return (if no js works - or we are in the default language)
|
59 |
elseif (isset($_GET['tr_cookie_bck'])) {
|
60 |
+
setcookie('TR_LNG', transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url), time() + 90 * 24 * 60 * 60, COOKIEPATH, COOKIE_DOMAIN);
|
61 |
if ($_SERVER['HTTP_REFERER']) {
|
62 |
wp_redirect($_SERVER['HTTP_REFERER']);
|
63 |
} else {
|
77 |
// we need curl for this proxy
|
78 |
if (!function_exists('curl_init')) return;
|
79 |
// we want to avoid unneeded work or dos attacks on languages we don't support
|
80 |
+
if (!in_array($_GET['tgl'], transposh_consts::$google_proxied_languages) || !$my_transposh_plugin->options->is_editable_language($_GET['tgl']))
|
81 |
+
return;
|
82 |
$url = 'http://translate.google.com/translate_a/t?client=a&text=' . urlencode($_GET['tgp']) . '&tl=' . $_GET['tgl'] . '&sl=auto';
|
83 |
$ch = curl_init();
|
84 |
curl_setopt($ch, CURLOPT_URL, $url);
|
94 |
elseif (isset($_GET['backup'])) {
|
95 |
$my_transposh_plugin->run_backup();
|
96 |
}
|
97 |
+
// Start restore on demand
|
98 |
+
elseif (isset($_GET['restore'])) {
|
99 |
+
$my_transposh_plugin->run_restore();
|
100 |
+
}
|
101 |
+
// Start cleanup on demand
|
102 |
+
elseif (isset($_GET['cleanup'])) {
|
103 |
+
// just make sure the admin started this... recently enough
|
104 |
+
check_ajax_referer('transposh-clean', 'nonce');
|
105 |
+
$my_transposh_plugin->database->cleanup($_GET['days']);
|
106 |
+
}
|
107 |
?>
|
wp/transposh_backup.php
CHANGED
@@ -1,22 +1,14 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* it under the terms of the GNU General Public License as published by
|
7 |
-
* the Free Software Foundation; either version 2 of the License, or
|
8 |
-
* (at your option) any later version.
|
9 |
-
*
|
10 |
-
* This program is distributed in the hope that it will be useful,
|
11 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
* GNU General Public License for more details.
|
14 |
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*
|
18 |
*
|
19 |
-
*
|
20 |
*/
|
21 |
|
22 |
/*
|
@@ -24,6 +16,7 @@
|
|
24 |
*/
|
25 |
|
26 |
define('TRANSPOSH_BACKUP_SERVICE_URL', 'http://svc.transposh.org/backup');
|
|
|
27 |
|
28 |
//define ("TRANSPOSH_BACKUP_SERVICE_URL" , "http://ofergen:8888/backup");
|
29 |
//class that reperesent the admin page
|
@@ -34,68 +27,85 @@ class transposh_backup {
|
|
34 |
|
35 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
36 |
function transposh_backup(&$transposh) {
|
37 |
-
|
38 |
}
|
39 |
|
40 |
function do_backup() {
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
if ($result['headers']['lastitem']) {
|
67 |
-
$rowstosend = $this->transposh->database->get_all_human_translation_history($result['headers']['lastitem'], 500);
|
68 |
-
while ($rowstosend) {
|
69 |
-
$item = 0;
|
70 |
-
foreach ($rowstosend as $row) {
|
71 |
-
if ($body['or' . ($item - 1)] != $row->original)
|
72 |
-
$body['or' . $item] = $row->original;
|
73 |
-
if ($body['ln' . ($item - 1)] != $row->lang)
|
74 |
-
$body['ln' . $item] = $row->lang;
|
75 |
-
if ($body['tr' . ($item - 1)] != $row->translated)
|
76 |
-
$body['tr' . $item] = $row->translated;
|
77 |
-
if ($body['tb' . ($item - 1)] != $row->translated_by)
|
78 |
-
$body['tb' . $item] = $row->translated_by;
|
79 |
-
if ($body['ts' . ($item - 1)] != $row->timestamp)
|
80 |
-
$body['ts' . $item] = $row->timestamp;
|
81 |
-
$item++;
|
82 |
-
}
|
83 |
-
$body['items'] = $item;
|
84 |
-
// no need to post 0 items
|
85 |
-
if ($item == 0) return;
|
86 |
-
$result = wp_remote_post(TRANSPOSH_BACKUP_SERVICE_URL, array('body' => $body));
|
87 |
-
if (is_wp_error($result)) {
|
88 |
-
echo "500 - " . $result->get_error_message();
|
89 |
-
return;
|
90 |
-
}
|
91 |
-
if ($result['headers']['fail']) {
|
92 |
-
echo "500 - " . $result['headers']['fail'];
|
93 |
-
return;
|
94 |
-
}
|
95 |
-
$rowstosend = $this->transposh->database->get_all_human_translation_history($row->timestamp, 500);
|
96 |
-
}
|
97 |
-
}
|
98 |
-
Echo '200 - backup in sync';
|
99 |
}
|
100 |
|
101 |
}
|
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 |
/*
|
16 |
*/
|
17 |
|
18 |
define('TRANSPOSH_BACKUP_SERVICE_URL', 'http://svc.transposh.org/backup');
|
19 |
+
define('TRANSPOSH_RESTORE_SERVICE_URL', 'http://svc.transposh.org/restore');
|
20 |
|
21 |
//define ("TRANSPOSH_BACKUP_SERVICE_URL" , "http://ofergen:8888/backup");
|
22 |
//class that reperesent the admin page
|
27 |
|
28 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
29 |
function transposh_backup(&$transposh) {
|
30 |
+
$this->transposh = &$transposh;
|
31 |
}
|
32 |
|
33 |
function do_backup() {
|
34 |
+
$body = array();
|
35 |
+
$body['home_url'] = $this->transposh->home_url;
|
36 |
+
$body['key'] = $this->transposh->options->get_transposh_key();
|
37 |
+
//Check if there are thing to backup, before even accessing the service
|
38 |
+
$rowstosend = $this->transposh->database->get_all_human_translation_history('null', 1);
|
39 |
+
if (empty($rowstosend)) {
|
40 |
+
echo "500 - No human translations to backup.";
|
41 |
+
return;
|
42 |
+
}
|
43 |
+
|
44 |
+
$result = wp_remote_post(TRANSPOSH_BACKUP_SERVICE_URL, array('body' => $body));
|
45 |
+
if (is_wp_error($result)) {
|
46 |
+
echo '500 - ' . $result->get_error_message();
|
47 |
+
return;
|
48 |
+
}
|
49 |
+
if ($result['headers']['fail']) {
|
50 |
+
echo '500 - ' . $result['headers']['fail'];
|
51 |
+
return;
|
52 |
+
}
|
53 |
+
if ($this->transposh->options->get_transposh_key() == "") {
|
54 |
+
$this->transposh->options->set_transposh_key($result['headers']['transposh-key']);
|
55 |
+
// TODO: deliever new gottenkey to client side?
|
56 |
+
//echo $this->transposh->options->get_transposh_key();
|
57 |
+
$this->transposh->options->update_options();
|
58 |
+
}
|
59 |
+
if ($result['headers']['lastitem']) {
|
60 |
+
$rowstosend = $this->transposh->database->get_all_human_translation_history($result['headers']['lastitem'], 500);
|
61 |
+
while ($rowstosend) {
|
62 |
+
$item = 0;
|
63 |
+
foreach ($rowstosend as $row) {
|
64 |
+
if ($body['or' . ($item - 1)] != $row->original)
|
65 |
+
$body['or' . $item] = $row->original;
|
66 |
+
if ($body['ln' . ($item - 1)] != $row->lang)
|
67 |
+
$body['ln' . $item] = $row->lang;
|
68 |
+
if ($body['tr' . ($item - 1)] != $row->translated)
|
69 |
+
$body['tr' . $item] = $row->translated;
|
70 |
+
if ($body['tb' . ($item - 1)] != $row->translated_by)
|
71 |
+
$body['tb' . $item] = $row->translated_by;
|
72 |
+
if ($body['ts' . ($item - 1)] != $row->timestamp)
|
73 |
+
$body['ts' . $item] = $row->timestamp;
|
74 |
+
$item++;
|
75 |
+
}
|
76 |
+
$body['items'] = $item;
|
77 |
+
// no need to post 0 items
|
78 |
+
if ($item == 0) return;
|
79 |
+
$result = wp_remote_post(TRANSPOSH_BACKUP_SERVICE_URL, array('body' => $body));
|
80 |
+
if (is_wp_error($result)) {
|
81 |
+
echo "500 - " . $result->get_error_message();
|
82 |
+
return;
|
83 |
+
}
|
84 |
+
if ($result['headers']['fail']) {
|
85 |
+
echo "500 - " . $result['headers']['fail'];
|
86 |
+
return;
|
87 |
+
}
|
88 |
+
$rowstosend = $this->transposh->database->get_all_human_translation_history($row->timestamp, 500);
|
89 |
+
}
|
90 |
+
}
|
91 |
+
Echo '200 - backup in sync';
|
92 |
+
}
|
93 |
|
94 |
+
function do_restore() {
|
95 |
+
$body['to'] = time(); //TODO: fix this to get from DB
|
96 |
+
$body['home_url'] = $this->transposh->home_url;
|
97 |
+
$body['key'] = $this->transposh->options->get_transposh_key();
|
98 |
+
$result = wp_remote_get(TRANSPOSH_RESTORE_SERVICE_URL . "?to={$body['to']}&key={$body['key']}&home_url={$body['home_url']}"); // gotta be a better way...
|
99 |
+
$lines = split("[\n|\r]", $result['body']);
|
100 |
+
foreach ($lines as $line) {
|
101 |
+
$trans = split(',', $line);
|
102 |
+
if ($trans[0])
|
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 |
|
111 |
}
|
wp/transposh_db.php
CHANGED
@@ -1,23 +1,16 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
|
|
|
|
4 |
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
-
* (at your option) any later version.
|
9 |
*
|
10 |
-
*
|
11 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
* GNU General Public License for more details.
|
14 |
-
*
|
15 |
-
* You should have received a copy of the GNU General Public License
|
16 |
-
* along with this program; if not, write to the Free Software
|
17 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
19 |
|
20 |
-
|
21 |
/**
|
22 |
* Contains db realated function which are likely to be specific for each environment.
|
23 |
* This implementation for use with mysql within wordpress
|
@@ -249,7 +242,7 @@ class transposh_database {
|
|
249 |
// We are now passing all posted items
|
250 |
for ($i = 0; $i < $items; $i++) {
|
251 |
if (isset($_POST["tk$i"])) {
|
252 |
-
$original = base64_url_decode($_POST["tk$i"]);
|
253 |
//The original content is encoded as base64 before it is sent (i.e. token), after we
|
254 |
//decode it should just the same after it was parsed.
|
255 |
$original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
|
@@ -289,7 +282,7 @@ class transposh_database {
|
|
289 |
$logvalues .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $loguser . "','" . $source . "')" . (($items != $i + 1) ? ', ' : '');
|
290 |
|
291 |
// If we have caching - we remove previous entry from cache
|
292 |
-
if (ENABLE_APC && function_exists('
|
293 |
apc_delete($original . '___' . $lang);
|
294 |
}
|
295 |
}
|
@@ -341,7 +334,7 @@ class transposh_database {
|
|
341 |
function get_translation_history($token, $lang) {
|
342 |
|
343 |
$ref = getenv('HTTP_REFERER');
|
344 |
-
$original = base64_url_decode($token);
|
345 |
|
346 |
|
347 |
// check params
|
@@ -487,6 +480,9 @@ class transposh_database {
|
|
487 |
|
488 |
}
|
489 |
|
|
|
|
|
|
|
490 |
function db_stats() {
|
491 |
echo "<h4>Database stats</h4>";
|
492 |
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
|
@@ -557,5 +553,59 @@ class transposh_database {
|
|
557 |
return $result;
|
558 |
}
|
559 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
}
|
561 |
?>
|
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 |
/**
|
15 |
* Contains db realated function which are likely to be specific for each environment.
|
16 |
* This implementation for use with mysql within wordpress
|
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'));
|
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 |
}
|
334 |
function get_translation_history($token, $lang) {
|
335 |
|
336 |
$ref = getenv('HTTP_REFERER');
|
337 |
+
$original = transposh_utils::base64_url_decode($token);
|
338 |
|
339 |
|
340 |
// check params
|
480 |
|
481 |
}
|
482 |
|
483 |
+
/**
|
484 |
+
* Provides some stats about our database
|
485 |
+
*/
|
486 |
function db_stats() {
|
487 |
echo "<h4>Database stats</h4>";
|
488 |
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
|
553 |
return $result;
|
554 |
}
|
555 |
|
556 |
+
/**
|
557 |
+
* This function removes translations and translation logs from the database, only
|
558 |
+
* when the last translation is automated
|
559 |
+
* @param int $days
|
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 |
+
|
578 |
+
function restore_translation($original, $lang, $translation, $by, $timestamp) {
|
579 |
+
// TODO in future
|
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 . "')";
|
586 |
+
$delvalues .= "(original ='$original' AND lang='$lang')";
|
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);
|
603 |
+
} else {
|
604 |
+
|
605 |
+
|
606 |
+
header("HTTP/1.0 404 Failed to update language database " . mysql_error());
|
607 |
+
}
|
608 |
+
}
|
609 |
+
|
610 |
}
|
611 |
?>
|
wp/transposh_options.php
CHANGED
@@ -1,21 +1,16 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
|
|
|
|
4 |
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
-
* (at your option) any later version.
|
9 |
*
|
10 |
-
*
|
11 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
* GNU General Public License for more details.
|
14 |
-
*
|
15 |
-
* You should have received a copy of the GNU General Public License
|
16 |
-
* along with this program; if not, write to the Free Software
|
17 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
|
|
19 |
// OLD Options - To be removed
|
20 |
// removed real old options support, no migration from 0.3.9 anymore
|
21 |
// @since 0.5.6
|
@@ -81,50 +76,51 @@ class transposh_plugin_options {
|
|
81 |
private $changed = false;
|
82 |
|
83 |
function transposh_plugin_options() {
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
}
|
90 |
|
91 |
// TODO: remove this function in a few versions (fix css, db version..., css flag
|
92 |
private function migrate_old_config() {
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
}
|
116 |
|
117 |
function get_anonymous_translation() {
|
118 |
-
|
|
|
119 |
return $this->options[ANONYMOUS_TRANSLATION];
|
120 |
}
|
121 |
|
122 |
function get_viewable_langs() {
|
123 |
-
|
124 |
}
|
125 |
|
126 |
function get_editable_langs() {
|
127 |
-
|
128 |
}
|
129 |
|
130 |
/**
|
@@ -133,17 +129,17 @@ class transposh_plugin_options {
|
|
133 |
* @return array sorted list of languages, pointing to names and flags
|
134 |
*/
|
135 |
function get_sorted_langs() {
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
}
|
140 |
|
141 |
function get_widget_progressbar() {
|
142 |
-
|
143 |
}
|
144 |
|
145 |
function get_widget_remove_logo() {
|
146 |
-
|
147 |
}
|
148 |
|
149 |
/**
|
@@ -152,53 +148,53 @@ class transposh_plugin_options {
|
|
152 |
* @return string
|
153 |
*/
|
154 |
function get_widget_file() {
|
155 |
-
|
156 |
}
|
157 |
|
158 |
function get_widget_allow_set_default_language() {
|
159 |
-
|
160 |
}
|
161 |
|
162 |
function get_enable_permalinks() {
|
163 |
-
|
164 |
}
|
165 |
|
166 |
function get_enable_footer_scripts() {
|
167 |
-
|
168 |
}
|
169 |
|
170 |
function get_enable_detect_language() {
|
171 |
-
|
172 |
}
|
173 |
|
174 |
function get_enable_default_translate() {
|
175 |
-
|
176 |
}
|
177 |
|
178 |
function get_enable_search_translate() {
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
}
|
183 |
|
184 |
function get_enable_url_translate() {
|
185 |
-
|
186 |
}
|
187 |
|
188 |
function get_enable_auto_translate() {
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
}
|
193 |
|
194 |
function get_enable_auto_post_translate() {
|
195 |
-
|
196 |
}
|
197 |
|
198 |
function get_preferred_translator() {
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
}
|
203 |
|
204 |
/**
|
@@ -206,23 +202,23 @@ class transposh_plugin_options {
|
|
206 |
* @return string Default language
|
207 |
*/
|
208 |
function get_default_language() {
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
}
|
219 |
|
220 |
function get_transposh_key() {
|
221 |
-
|
222 |
}
|
223 |
|
224 |
function get_transposh_backup_schedule() {
|
225 |
-
|
226 |
}
|
227 |
|
228 |
/**
|
@@ -231,37 +227,37 @@ class transposh_plugin_options {
|
|
231 |
* @param pointer $option Points to the option in the options array
|
232 |
*/
|
233 |
private function set_value($val, &$option) {
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
}
|
239 |
|
240 |
function set_anonymous_translation($val) {
|
241 |
-
|
242 |
-
|
243 |
}
|
244 |
|
245 |
function set_viewable_langs($val) {
|
246 |
-
|
247 |
}
|
248 |
|
249 |
function set_editable_langs($val) {
|
250 |
-
|
251 |
}
|
252 |
|
253 |
function set_sorted_langs($val) {
|
254 |
-
|
255 |
}
|
256 |
|
257 |
function set_widget_progressbar($val) {
|
258 |
-
|
259 |
-
|
260 |
}
|
261 |
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
}
|
266 |
|
267 |
/**
|
@@ -270,56 +266,56 @@ class transposh_plugin_options {
|
|
270 |
* @param string $val
|
271 |
*/
|
272 |
function set_widget_file($val) {
|
273 |
-
|
274 |
}
|
275 |
|
276 |
function set_widget_allow_set_default_language($val) {
|
277 |
-
|
278 |
-
|
279 |
}
|
280 |
|
281 |
function set_enable_permalinks($val) {
|
282 |
-
|
283 |
-
|
284 |
}
|
285 |
|
286 |
function set_enable_detect_language($val) {
|
287 |
-
|
288 |
-
|
289 |
}
|
290 |
|
291 |
function set_enable_footer_scripts($val) {
|
292 |
-
|
293 |
-
|
294 |
}
|
295 |
|
296 |
function set_enable_default_translate($val) {
|
297 |
-
|
298 |
-
|
299 |
}
|
300 |
|
301 |
function set_enable_search_translate($val) {
|
302 |
-
|
303 |
-
|
304 |
}
|
305 |
|
306 |
function set_enable_url_translate($val) {
|
307 |
-
|
308 |
-
|
309 |
}
|
310 |
|
311 |
function set_enable_auto_translate($val) {
|
312 |
-
|
313 |
-
|
314 |
}
|
315 |
|
316 |
function set_enable_auto_post_translate($val) {
|
317 |
-
|
318 |
-
|
319 |
}
|
320 |
|
321 |
function set_preferred_translator($val) {
|
322 |
-
|
323 |
}
|
324 |
|
325 |
/**
|
@@ -328,30 +324,30 @@ class transposh_plugin_options {
|
|
328 |
* @param string $val Language set as default
|
329 |
*/
|
330 |
function set_default_language($val) {
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
}
|
336 |
|
337 |
function set_transposh_key($val) {
|
338 |
-
|
339 |
}
|
340 |
|
341 |
function set_transposh_backup_schedule($val) {
|
342 |
-
|
343 |
}
|
344 |
|
345 |
/**
|
346 |
* Updates options at the wordpress options table if there was a change
|
347 |
*/
|
348 |
function update_options() {
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
}
|
356 |
|
357 |
/**
|
@@ -360,7 +356,7 @@ class transposh_plugin_options {
|
|
360 |
* @return boolean Is this the default language?
|
361 |
*/
|
362 |
function is_default_language($language) {
|
363 |
-
|
364 |
}
|
365 |
|
366 |
/**
|
@@ -368,7 +364,8 @@ class transposh_plugin_options {
|
|
368 |
* @return boolean Is this language editable?
|
369 |
*/
|
370 |
function is_editable_language($language) {
|
371 |
-
|
|
|
372 |
}
|
373 |
|
374 |
/**
|
@@ -376,7 +373,8 @@ class transposh_plugin_options {
|
|
376 |
* @return boolean Is this language viewable?
|
377 |
*/
|
378 |
function is_viewable_language($language) {
|
379 |
-
|
|
|
380 |
}
|
381 |
|
382 |
}
|
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
|
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 |
}
|
85 |
|
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 |
+
}
|
93 |
+
if ($this->options[OLD_WIDGET_STYLE] == 1 && $this->options[OLD_WIDGET_CSS_FLAGS] == 1) {
|
94 |
+
$this->set_widget_file('flags/tpw_flags_css.php');
|
95 |
+
}
|
96 |
+
if ($this->options[OLD_WIDGET_STYLE] == 2 && $this->options[OLD_WIDGET_CSS_FLAGS] == 0) {
|
97 |
+
$this->set_widget_file('flagslist/tpw_list_with_flags.php');
|
98 |
+
}
|
99 |
+
if ($this->options[OLD_WIDGET_STYLE] == 2 && $this->options[OLD_WIDGET_CSS_FLAGS] == 1) {
|
100 |
+
$this->set_widget_file('flagslist/tpw_list_with_flags_css.php');
|
101 |
+
}
|
102 |
+
unset($this->options[OLD_WIDGET_CSS_FLAGS]);
|
103 |
+
unset($this->options[OLD_WIDGET_IN_LIST]);
|
104 |
+
unset($this->options[OLD_WIDGET_STYLE]);
|
105 |
+
unset($this->options[OLD_MSN_TRANSLATE_KEY]);
|
106 |
+
unset($this->options[OLD_ENABLE_MSN_TRANSLATE]);
|
107 |
+
|
108 |
+
update_option(TRANSPOSH_OPTIONS, $this->options);
|
109 |
+
}
|
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() {
|
119 |
+
return $this->options[VIEWABLE_LANGS];
|
120 |
}
|
121 |
|
122 |
function get_editable_langs() {
|
123 |
+
return $this->options[EDITABLE_LANGS];
|
124 |
}
|
125 |
|
126 |
/**
|
129 |
* @return array sorted list of languages, pointing to names and flags
|
130 |
*/
|
131 |
function get_sorted_langs() {
|
132 |
+
if (isset($this->options[SORTED_LANGS]))
|
133 |
+
return array_merge(array_flip(explode(",", $this->options[SORTED_LANGS])), transposh_consts::$languages);
|
134 |
+
return transposh_consts::$languages;
|
135 |
}
|
136 |
|
137 |
function get_widget_progressbar() {
|
138 |
+
return $this->options[WIDGET_PROGRESSBAR];
|
139 |
}
|
140 |
|
141 |
function get_widget_remove_logo() {
|
142 |
+
return $this->options[WIDGET_REMOVE_LOGO_FOR_AD];
|
143 |
}
|
144 |
|
145 |
/**
|
148 |
* @return string
|
149 |
*/
|
150 |
function get_widget_file() {
|
151 |
+
return $this->options[WIDGET_FILE];
|
152 |
}
|
153 |
|
154 |
function get_widget_allow_set_default_language() {
|
155 |
+
return $this->options[WIDGET_ALLOW_SET_DEFLANG];
|
156 |
}
|
157 |
|
158 |
function get_enable_permalinks() {
|
159 |
+
return $this->options[ENABLE_PERMALINKS];
|
160 |
}
|
161 |
|
162 |
function get_enable_footer_scripts() {
|
163 |
+
return $this->options[ENABLE_FOOTER_SCRIPTS];
|
164 |
}
|
165 |
|
166 |
function get_enable_detect_language() {
|
167 |
+
return $this->options[ENABLE_DETECT_LANG_AND_REDIRECT];
|
168 |
}
|
169 |
|
170 |
function get_enable_default_translate() {
|
171 |
+
return $this->options[ENABLE_DEFAULT_TRANSLATE];
|
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 |
|
180 |
function get_enable_url_translate() {
|
181 |
+
return $this->options[ENABLE_URL_TRANSLATE];
|
182 |
}
|
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 |
|
190 |
function get_enable_auto_post_translate() {
|
191 |
+
return $this->options[ENABLE_AUTO_POST_TRANSLATE];
|
192 |
}
|
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 |
|
200 |
/**
|
202 |
* @return string Default language
|
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";
|
211 |
+
}
|
212 |
+
}
|
213 |
+
return $default;
|
214 |
}
|
215 |
|
216 |
function get_transposh_key() {
|
217 |
+
return $this->options[TRANSPOSH_KEY];
|
218 |
}
|
219 |
|
220 |
function get_transposh_backup_schedule() {
|
221 |
+
return $this->options[TRANSPOSH_BACKUP_SCHEDULE];
|
222 |
}
|
223 |
|
224 |
/**
|
227 |
* @param pointer $option Points to the option in the options array
|
228 |
*/
|
229 |
private function set_value($val, &$option) {
|
230 |
+
if ($val !== $option) {
|
231 |
+
$option = $val;
|
232 |
+
$this->changed = true;
|
233 |
+
}
|
234 |
}
|
235 |
|
236 |
function set_anonymous_translation($val) {
|
237 |
+
$val = ($val) ? 1 : 0;
|
238 |
+
$this->set_value($val, $this->options[ANONYMOUS_TRANSLATION]);
|
239 |
}
|
240 |
|
241 |
function set_viewable_langs($val) {
|
242 |
+
$this->set_value($val, $this->options[VIEWABLE_LANGS]);
|
243 |
}
|
244 |
|
245 |
function set_editable_langs($val) {
|
246 |
+
$this->set_value($val, $this->options[EDITABLE_LANGS]);
|
247 |
}
|
248 |
|
249 |
function set_sorted_langs($val) {
|
250 |
+
$this->set_value($val, $this->options[SORTED_LANGS]);
|
251 |
}
|
252 |
|
253 |
function set_widget_progressbar($val) {
|
254 |
+
$val = ($val) ? 1 : 0;
|
255 |
+
$this->set_value($val, $this->options[WIDGET_PROGRESSBAR]);
|
256 |
}
|
257 |
|
258 |
+
function set_widget_remove_logo($val) {
|
259 |
+
$val = ($val) ? 1 : 0;
|
260 |
+
$this->set_value($val, $this->options[WIDGET_REMOVE_LOGO_FOR_AD]);
|
261 |
}
|
262 |
|
263 |
/**
|
266 |
* @param string $val
|
267 |
*/
|
268 |
function set_widget_file($val) {
|
269 |
+
$this->set_value($val, $this->options[WIDGET_FILE]);
|
270 |
}
|
271 |
|
272 |
function set_widget_allow_set_default_language($val) {
|
273 |
+
$val = ($val) ? 1 : 0;
|
274 |
+
$this->set_value($val, $this->options[WIDGET_ALLOW_SET_DEFLANG]);
|
275 |
}
|
276 |
|
277 |
function set_enable_permalinks($val) {
|
278 |
+
$val = ($val) ? 1 : 0;
|
279 |
+
$this->set_value($val, $this->options[ENABLE_PERMALINKS]);
|
280 |
}
|
281 |
|
282 |
function set_enable_detect_language($val) {
|
283 |
+
$val = ($val) ? 1 : 0;
|
284 |
+
$this->set_value($val, $this->options[ENABLE_DETECT_LANG_AND_REDIRECT]);
|
285 |
}
|
286 |
|
287 |
function set_enable_footer_scripts($val) {
|
288 |
+
$val = ($val) ? 1 : 0;
|
289 |
+
$this->set_value($val, $this->options[ENABLE_FOOTER_SCRIPTS]);
|
290 |
}
|
291 |
|
292 |
function set_enable_default_translate($val) {
|
293 |
+
$val = ($val) ? 1 : 0;
|
294 |
+
$this->set_value($val, $this->options[ENABLE_DEFAULT_TRANSLATE]);
|
295 |
}
|
296 |
|
297 |
function set_enable_search_translate($val) {
|
298 |
+
$val = ($val) ? 1 : 0;
|
299 |
+
$this->set_value($val, $this->options[ENABLE_SEARCH_TRANSLATE]);
|
300 |
}
|
301 |
|
302 |
function set_enable_url_translate($val) {
|
303 |
+
$val = ($val) ? 1 : 0;
|
304 |
+
$this->set_value($val, $this->options[ENABLE_URL_TRANSLATE]);
|
305 |
}
|
306 |
|
307 |
function set_enable_auto_translate($val) {
|
308 |
+
$val = ($val) ? 1 : 0;
|
309 |
+
$this->set_value($val, $this->options[ENABLE_AUTO_TRANSLATE]);
|
310 |
}
|
311 |
|
312 |
function set_enable_auto_post_translate($val) {
|
313 |
+
$val = ($val) ? 1 : 0;
|
314 |
+
$this->set_value($val, $this->options[ENABLE_AUTO_POST_TRANSLATE]);
|
315 |
}
|
316 |
|
317 |
function set_preferred_translator($val) {
|
318 |
+
$this->set_value($val, $this->options[PREFERRED_TRANSLATOR]);
|
319 |
}
|
320 |
|
321 |
/**
|
324 |
* @param string $val Language set as default
|
325 |
*/
|
326 |
function set_default_language($val) {
|
327 |
+
if (!transposh_consts::$languages[$val]) {
|
328 |
+
$val = "en";
|
329 |
+
}
|
330 |
+
$this->set_value($val, $this->options[DEFAULT_LANG]);
|
331 |
}
|
332 |
|
333 |
function set_transposh_key($val) {
|
334 |
+
$this->set_value($val, $this->options[TRANSPOSH_KEY]);
|
335 |
}
|
336 |
|
337 |
function set_transposh_backup_schedule($val) {
|
338 |
+
$this->set_value($val, $this->options[TRANSPOSH_BACKUP_SCHEDULE]);
|
339 |
}
|
340 |
|
341 |
/**
|
342 |
* Updates options at the wordpress options table if there was a change
|
343 |
*/
|
344 |
function update_options() {
|
345 |
+
if ($this->changed) {
|
346 |
+
update_option(TRANSPOSH_OPTIONS, $this->options);
|
347 |
+
} else {
|
348 |
+
|
349 |
+
}
|
350 |
+
$this->changed = false;
|
351 |
}
|
352 |
|
353 |
/**
|
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 |
/**
|
364 |
* @return boolean Is this language editable?
|
365 |
*/
|
366 |
function is_editable_language($language) {
|
367 |
+
if ($this->is_default_language($language)) return true;
|
368 |
+
return (strpos($this->get_editable_langs(), $language) !== false);
|
369 |
}
|
370 |
|
371 |
/**
|
373 |
* @return boolean Is this language viewable?
|
374 |
*/
|
375 |
function is_viewable_language($language) {
|
376 |
+
if ($this->is_default_language($language)) return true;
|
377 |
+
return (strpos($this->get_viewable_langs(), $language) !== false);
|
378 |
}
|
379 |
|
380 |
}
|
wp/transposh_postpublish.php
CHANGED
@@ -1,21 +1,14 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* it under the terms of the GNU General Public License as published by
|
7 |
-
* the Free Software Foundation; either version 2 of the License, or
|
8 |
-
* (at your option) any later version.
|
9 |
-
*
|
10 |
-
* This program is distributed in the hope that it will be useful,
|
11 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
* GNU General Public License for more details.
|
14 |
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*
|
18 |
*
|
|
|
19 |
*/
|
20 |
|
21 |
/*
|
@@ -62,7 +55,7 @@ class transposh_postpublish {
|
|
62 |
'post_url' => $this->transposh->post_url,
|
63 |
'post' => $_GET['post'],
|
64 |
'preferred' => $this->transposh->options->get_preferred_translator(),
|
65 |
-
'l10n_print_after' => 't_jp.g_langs = ' . json_encode(
|
66 |
'plugin_url' => $this->transposh_plugin_url,
|
67 |
'edit' => ($this->edit_mode? '1' : ''),
|
68 |
//'rtl' => (in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : ''),
|
@@ -101,7 +94,7 @@ class transposh_postpublish {
|
|
101 |
// Merge the two arrays for traversing
|
102 |
$phrases = array_merge($phrases, $phrases2);
|
103 |
|
104 |
-
// Add
|
105 |
if ($this->transposh->options->get_enable_url_translate()) {
|
106 |
$permalink = get_permalink($postID);
|
107 |
$permalink = substr($permalink, strlen($this->transposh->home_url) + 1);
|
@@ -109,7 +102,7 @@ class transposh_postpublish {
|
|
109 |
foreach ($parts as $part) {
|
110 |
if (!$part || is_numeric($part)) continue;
|
111 |
$part = str_replace('-', ' ', $part);
|
112 |
-
$phrases[] = $part;
|
113 |
}
|
114 |
}
|
115 |
|
@@ -119,7 +112,7 @@ class transposh_postpublish {
|
|
119 |
// as we don't normally want to auto-translate the default language -FIX THIS to include only correct stuff, how?
|
120 |
if (!$this->transposh->options->is_default_language($lang) || $this->transposh->options->get_enable_default_translate()) {
|
121 |
// There is no point in returning phrases, languages pairs that cannot be translated
|
122 |
-
if (in_array($lang,
|
123 |
list($translation, $source) = $this->transposh->database->fetch_translation($key, $lang);
|
124 |
if (!$translation) {
|
125 |
// p stands for phrases, l stands for languages, t is token
|
@@ -133,7 +126,7 @@ class transposh_postpublish {
|
|
133 |
}
|
134 |
// only if a languages list was created we'll need to translate this
|
135 |
if (is_array($json['p'][$key]['l'])) {
|
136 |
-
$json['p'][$key]['t'] = base64_url_encode($key);
|
137 |
$json['length']++;
|
138 |
}
|
139 |
}
|
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 |
/*
|
55 |
'post_url' => $this->transposh->post_url,
|
56 |
'post' => $_GET['post'],
|
57 |
'preferred' => $this->transposh->options->get_preferred_translator(),
|
58 |
+
'l10n_print_after' => 't_jp.g_langs = ' . json_encode(transposh_consts::$google_languages) . '; t_jp.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';'/*
|
59 |
'plugin_url' => $this->transposh_plugin_url,
|
60 |
'edit' => ($this->edit_mode? '1' : ''),
|
61 |
//'rtl' => (in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : ''),
|
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);
|
102 |
foreach ($parts as $part) {
|
103 |
if (!$part || is_numeric($part)) continue;
|
104 |
$part = str_replace('-', ' ', $part);
|
105 |
+
$phrases[] = urldecode($part);
|
106 |
}
|
107 |
}
|
108 |
|
112 |
// as we don't normally want to auto-translate the default language -FIX THIS to include only correct stuff, how?
|
113 |
if (!$this->transposh->options->is_default_language($lang) || $this->transposh->options->get_enable_default_translate()) {
|
114 |
// There is no point in returning phrases, languages pairs that cannot be translated
|
115 |
+
if (in_array($lang, transposh_consts::$bing_languages) || in_array($lang, transposh_consts::$google_languages)) {
|
116 |
list($translation, $source) = $this->transposh->database->fetch_translation($key, $lang);
|
117 |
if (!$translation) {
|
118 |
// p stands for phrases, l stands for languages, t is token
|
126 |
}
|
127 |
// only if a languages list was created we'll need to translate this
|
128 |
if (is_array($json['p'][$key]['l'])) {
|
129 |
+
$json['p'][$key]['t'] = transposh_utils::base64_url_encode($key);
|
130 |
$json['length']++;
|
131 |
}
|
132 |
}
|
wp/transposh_widget.php
CHANGED
@@ -1,20 +1,14 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* it under the terms of the GNU General Public License as published by
|
7 |
-
* the Free Software Foundation; either version 2 of the License, or
|
8 |
-
* (at your option) any later version.
|
9 |
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
-
* GNU General Public License for more details.
|
14 |
*
|
15 |
-
*
|
16 |
-
* along with this program; if not, write to the Free Software
|
17 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
19 |
|
20 |
/*
|
@@ -51,7 +45,7 @@ class transposh_plugin_widget {
|
|
51 |
$ref = getenv('HTTP_REFERER');
|
52 |
$lang = $_POST[LANG_PARAM];
|
53 |
if ($lang == '') {
|
54 |
-
$lang = get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url);
|
55 |
}
|
56 |
if ($lang == $this->transposh->options->get_default_language() || $lang == "none")
|
57 |
$lang = '';
|
@@ -59,20 +53,20 @@ class transposh_plugin_widget {
|
|
59 |
|
60 |
// first, we might need to get the original url back
|
61 |
if ($this->transposh->options->get_enable_url_translate()) {
|
62 |
-
$ref = get_original_url($ref, $this->transposh->home_url, get_language_from_url($ref, $this->transposh->home_url), array($this->transposh->database, 'fetch_original'));
|
63 |
}
|
64 |
|
65 |
//remove existing language settings.
|
66 |
-
$ref = cleanup_url($ref, $this->transposh->home_url);
|
67 |
|
68 |
|
69 |
if ($lang && $this->transposh->options->get_enable_url_translate()) {
|
70 |
// and then, we might have to translate it
|
71 |
-
$ref = translate_url($ref, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation'));
|
72 |
$ref = str_replace(array('%2F', '%3A', '%3B', '%3F', '%3D', '%26'), array('/', ':', ';', '?', '=', '&'), urlencode($ref));
|
73 |
|
74 |
}
|
75 |
-
$ref = rewrite_url_lang_param($ref, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]);
|
76 |
|
77 |
|
78 |
|
@@ -170,10 +164,10 @@ class transposh_plugin_widget {
|
|
170 |
$page_url = $_SERVER['REQUEST_URI'];
|
171 |
|
172 |
//remove any language identifier and find the "clean" url, used for posting and calculating urls if needed
|
173 |
-
$clean_page_url = cleanup_url($page_url, $this->transposh->home_url, true);
|
174 |
// we need this if we are using url translations
|
175 |
if ($this->transposh->options->get_enable_url_translate() && $calc_url) {
|
176 |
-
$clean_page_url = get_original_url($clean_page_url, '', $this->transposh->target_language, array($this->transposh->database, 'fetch_original'));
|
177 |
}
|
178 |
|
179 |
|
@@ -186,13 +180,13 @@ class transposh_plugin_widget {
|
|
186 |
($this->transposh->options->is_editable_language($code) && $this->transposh->is_translator()) ||
|
187 |
($this->transposh->options->is_default_language($code))) {
|
188 |
if ($this->transposh->options->get_enable_url_translate() && $calc_url) {
|
189 |
-
$page_url = translate_url($clean_page_url, '', $code, array(&$this->transposh->database, 'fetch_translation'));
|
190 |
} else {
|
191 |
$page_url = $clean_page_url;
|
192 |
}
|
193 |
// clean $code in default lanaguge
|
194 |
if ($calc_url)
|
195 |
-
$page_url = rewrite_url_lang_param($page_url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, ($code == $this->transposh->options->get_default_language()) ? '' : $code, $this->transposh->edit_mode);
|
196 |
$widget_args[] = array(
|
197 |
'lang' => $langname,
|
198 |
'langorig' => $language,
|
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 |
/*
|
45 |
$ref = getenv('HTTP_REFERER');
|
46 |
$lang = $_POST[LANG_PARAM];
|
47 |
if ($lang == '') {
|
48 |
+
$lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url);
|
49 |
}
|
50 |
if ($lang == $this->transposh->options->get_default_language() || $lang == "none")
|
51 |
$lang = '';
|
53 |
|
54 |
// first, we might need to get the original url back
|
55 |
if ($this->transposh->options->get_enable_url_translate()) {
|
56 |
+
$ref = transposh_utils::get_original_url($ref, $this->transposh->home_url, transposh_utils::get_language_from_url($ref, $this->transposh->home_url), array($this->transposh->database, 'fetch_original'));
|
57 |
}
|
58 |
|
59 |
//remove existing language settings.
|
60 |
+
$ref = transposh_utils::cleanup_url($ref, $this->transposh->home_url);
|
61 |
|
62 |
|
63 |
if ($lang && $this->transposh->options->get_enable_url_translate()) {
|
64 |
// and then, we might have to translate it
|
65 |
+
$ref = transposh_utils::translate_url($ref, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation'));
|
66 |
$ref = str_replace(array('%2F', '%3A', '%3B', '%3F', '%3D', '%26'), array('/', ':', ';', '?', '=', '&'), urlencode($ref));
|
67 |
|
68 |
}
|
69 |
+
$ref = transposh_utils::rewrite_url_lang_param($ref, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]);
|
70 |
|
71 |
|
72 |
|
164 |
$page_url = $_SERVER['REQUEST_URI'];
|
165 |
|
166 |
//remove any language identifier and find the "clean" url, used for posting and calculating urls if needed
|
167 |
+
$clean_page_url = transposh_utils::cleanup_url($page_url, $this->transposh->home_url, true);
|
168 |
// we need this if we are using url translations
|
169 |
if ($this->transposh->options->get_enable_url_translate() && $calc_url) {
|
170 |
+
$clean_page_url = transposh_utils::get_original_url($clean_page_url, '', $this->transposh->target_language, array($this->transposh->database, 'fetch_original'));
|
171 |
}
|
172 |
|
173 |
|
180 |
($this->transposh->options->is_editable_language($code) && $this->transposh->is_translator()) ||
|
181 |
($this->transposh->options->is_default_language($code))) {
|
182 |
if ($this->transposh->options->get_enable_url_translate() && $calc_url) {
|
183 |
+
$page_url = transposh_utils::translate_url($clean_page_url, '', $code, array(&$this->transposh->database, 'fetch_translation'));
|
184 |
} else {
|
185 |
$page_url = $clean_page_url;
|
186 |
}
|
187 |
// clean $code in default lanaguge
|
188 |
if ($calc_url)
|
189 |
+
$page_url = transposh_utils::rewrite_url_lang_param($page_url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, ($code == $this->transposh->options->get_default_language()) ? '' : $code, $this->transposh->edit_mode);
|
190 |
$widget_args[] = array(
|
191 |
'lang' => $langname,
|
192 |
'langorig' => $language,
|