Version Description
= 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.5.6 |
Comparing to | |
See all releases |
Code changes from version 0.5.5 to 0.5.6
- core/constants.php +285 -266
- core/globals.php +0 -46
- core/parser.php +525 -518
- core/utils.php +171 -177
- css/transposh_flags.css +0 -1
- css/transposh_widget.css +0 -1
- img/flags/basque.png +0 -0
- img/flags58.png +0 -0
- js/lazy.js +5 -5
- js/transposh.js +5 -5
- readme.txt +13 -7
- transposh.php +478 -510
- widgets/dropdown/arrow.png +0 -0
- widgets/dropdown/tpw_image_dropdown.css +46 -0
- widgets/dropdown/tpw_image_dropdown.js +29 -0
- widgets/dropdown/tpw_image_dropdown.php +63 -0
- widgets/flags/flags58.png +0 -0
- widgets/flags/tpw_flags.css +28 -0
- widgets/flags/tpw_flags.php +56 -0
- widgets/flags/tpw_flags_css.css +96 -0
- widgets/flags/tpw_flags_css.php +51 -0
- widgets/flagslist/tpw_list_with_flags.php +65 -0
- widgets/flagslist/tpw_list_with_flags_css.php +61 -0
- widgets/tpw_default.php +53 -0
- wp/transposh_admin.php +426 -432
- wp/transposh_ajax.php +59 -57
- wp/transposh_backup.php +77 -71
- wp/transposh_db.php +429 -427
- wp/transposh_options.php +149 -195
- wp/transposh_postpublish.php +122 -119
- wp/transposh_widget.php +301 -241
core/constants.php
CHANGED
@@ -1,301 +1,320 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*/
|
18 |
|
19 |
//Language indicator in URL. i.e. lang=en
|
20 |
-
define(
|
21 |
|
22 |
//Edit mode indicator in URL. i.e. lang=en&edit=true
|
23 |
-
define(
|
24 |
|
25 |
//Enable apc usage
|
26 |
-
define(
|
27 |
|
28 |
//Class marking a section not be translated.
|
29 |
-
define(
|
30 |
-
define(
|
31 |
-
define(
|
32 |
|
33 |
//Supported languages, new languages can be added here
|
34 |
//the array directs from language code to - English Name, Native name, flag
|
35 |
$languages = array(
|
36 |
-
|
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 |
//Language which are read from right to left (rtl)
|
92 |
-
$rtl_languages = array(
|
93 |
|
94 |
-
//Google supported languages
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
//Define the new capability that will be assigned to roles - translator
|
100 |
-
define(
|
101 |
|
102 |
-
|
|
|
103 |
|
104 |
//Define segment id prefix, will be included in span tag. also used as class identifier
|
105 |
-
define(
|
106 |
|
107 |
//The name of our admin page
|
108 |
define('TRANSPOSH_ADMIN_PAGE_NAME', 'transposh');
|
109 |
|
110 |
//0.3.5 - Storing all options in this config option
|
111 |
-
define(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
/* Full language list according to ISO
|
114 |
-
ISO 639-1 Language name Native name
|
115 |
-
aa Afar Afaraf
|
116 |
-
ab Abkhazian Аҧсуа
|
117 |
-
ae Avestan avesta
|
118 |
-
af Afrikaans Afrikaans
|
119 |
-
ak Akan Akan
|
120 |
-
am Amharic አማርኛ
|
121 |
-
an Aragonese Aragonés
|
122 |
-
ar Arabic العربية
|
123 |
-
as Assamese অসমীয়া
|
124 |
-
av Avaric авар мацӀ, магӀарул мацӀ
|
125 |
-
ay Aymara aymar aru
|
126 |
-
az Azerbaijani azərbaycan dili
|
127 |
-
ba Bashkir башҡорт теле
|
128 |
-
be Belarusian Беларуская
|
129 |
-
bg Bulgarian български език
|
130 |
-
bh Bihari भोजपुरी
|
131 |
-
bi Bislama Bislama
|
132 |
-
bm Bambara bamanankan
|
133 |
-
bn Bengali বাংলা
|
134 |
-
bo Tibetan བོད་ཡིག
|
135 |
-
br Breton brezhoneg
|
136 |
-
bs Bosnian bosanski jezik
|
137 |
-
ca Catalan, Valencian Català
|
138 |
-
ce Chechen нохчийн мотт
|
139 |
-
ch Chamorro Chamoru
|
140 |
-
co Corsican corsu, lingua corsa
|
141 |
-
cr Cree ᓀᐦᐃᔭᐍᐏᐣ
|
142 |
-
cs Czech česky, čeština
|
143 |
-
cu Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian, Old Church Slavonic ѩзыкъ словѣньскъ
|
144 |
-
cv Chuvash чӑваш чӗлхи
|
145 |
-
cy Welsh Cymraeg
|
146 |
-
da Danish dansk
|
147 |
-
de German Deutsch
|
148 |
-
dv Divehi, Dhivehi, Maldivian ދިވެހި
|
149 |
-
dz Dzongkha རྫོང་ཁ
|
150 |
-
ee Ewe Eʋegbe
|
151 |
-
el Modern Greek Ελληνικά
|
152 |
-
en English English
|
153 |
-
eo Esperanto Esperanto
|
154 |
-
es Spanish, Castilian español, castellano
|
155 |
-
et Estonian eesti, eesti keel
|
156 |
-
eu Basque euskara, euskera
|
157 |
-
fa Persian فارسی
|
158 |
-
ff Fulah Fulfulde, Pulaar, Pular
|
159 |
-
fi Finnish suomi, suomen kieli
|
160 |
-
fj Fijian vosa Vakaviti
|
161 |
-
fo Faroese føroyskt
|
162 |
-
fr French français, langue française
|
163 |
-
fy Western Frisian Frysk
|
164 |
-
ga Irish Gaeilge
|
165 |
-
gd Gaelic, Scottish Gaelic Gàidhlig
|
166 |
-
gl Galician Galego
|
167 |
-
gn Guaraní Avañe'ẽ
|
168 |
-
gu Gujarati ગુજરાતી
|
169 |
-
gv Manx Gaelg, Gailck
|
170 |
-
ha Hausa Hausa, هَوُسَ
|
171 |
-
he Modern Hebrew עברית
|
172 |
-
hi Hindi हिन्दी, हिंदी
|
173 |
-
ho Hiri Motu Hiri Motu
|
174 |
-
hr Croatian hrvatski
|
175 |
-
ht Haitian, Haitian Creole Kreyòl ayisyen
|
176 |
-
hu Hungarian Magyar
|
177 |
-
hy Armenian Հայերեն
|
178 |
-
hz Herero Otjiherero
|
179 |
-
ia Interlingua (International Auxiliary Language Association) Interlingua
|
180 |
-
id Indonesian Bahasa Indonesia
|
181 |
-
ie Interlingue, Occidental Interlingue
|
182 |
-
ig Igbo Igbo
|
183 |
-
ii Sichuan Yi, Nuosu ꆇꉙ
|
184 |
-
ik Inupiaq Iñupiaq, Iñupiatun
|
185 |
-
io Ido Ido
|
186 |
-
is Icelandic Íslenska
|
187 |
-
it Italian Italiano
|
188 |
-
iu Inuktitut ᐃᓄᒃᑎᑐᑦ
|
189 |
-
ja Japanese 日本語 (にほんご/にっぽんご)
|
190 |
-
jv Javanese basa Jawa
|
191 |
-
ka Georgian ქართული
|
192 |
-
kg Kongo KiKongo
|
193 |
-
ki Kikuyu, Gikuyu Gĩkũyũ
|
194 |
-
kj Kwanyama, Kuanyama Kuanyama
|
195 |
-
kk Kazakh Қазақ тілі
|
196 |
-
kl Kalaallisut, Greenlandic kalaallisut, kalaallit oqaasii
|
197 |
-
km Central Khmer ភាសាខ្មែរ
|
198 |
-
kn Kannada ಕನ್ನಡ
|
199 |
-
ko Korean 한국어 (韓國語), 조선말 (朝鮮語)
|
200 |
-
kr Kanuri Kanuri
|
201 |
-
ks Kashmiri कश्मीरी, كشميري
|
202 |
-
ku Kurdish Kurdî, كوردی
|
203 |
-
kv Komi коми кыв
|
204 |
-
kw Cornish Kernewek
|
205 |
-
ky Kirghiz, Kyrgyz кыргыз тили
|
206 |
-
la Latin latine, lingua latina
|
207 |
-
lb Luxembourgish, Letzeburgesch Lëtzebuergesch
|
208 |
-
lg Ganda Luganda
|
209 |
-
li Limburgish, Limburgan, Limburger Limburgs
|
210 |
-
ln Lingala Lingála
|
211 |
-
lo Lao ພາສາລາວ
|
212 |
-
lt Lithuanian lietuvių kalba
|
213 |
-
lu Luba-Katanga
|
214 |
-
lv Latvian latviešu valoda
|
215 |
-
mg Malagasy Malagasy fiteny
|
216 |
-
mh Marshallese Kajin M̧ajeļ
|
217 |
-
mi Māori te reo Māori
|
218 |
-
mk Macedonian македонски јазик
|
219 |
-
ml Malayalam മലയാളം
|
220 |
-
mn Mongolian Монгол
|
221 |
-
mr Marathi मराठी
|
222 |
-
ms Malay bahasa Melayu, بهاس ملايو
|
223 |
-
mt Maltese Malti
|
224 |
-
my Burmese ဗမာစာ
|
225 |
-
na Nauru Ekakairũ Naoero
|
226 |
-
nb Norwegian Bokmål Norsk bokmål
|
227 |
-
nd North Ndebele isiNdebele
|
228 |
-
ne Nepali नेपाली
|
229 |
-
ng Ndonga Owambo
|
230 |
-
nl Dutch, Flemish Nederlands, Vlaams
|
231 |
-
nn Norwegian Nynorsk Norsk nynorsk
|
232 |
-
no Norwegian Norsk
|
233 |
-
nr South Ndebele isiNdebele
|
234 |
-
nv Navajo, Navaho Diné bizaad, Dinékʼehǰí
|
235 |
-
ny Chichewa, Chewa, Nyanja chiCheŵa, chinyanja
|
236 |
-
oc Occitan (after 1500) Occitan
|
237 |
-
oj Ojibwa ᐊᓂᔑᓈᐯᒧᐎᓐ
|
238 |
-
om Oromo Afaan Oromoo
|
239 |
-
or Oriya ଓଡ଼ିଆ
|
240 |
-
os Ossetian, Ossetic Ирон æвзаг
|
241 |
-
pa Panjabi, Punjabi ਪੰਜਾਬੀ, پنجابی
|
242 |
-
pi Pāli पाऴि
|
243 |
-
pl Polish polski
|
244 |
-
ps Pashto, Pushto پښتو
|
245 |
-
pt Portuguese Português
|
246 |
-
qu Quechua Runa Simi, Kichwa
|
247 |
-
rm Romansh rumantsch grischun
|
248 |
-
rn Rundi kiRundi
|
249 |
-
ro Romanian, Moldavian, Moldovan română
|
250 |
-
ru Russian Русский язык
|
251 |
-
rw Kinyarwanda Ikinyarwanda
|
252 |
-
sa Sanskrit संस्कृतम्
|
253 |
-
sc Sardinian sardu
|
254 |
-
sd Sindhi सिन्धी, سنڌي، سندھی
|
255 |
-
se Northern Sami Davvisámegiella
|
256 |
-
sg Sango yângâ tî sängö
|
257 |
-
si Sinhala, Sinhalese සිංහල
|
258 |
-
sk Slovak slovenčina
|
259 |
-
sl Slovene slovenščina
|
260 |
-
sm Samoan gagana fa'a Samoa
|
261 |
-
sn Shona chiShona
|
262 |
-
so Somali Soomaaliga, af Soomaali
|
263 |
-
sq Albanian Shqip
|
264 |
-
sr Serbian српски језик
|
265 |
-
ss Swati SiSwati
|
266 |
-
st Southern Sotho Sesotho
|
267 |
-
su Sundanese Basa Sunda
|
268 |
-
sv Swedish svenska
|
269 |
-
sw Swahili Kiswahili
|
270 |
-
ta Tamil தமிழ்
|
271 |
-
te Telugu తెలుగు
|
272 |
-
tg Tajik тоҷикӣ, toğikī, تاجیکی
|
273 |
-
th Thai ไทย
|
274 |
-
ti Tigrinya ትግርኛ
|
275 |
-
tk Turkmen Türkmen, Түркмен
|
276 |
-
tl Tagalog Wikang Tagalog, ᜏᜒᜃᜅ᜔ ᜆᜄᜎᜓᜄ᜔
|
277 |
-
tn Tswana Setswana
|
278 |
-
to Tonga (Tonga Islands) faka Tonga
|
279 |
-
tr Turkish Türkçe
|
280 |
-
ts Tsonga Xitsonga
|
281 |
-
tt Tatar татарча, tatarça, تاتارچا
|
282 |
-
tw Twi Twi
|
283 |
-
ty Tahitian Reo Mā`ohi
|
284 |
-
ug Uighur, Uyghur Uyƣurqə, ئۇيغۇرچە
|
285 |
-
uk Ukrainian Українська
|
286 |
-
ur Urdu اردو
|
287 |
-
uz Uzbek O'zbek, Ўзбек, أۇزبېك
|
288 |
-
ve Venda Tshivenḓa
|
289 |
-
vi Vietnamese Tiếng Việt
|
290 |
-
vo Volapük Volapük
|
291 |
-
wa Walloon Walon
|
292 |
-
wo Wolof Wollof
|
293 |
-
xh Xhosa isiXhosa
|
294 |
-
yi Yiddish ייִדיש
|
295 |
-
yo Yoruba Yorùbá
|
296 |
-
za Zhuang, Chuang Saɯ cueŋƅ, Saw cuengh
|
297 |
-
zh Chinese 中文 (Zhōngwén), 汉语, 漢語
|
298 |
-
zu Zulu isiZulu
|
299 |
|
300 |
-
*/
|
301 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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
|
21 |
+
define('LANG_PARAM', 'lang');
|
22 |
|
23 |
//Edit mode indicator in URL. i.e. lang=en&edit=true
|
24 |
+
define('EDIT_PARAM', 'edit');
|
25 |
|
26 |
//Enable apc usage
|
27 |
+
define('ENABLE_APC', TRUE);
|
28 |
|
29 |
//Class marking a section not be translated.
|
30 |
+
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 |
+
'en' => 'English,English,us',
|
38 |
+
'af' => 'Afrikaans,Afrikaans,za',
|
39 |
+
'sq' => 'Albanian,Shqip,al',
|
40 |
+
'ar' => 'Arabic,العربية,sa',
|
41 |
+
'hy' => 'Armenian,Հայերեն,am',
|
42 |
+
'az' => 'Azerbaijani,azərbaycan dili,az',
|
43 |
+
'eu' => 'Basque,euskara,basque',
|
44 |
+
'be' => 'Belarusian,Беларуская,by',
|
45 |
+
'bg' => 'Bulgarian,Български,bg',
|
46 |
+
'ca' => 'Catalan,Català,catalonia',
|
47 |
+
'zh' => 'Chinese (Simplified),中文(简体),cn',
|
48 |
+
'zh-tw' => 'Chinese (Traditional),中文(漢字),tw',
|
49 |
+
'hr' => 'Croatian,Hrvatski,hr',
|
50 |
+
'cs' => 'Czech,čeština,cz',
|
51 |
+
'da' => 'Danish,dansk,dk',
|
52 |
+
'nl' => 'Dutch,Nederlands,nl',
|
53 |
+
'et' => 'Estonian,Eesti keel,ee',
|
54 |
+
'fi' => 'Finnish,Suomi,fi',
|
55 |
+
'fr' => 'French,Français,fr',
|
56 |
+
'gl' => 'Galician,Galego,galicia',
|
57 |
+
'ka' => 'Georgian,ქართული,ge',
|
58 |
+
'de' => 'German,Deutsch,de',
|
59 |
+
'el' => 'Greek,Ελληνικά,gr',
|
60 |
+
'ht' => 'Haitian,Kreyòl ayisyen,ht',
|
61 |
+
'he' => 'Hebrew,עברית,il',
|
62 |
+
'hi' => 'Hindi,हिन्दी; हिंदी,in',
|
63 |
+
'hu' => 'Hungarian,magyar,hu',
|
64 |
+
'is' => 'Icelandic,íslenska,is',
|
65 |
+
'id' => 'Indonesian,Bahasa Indonesia,id',
|
66 |
+
'ga' => 'Irish,Gaeilge,ie',
|
67 |
+
'it' => 'Italian,Italiano,it',
|
68 |
+
'ja' => 'Japanese,日本語,jp',
|
69 |
+
'ko' => 'Korean,우리말,kr',
|
70 |
+
'lv' => 'Latvian,latviešu valoda,lv',
|
71 |
+
'lt' => 'Lithuanian,lietuvių kalba,lt',
|
72 |
+
'mk' => 'Macedonian,македонски јазик,mk',
|
73 |
+
'ms' => 'Malay,bahasa Melayu,my',
|
74 |
+
'mt' => 'Maltese,Malti,mt',
|
75 |
+
'no' => 'Norwegian,Norsk,no',
|
76 |
+
'fa' => 'Persian,فارسی,ir',
|
77 |
+
'pl' => 'Polish,Polski,pl',
|
78 |
+
'pt' => 'Portuguese,Português,pt',
|
79 |
+
'ro' => 'Romanian,Română,ro',
|
80 |
+
'ru' => 'Russian,Русский,ru',
|
81 |
+
'sr' => 'Serbian,српски језик,rs',
|
82 |
+
'sk' => 'Slovak,slovenčina,sk',
|
83 |
+
'sl' => 'Slovene,slovenščina,sl', //slovenian
|
84 |
+
'es' => 'Spanish,Español,es',
|
85 |
+
'sw' => 'Swahili,Kiswahili,ke',
|
86 |
+
'sv' => 'Swedish,svenska,se',
|
87 |
+
'tl' => 'Tagalog,Tagalog,ph', // fhilipino
|
88 |
+
'th' => 'Thai,ภาษาไทย,th',
|
89 |
+
'tr' => 'Turkish,Türkçe,tr',
|
90 |
+
'uk' => 'Ukrainian,Українська,ua',
|
91 |
+
'ur' => 'Urdu,اردو,pk',
|
92 |
+
'vi' => 'Vietnamese,Tiếng Việt,vn',
|
93 |
+
'cy' => 'Welsh,Cymraeg,wales',
|
94 |
+
'yi' => 'Yiddish,ייִדיש,europeanunion'
|
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 |
+
//Bing supported languages
|
106 |
+
//(got this using Microsoft.Translator.GetLanguages() - fixed to match our codes)
|
107 |
+
//@updated 2010-Jun-30
|
108 |
+
$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');
|
109 |
|
110 |
//Define the new capability that will be assigned to roles - translator
|
111 |
+
define('TRANSLATOR', 'translator');
|
112 |
|
113 |
+
//Define for transposh plugin version
|
114 |
+
define('TRANSPOSH_PLUGIN_VER', '0.5.6');
|
115 |
|
116 |
//Define segment id prefix, will be included in span tag. also used as class identifier
|
117 |
+
define('SPAN_PREFIX', 'tr_');
|
118 |
|
119 |
//The name of our admin page
|
120 |
define('TRANSPOSH_ADMIN_PAGE_NAME', 'transposh');
|
121 |
|
122 |
//0.3.5 - Storing all options in this config option
|
123 |
+
define('TRANSPOSH_OPTIONS', 'transposh_options');
|
124 |
+
|
125 |
+
//0.5.6 new definitions
|
126 |
+
//Defintions for directories used in the plugin
|
127 |
+
define('TRANSPOSH_DIR_CSS', 'css');
|
128 |
+
define('TRANSPOSH_DIR_IMG', 'img');
|
129 |
+
define('TRANSPOSH_DIR_JS', 'js');
|
130 |
+
define('TRANSPOSH_DIR_WIDGETS', 'widgets');
|
131 |
|
132 |
/* Full language list according to ISO
|
133 |
+
ISO 639-1 Language name Native name
|
134 |
+
aa Afar Afaraf
|
135 |
+
ab Abkhazian Аҧсуа
|
136 |
+
ae Avestan avesta
|
137 |
+
af Afrikaans Afrikaans
|
138 |
+
ak Akan Akan
|
139 |
+
am Amharic አማርኛ
|
140 |
+
an Aragonese Aragonés
|
141 |
+
ar Arabic العربية
|
142 |
+
as Assamese অসমীয়া
|
143 |
+
av Avaric авар мацӀ, магӀарул мацӀ
|
144 |
+
ay Aymara aymar aru
|
145 |
+
az Azerbaijani azərbaycan dili
|
146 |
+
ba Bashkir башҡорт теле
|
147 |
+
be Belarusian Беларуская
|
148 |
+
bg Bulgarian български език
|
149 |
+
bh Bihari भोजपुरी
|
150 |
+
bi Bislama Bislama
|
151 |
+
bm Bambara bamanankan
|
152 |
+
bn Bengali বাংলা
|
153 |
+
bo Tibetan བོད་ཡིག
|
154 |
+
br Breton brezhoneg
|
155 |
+
bs Bosnian bosanski jezik
|
156 |
+
ca Catalan, Valencian Català
|
157 |
+
ce Chechen нохчийн мотт
|
158 |
+
ch Chamorro Chamoru
|
159 |
+
co Corsican corsu, lingua corsa
|
160 |
+
cr Cree ᓀᐦᐃᔭᐍᐏᐣ
|
161 |
+
cs Czech česky, čeština
|
162 |
+
cu Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian, Old Church Slavonic ѩзыкъ словѣньскъ
|
163 |
+
cv Chuvash чӑваш чӗлхи
|
164 |
+
cy Welsh Cymraeg
|
165 |
+
da Danish dansk
|
166 |
+
de German Deutsch
|
167 |
+
dv Divehi, Dhivehi, Maldivian ދިވެހި
|
168 |
+
dz Dzongkha རྫོང་ཁ
|
169 |
+
ee Ewe Eʋegbe
|
170 |
+
el Modern Greek Ελληνικά
|
171 |
+
en English English
|
172 |
+
eo Esperanto Esperanto
|
173 |
+
es Spanish, Castilian español, castellano
|
174 |
+
et Estonian eesti, eesti keel
|
175 |
+
eu Basque euskara, euskera
|
176 |
+
fa Persian فارسی
|
177 |
+
ff Fulah Fulfulde, Pulaar, Pular
|
178 |
+
fi Finnish suomi, suomen kieli
|
179 |
+
fj Fijian vosa Vakaviti
|
180 |
+
fo Faroese føroyskt
|
181 |
+
fr French français, langue française
|
182 |
+
fy Western Frisian Frysk
|
183 |
+
ga Irish Gaeilge
|
184 |
+
gd Gaelic, Scottish Gaelic Gàidhlig
|
185 |
+
gl Galician Galego
|
186 |
+
gn Guaraní Avañe'ẽ
|
187 |
+
gu Gujarati ગુજરાતી
|
188 |
+
gv Manx Gaelg, Gailck
|
189 |
+
ha Hausa Hausa, هَوُسَ
|
190 |
+
he Modern Hebrew עברית
|
191 |
+
hi Hindi हिन्दी, हिंदी
|
192 |
+
ho Hiri Motu Hiri Motu
|
193 |
+
hr Croatian hrvatski
|
194 |
+
ht Haitian, Haitian Creole Kreyòl ayisyen
|
195 |
+
hu Hungarian Magyar
|
196 |
+
hy Armenian Հայերեն
|
197 |
+
hz Herero Otjiherero
|
198 |
+
ia Interlingua (International Auxiliary Language Association) Interlingua
|
199 |
+
id Indonesian Bahasa Indonesia
|
200 |
+
ie Interlingue, Occidental Interlingue
|
201 |
+
ig Igbo Igbo
|
202 |
+
ii Sichuan Yi, Nuosu ꆇꉙ
|
203 |
+
ik Inupiaq Iñupiaq, Iñupiatun
|
204 |
+
io Ido Ido
|
205 |
+
is Icelandic Íslenska
|
206 |
+
it Italian Italiano
|
207 |
+
iu Inuktitut ᐃᓄᒃᑎᑐᑦ
|
208 |
+
ja Japanese 日本語 (にほんご/にっぽんご)
|
209 |
+
jv Javanese basa Jawa
|
210 |
+
ka Georgian ქართული
|
211 |
+
kg Kongo KiKongo
|
212 |
+
ki Kikuyu, Gikuyu Gĩkũyũ
|
213 |
+
kj Kwanyama, Kuanyama Kuanyama
|
214 |
+
kk Kazakh Қазақ тілі
|
215 |
+
kl Kalaallisut, Greenlandic kalaallisut, kalaallit oqaasii
|
216 |
+
km Central Khmer ភាសាខ្មែរ
|
217 |
+
kn Kannada ಕನ್ನಡ
|
218 |
+
ko Korean 한국어 (韓國語), 조선말 (朝鮮語)
|
219 |
+
kr Kanuri Kanuri
|
220 |
+
ks Kashmiri कश्मीरी, كشميري
|
221 |
+
ku Kurdish Kurdî, كوردی
|
222 |
+
kv Komi коми кыв
|
223 |
+
kw Cornish Kernewek
|
224 |
+
ky Kirghiz, Kyrgyz кыргыз тили
|
225 |
+
la Latin latine, lingua latina
|
226 |
+
lb Luxembourgish, Letzeburgesch Lëtzebuergesch
|
227 |
+
lg Ganda Luganda
|
228 |
+
li Limburgish, Limburgan, Limburger Limburgs
|
229 |
+
ln Lingala Lingála
|
230 |
+
lo Lao ພາສາລາວ
|
231 |
+
lt Lithuanian lietuvių kalba
|
232 |
+
lu Luba-Katanga
|
233 |
+
lv Latvian latviešu valoda
|
234 |
+
mg Malagasy Malagasy fiteny
|
235 |
+
mh Marshallese Kajin M̧ajeļ
|
236 |
+
mi Māori te reo Māori
|
237 |
+
mk Macedonian македонски јазик
|
238 |
+
ml Malayalam മലയാളം
|
239 |
+
mn Mongolian Монгол
|
240 |
+
mr Marathi मराठी
|
241 |
+
ms Malay bahasa Melayu, بهاس ملايو
|
242 |
+
mt Maltese Malti
|
243 |
+
my Burmese ဗမာစာ
|
244 |
+
na Nauru Ekakairũ Naoero
|
245 |
+
nb Norwegian Bokmål Norsk bokmål
|
246 |
+
nd North Ndebele isiNdebele
|
247 |
+
ne Nepali नेपाली
|
248 |
+
ng Ndonga Owambo
|
249 |
+
nl Dutch, Flemish Nederlands, Vlaams
|
250 |
+
nn Norwegian Nynorsk Norsk nynorsk
|
251 |
+
no Norwegian Norsk
|
252 |
+
nr South Ndebele isiNdebele
|
253 |
+
nv Navajo, Navaho Diné bizaad, Dinékʼehǰí
|
254 |
+
ny Chichewa, Chewa, Nyanja chiCheŵa, chinyanja
|
255 |
+
oc Occitan (after 1500) Occitan
|
256 |
+
oj Ojibwa ᐊᓂᔑᓈᐯᒧᐎᓐ
|
257 |
+
om Oromo Afaan Oromoo
|
258 |
+
or Oriya ଓଡ଼ିଆ
|
259 |
+
os Ossetian, Ossetic Ирон æвзаг
|
260 |
+
pa Panjabi, Punjabi ਪੰਜਾਬੀ, پنجابی
|
261 |
+
pi Pāli पाऴि
|
262 |
+
pl Polish polski
|
263 |
+
ps Pashto, Pushto پښتو
|
264 |
+
pt Portuguese Português
|
265 |
+
qu Quechua Runa Simi, Kichwa
|
266 |
+
rm Romansh rumantsch grischun
|
267 |
+
rn Rundi kiRundi
|
268 |
+
ro Romanian, Moldavian, Moldovan română
|
269 |
+
ru Russian Русский язык
|
270 |
+
rw Kinyarwanda Ikinyarwanda
|
271 |
+
sa Sanskrit संस्कृतम्
|
272 |
+
sc Sardinian sardu
|
273 |
+
sd Sindhi सिन्धी, سنڌي، سندھی
|
274 |
+
se Northern Sami Davvisámegiella
|
275 |
+
sg Sango yângâ tî sängö
|
276 |
+
si Sinhala, Sinhalese සිංහල
|
277 |
+
sk Slovak slovenčina
|
278 |
+
sl Slovene slovenščina
|
279 |
+
sm Samoan gagana fa'a Samoa
|
280 |
+
sn Shona chiShona
|
281 |
+
so Somali Soomaaliga, af Soomaali
|
282 |
+
sq Albanian Shqip
|
283 |
+
sr Serbian српски језик
|
284 |
+
ss Swati SiSwati
|
285 |
+
st Southern Sotho Sesotho
|
286 |
+
su Sundanese Basa Sunda
|
287 |
+
sv Swedish svenska
|
288 |
+
sw Swahili Kiswahili
|
289 |
+
ta Tamil தமிழ்
|
290 |
+
te Telugu తెలుగు
|
291 |
+
tg Tajik тоҷикӣ, toğikī, تاجیکی
|
292 |
+
th Thai ไทย
|
293 |
+
ti Tigrinya ትግርኛ
|
294 |
+
tk Turkmen Türkmen, Түркмен
|
295 |
+
tl Tagalog Wikang Tagalog, ᜏᜒᜃᜅ᜔ ᜆᜄᜎᜓᜄ᜔
|
296 |
+
tn Tswana Setswana
|
297 |
+
to Tonga (Tonga Islands) faka Tonga
|
298 |
+
tr Turkish Türkçe
|
299 |
+
ts Tsonga Xitsonga
|
300 |
+
tt Tatar татарча, tatarça, تاتارچا
|
301 |
+
tw Twi Twi
|
302 |
+
ty Tahitian Reo Mā`ohi
|
303 |
+
ug Uighur, Uyghur Uyƣurqə, ئۇيغۇرچە
|
304 |
+
uk Ukrainian Українська
|
305 |
+
ur Urdu اردو
|
306 |
+
uz Uzbek O'zbek, Ўзбек, أۇزبېك
|
307 |
+
ve Venda Tshivenḓa
|
308 |
+
vi Vietnamese Tiếng Việt
|
309 |
+
vo Volapük Volapük
|
310 |
+
wa Walloon Walon
|
311 |
+
wo Wolof Wollof
|
312 |
+
xh Xhosa isiXhosa
|
313 |
+
yi Yiddish ייִדיש
|
314 |
+
yo Yoruba Yorùbá
|
315 |
+
za Zhuang, Chuang Saɯ cueŋƅ, Saw cuengh
|
316 |
+
zh Chinese 中文 (Zhōngwén), 汉语, 漢語
|
317 |
+
zu Zulu isiZulu
|
318 |
|
319 |
+
*/
|
320 |
?>
|
core/globals.php
DELETED
@@ -1,46 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
-
*
|
4 |
-
* This program is free software; you can redistribute it and/or modify
|
5 |
-
* it under the terms of the GNU General Public License as published by
|
6 |
-
* the Free Software Foundation; either version 2 of the License, or
|
7 |
-
* (at your option) any later version.
|
8 |
-
*
|
9 |
-
* This program is distributed in the hope that it will be useful,
|
10 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
-
* GNU General Public License for more details.
|
13 |
-
*
|
14 |
-
* You should have received a copy of the GNU General Public License
|
15 |
-
* along with this program; if not, write to the Free Software
|
16 |
-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17 |
-
*/
|
18 |
-
|
19 |
-
|
20 |
-
/**
|
21 |
-
*
|
22 |
-
* Contains the global settings which are shared among the different tasks
|
23 |
-
* of this plugin.
|
24 |
-
*
|
25 |
-
*/
|
26 |
-
|
27 |
-
//Home (root) url of the site/blog under which translation will take place.
|
28 |
-
//$home_url;
|
29 |
-
|
30 |
-
//The url pointing to the base of the plugin. Used for generating urls to resources
|
31 |
-
//$tr_plugin_url;
|
32 |
-
|
33 |
-
//The language to which the current page will be translated to.
|
34 |
-
//$lang;
|
35 |
-
|
36 |
-
//Is the current user is in edit mode.
|
37 |
-
//$is_edit_mode = FALSE;
|
38 |
-
|
39 |
-
//Indicates whether automatic translation (i.e. google) is enabled for this page
|
40 |
-
//$enable_auto_translate = FALSE;
|
41 |
-
|
42 |
-
//Indicates whether to use parameters when rewriting url as oppposed to using permalinks format
|
43 |
-
// http://wordpress?lang=he vs. http://wordpress/he/ when flag is set to TRUE
|
44 |
-
//$enable_permalinks_rewrite = FALSE;
|
45 |
-
|
46 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
core/parser.php
CHANGED
@@ -1,49 +1,49 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*/
|
18 |
|
19 |
require_once("shd/simple_html_dom.php");
|
|
|
20 |
|
21 |
|
22 |
/**
|
23 |
* parserstats class - holds parser statistics
|
24 |
*/
|
25 |
class parserstats {
|
|
|
26 |
/** @var int Holds the total phrases the parser encountered */
|
27 |
public $total_phrases;
|
28 |
/** @var int Holds the number of phrases that had translation */
|
29 |
public $translated_phrases;
|
30 |
/** @var int Holds the number of phrases that had human translation */
|
31 |
public $human_translated_phrases;
|
32 |
-
|
33 |
/** @var int Holds the number of phrases that are hidden - yet still somewhat viewable (such as the title attribure) */
|
34 |
public $hidden_phrases;
|
35 |
/** @var int Holds the number of phrases that are hidden and translated */
|
36 |
public $hidden_translated_phrases;
|
37 |
/** @var int Holds the amounts of hidden spans created for translation */
|
38 |
public $hidden_translateable_phrases;
|
39 |
-
|
40 |
/** @var int Holds the number of phrases that are hidden and probably won't be viewed - such as meta keys */
|
41 |
public $meta_phrases;
|
42 |
/** @var int Holds the number of translated phrases that are hidden and probably won't be viewed - such as meta keys */
|
43 |
public $meta_translated_phrases;
|
44 |
/** @var float Holds the time translation took */
|
45 |
public $time;
|
46 |
-
|
47 |
/** @var int Holds the time translation started */
|
48 |
private $start_time;
|
49 |
|
@@ -51,7 +51,7 @@ class parserstats {
|
|
51 |
* This function is when the object is initialized, which is a good time to start ticking.
|
52 |
*/
|
53 |
function parserstats() {
|
54 |
-
|
55 |
}
|
56 |
|
57 |
/**
|
@@ -59,42 +59,47 @@ class parserstats {
|
|
59 |
* @return int How many phrases were auto-translated
|
60 |
*/
|
61 |
function get_computer_translated_phrases() {
|
62 |
-
|
63 |
}
|
|
|
64 |
/**
|
65 |
* Calculated values - missing phrases
|
66 |
* @return int How many phrases are missing
|
67 |
*/
|
68 |
function get_missing_phrases() {
|
69 |
-
|
70 |
}
|
|
|
71 |
/**
|
72 |
* Start the timer
|
73 |
*/
|
74 |
function start_timing() {
|
75 |
-
|
76 |
}
|
|
|
77 |
/**
|
78 |
* Stop timing, store time for reference
|
79 |
*/
|
80 |
function stop_timing() {
|
81 |
-
|
82 |
}
|
|
|
83 |
}
|
84 |
|
85 |
/**
|
86 |
* Parser class - allows phrase marking and translation with callback functions
|
87 |
*/
|
88 |
class parser {
|
|
|
89 |
public $url_rewrite_func = null;
|
90 |
public $fetch_translate_func = null;
|
91 |
public $prefetch_translate_func = null;
|
92 |
-
|
93 |
private $segment_id = 0;
|
94 |
/** @var simple_html_dom_node Contains the current node */
|
95 |
private $currentnode;
|
96 |
/** @var simple_html_dom Contains the document dom model */
|
97 |
-
private $html;
|
|
|
98 |
public $dir_rtl;
|
99 |
/** @var string Contains the iso of the target language */
|
100 |
public $lang;
|
@@ -108,7 +113,7 @@ class parser {
|
|
108 |
public $is_auto_translate;
|
109 |
public $feed_fix;
|
110 |
//first three are html, later 3 come from feeds xml (link is problematic...)
|
111 |
-
protected $ignore_tags = array('script'=>1, 'style'=>1, 'code'=>1,'wfw:commentrss'=>1,'comments'=>1,'guid'=>1);
|
112 |
/** @var parserstats Contains parsing statistics */
|
113 |
private $stats;
|
114 |
|
@@ -118,8 +123,8 @@ class parser {
|
|
118 |
* @return boolean true if current position marks a white space
|
119 |
*/
|
120 |
function is_white_space($char) {
|
121 |
-
|
122 |
-
|
123 |
}
|
124 |
|
125 |
/**
|
@@ -128,7 +133,7 @@ class parser {
|
|
128 |
* @return boolean true if a-z
|
129 |
*/
|
130 |
function is_a_to_z_character($char) {
|
131 |
-
|
132 |
}
|
133 |
|
134 |
/**
|
@@ -136,7 +141,7 @@ class parser {
|
|
136 |
* @return boolean true if a digit
|
137 |
*/
|
138 |
function is_digit($char) {
|
139 |
-
|
140 |
}
|
141 |
|
142 |
/**
|
@@ -146,12 +151,13 @@ class parser {
|
|
146 |
* @return int length of entity
|
147 |
*/
|
148 |
function is_html_entity($string, $position) {
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
155 |
}
|
156 |
|
157 |
/**
|
@@ -163,87 +169,86 @@ class parser {
|
|
163 |
* @return boolean true if not a breaker (apostrophy)
|
164 |
*/
|
165 |
function is_entity_breaker($entity) {
|
166 |
-
|
167 |
}
|
168 |
|
169 |
/**
|
170 |
* Some entities are to be regarded as simple letters in most cases
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
*/
|
236 |
-
|
237 |
function is_entity_letter($entity) {
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
}
|
248 |
|
249 |
/**
|
@@ -254,10 +259,14 @@ class parser {
|
|
254 |
* @return int length of breaker if current position marks a break in sentence
|
255 |
*/
|
256 |
function is_sentence_breaker($char, $nextchar, $nextnextchar) {
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
|
|
|
|
|
|
|
|
261 |
}
|
262 |
|
263 |
/**
|
@@ -265,7 +274,7 @@ class parser {
|
|
265 |
* @return int length of number.
|
266 |
*/
|
267 |
function is_number($page, $position) {
|
268 |
-
|
269 |
}
|
270 |
|
271 |
/**
|
@@ -273,21 +282,19 @@ class parser {
|
|
273 |
* @param int $start - beginning of pharse in element
|
274 |
* @param int $end - end of pharse in element
|
275 |
*/
|
276 |
-
function tag_phrase($string
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
$node->inselect = true;
|
290 |
-
}
|
291 |
}
|
292 |
|
293 |
/**
|
@@ -295,72 +302,72 @@ class parser {
|
|
295 |
* @param string $string - the string which is "broken" into smaller strings
|
296 |
*/
|
297 |
function parsetext($string) {
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
}
|
365 |
|
366 |
/**
|
@@ -369,87 +376,86 @@ class parser {
|
|
369 |
* @param simple_html_dom_node $node
|
370 |
*/
|
371 |
function translate_tagging($node, $level = 0) {
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
}
|
453 |
}
|
454 |
|
455 |
/**
|
@@ -460,24 +466,24 @@ class parser {
|
|
460 |
* @param boolean $for_hidden_element
|
461 |
* @return string
|
462 |
*/
|
463 |
-
function create_edit_span
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
}
|
482 |
|
483 |
/**
|
@@ -486,220 +492,220 @@ class parser {
|
|
486 |
* @return string Translated content is here
|
487 |
*/
|
488 |
function fix_html($string) {
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
}
|
704 |
|
705 |
/**
|
@@ -709,17 +715,18 @@ class parser {
|
|
709 |
* @since 0.3.5
|
710 |
*/
|
711 |
function get_phrases_list($string) {
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
}
|
|
|
724 |
}
|
725 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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");
|
21 |
+
require_once("constants.php");
|
22 |
|
23 |
|
24 |
/**
|
25 |
* parserstats class - holds parser statistics
|
26 |
*/
|
27 |
class parserstats {
|
28 |
+
|
29 |
/** @var int Holds the total phrases the parser encountered */
|
30 |
public $total_phrases;
|
31 |
/** @var int Holds the number of phrases that had translation */
|
32 |
public $translated_phrases;
|
33 |
/** @var int Holds the number of phrases that had human translation */
|
34 |
public $human_translated_phrases;
|
|
|
35 |
/** @var int Holds the number of phrases that are hidden - yet still somewhat viewable (such as the title attribure) */
|
36 |
public $hidden_phrases;
|
37 |
/** @var int Holds the number of phrases that are hidden and translated */
|
38 |
public $hidden_translated_phrases;
|
39 |
/** @var int Holds the amounts of hidden spans created for translation */
|
40 |
public $hidden_translateable_phrases;
|
|
|
41 |
/** @var int Holds the number of phrases that are hidden and probably won't be viewed - such as meta keys */
|
42 |
public $meta_phrases;
|
43 |
/** @var int Holds the number of translated phrases that are hidden and probably won't be viewed - such as meta keys */
|
44 |
public $meta_translated_phrases;
|
45 |
/** @var float Holds the time translation took */
|
46 |
public $time;
|
|
|
47 |
/** @var int Holds the time translation started */
|
48 |
private $start_time;
|
49 |
|
51 |
* This function is when the object is initialized, which is a good time to start ticking.
|
52 |
*/
|
53 |
function parserstats() {
|
54 |
+
$this->start_time = microtime(true);
|
55 |
}
|
56 |
|
57 |
/**
|
59 |
* @return int How many phrases were auto-translated
|
60 |
*/
|
61 |
function get_computer_translated_phrases() {
|
62 |
+
return $this->translated_phrases - $this->human_translated_phrases;
|
63 |
}
|
64 |
+
|
65 |
/**
|
66 |
* Calculated values - missing phrases
|
67 |
* @return int How many phrases are missing
|
68 |
*/
|
69 |
function get_missing_phrases() {
|
70 |
+
return $this->total_phrases - $this->translated_phrases;
|
71 |
}
|
72 |
+
|
73 |
/**
|
74 |
* Start the timer
|
75 |
*/
|
76 |
function start_timing() {
|
77 |
+
$this->start_time = microtime(true);
|
78 |
}
|
79 |
+
|
80 |
/**
|
81 |
* Stop timing, store time for reference
|
82 |
*/
|
83 |
function stop_timing() {
|
84 |
+
$this->time = number_format(microtime(true) - $this->start_time, 3);
|
85 |
}
|
86 |
+
|
87 |
}
|
88 |
|
89 |
/**
|
90 |
* Parser class - allows phrase marking and translation with callback functions
|
91 |
*/
|
92 |
class parser {
|
93 |
+
|
94 |
public $url_rewrite_func = null;
|
95 |
public $fetch_translate_func = null;
|
96 |
public $prefetch_translate_func = null;
|
|
|
97 |
private $segment_id = 0;
|
98 |
/** @var simple_html_dom_node Contains the current node */
|
99 |
private $currentnode;
|
100 |
/** @var simple_html_dom Contains the document dom model */
|
101 |
+
private $html;
|
102 |
+
// the document
|
103 |
public $dir_rtl;
|
104 |
/** @var string Contains the iso of the target language */
|
105 |
public $lang;
|
113 |
public $is_auto_translate;
|
114 |
public $feed_fix;
|
115 |
//first three are html, later 3 come from feeds xml (link is problematic...)
|
116 |
+
protected $ignore_tags = array('script' => 1, 'style' => 1, 'code' => 1, 'wfw:commentrss' => 1, 'comments' => 1, 'guid' => 1);
|
117 |
/** @var parserstats Contains parsing statistics */
|
118 |
private $stats;
|
119 |
|
123 |
* @return boolean true if current position marks a white space
|
124 |
*/
|
125 |
function is_white_space($char) {
|
126 |
+
if (!$char) return TRUE;
|
127 |
+
return strspn($char, " \t\r\n\0\x0B");
|
128 |
}
|
129 |
|
130 |
/**
|
133 |
* @return boolean true if a-z
|
134 |
*/
|
135 |
function is_a_to_z_character($char) {
|
136 |
+
return (($char >= 'a' && $char <= 'z') || ($char >= 'A' && $char <= 'Z')) ? true : false;
|
137 |
}
|
138 |
|
139 |
/**
|
141 |
* @return boolean true if a digit
|
142 |
*/
|
143 |
function is_digit($char) {
|
144 |
+
return (($char >= '0' && $char <= '9')) ? true : false;
|
145 |
}
|
146 |
|
147 |
/**
|
151 |
* @return int length of entity
|
152 |
*/
|
153 |
function is_html_entity($string, $position) {
|
154 |
+
if ($string[$position] == "&") {
|
155 |
+
$end_pos = $position + 1;
|
156 |
+
while ($string[$end_pos] == "#" || $this->is_digit($string[$end_pos]) || $this->is_a_to_z_character($string[$end_pos]))
|
157 |
+
++$end_pos;
|
158 |
+
if ($string[$end_pos] == ';') return $end_pos - $position + 1;
|
159 |
+
}
|
160 |
+
return 0;
|
161 |
}
|
162 |
|
163 |
/**
|
169 |
* @return boolean true if not a breaker (apostrophy)
|
170 |
*/
|
171 |
function is_entity_breaker($entity) {
|
172 |
+
return!(stripos('’'"''', $entity) !== FALSE);
|
173 |
}
|
174 |
|
175 |
/**
|
176 |
* Some entities are to be regarded as simple letters in most cases
|
177 |
+
À À À À latin capital letter A with grave
|
178 |
+
Á Á Á Á latin capital letter A with acute
|
179 |
+
    latin capital letter A with circumflex
|
180 |
+
à à à à latin capital letter A with tilde
|
181 |
+
Ä Ä Ä Ä latin capital letter A with diaeresis
|
182 |
+
Å Å Å Å latin capital letter A with ring above
|
183 |
+
Æ Æ Æ Æ latin capital letter AE
|
184 |
+
Ç Ç Ç Ç latin capital letter C with cedilla
|
185 |
+
È È È È latin capital letter E with grave
|
186 |
+
É É É É latin capital letter E with acute
|
187 |
+
Ê Ê Ê Ê latin capital letter E with circumflex
|
188 |
+
Ë Ë Ë Ë latin capital letter E with diaeresis
|
189 |
+
Ì Ì Ì Ì latin capital letter I with grave
|
190 |
+
Í Í Í Í latin capital letter I with acute
|
191 |
+
Î Î Î Î latin capital letter I with circumflex
|
192 |
+
Ï Ï Ï Ï latin capital letter I with diaeresis
|
193 |
+
Ð Ð Ð Ð latin capital letter ETH
|
194 |
+
Ñ Ñ Ñ Ñ latin capital letter N with tilde
|
195 |
+
Ò Ò Ò Ò latin capital letter O with grave
|
196 |
+
Ó Ó Ó Ó latin capital letter O with acute
|
197 |
+
Ô Ô Ô Ô latin capital letter O with circumflex
|
198 |
+
Õ Õ Õ Õ latin capital letter O with tilde
|
199 |
+
Ö Ö Ö Ö latin capital letter O with diaeresis
|
200 |
+
//× × × × multiplication sign
|
201 |
+
Ø Ø Ø Ø latin capital letter O with stroke
|
202 |
+
Ù Ù Ù Ù latin capital letter U with grave
|
203 |
+
Ú Ú Ú Ú latin capital letter U with acute
|
204 |
+
Û Û Û Û latin capital letter U with circumflex
|
205 |
+
Ü Ü Ü Ü latin capital letter U with diaeresis
|
206 |
+
Ý Ý Ý Ý latin capital letter Y with acute
|
207 |
+
Þ Þ Þ Þ latin capital letter THORN
|
208 |
+
ß ß ß ß latin small letter sharp s
|
209 |
+
à à à à latin small letter a with grave
|
210 |
+
á á á á latin small letter a with acute
|
211 |
+
â â â â latin small letter a with circumflex
|
212 |
+
ã ã ã ã latin small letter a with tilde
|
213 |
+
ä ä ä ä latin small letter a with diaeresis
|
214 |
+
å å å å latin small letter a with ring above
|
215 |
+
æ æ æ æ latin small letter ae
|
216 |
+
ç ç ç ç latin small letter c with cedilla
|
217 |
+
è è è è latin small letter e with grave
|
218 |
+
é é é é latin small letter e with acute
|
219 |
+
ê ê ê ê latin small letter e with circumflex
|
220 |
+
ë ë ë ë latin small letter e with diaeresis
|
221 |
+
ì ì ì ì latin small letter i with grave
|
222 |
+
í í í í latin small letter i with acute
|
223 |
+
î î î î latin small letter i with circumflex
|
224 |
+
ï ï ï ï latin small letter i with diaeresis
|
225 |
+
ð ð ð ð latin small letter eth
|
226 |
+
ñ ñ ñ ñ latin small letter n with tilde
|
227 |
+
ò ò ò ò latin small letter o with grave
|
228 |
+
ó ó ó ó latin small letter o with acute
|
229 |
+
ô ô ô ô latin small letter o with circumflex
|
230 |
+
õ õ õ õ latin small letter o with tilde
|
231 |
+
ö ö ö ö latin small letter o with diaeresis
|
232 |
+
//÷ ÷ ÷ ÷ division sign
|
233 |
+
ø ø ø ø latin small letter o with stroke
|
234 |
+
ù ù ù ù latin small letter u with grave
|
235 |
+
ú ú ú ú latin small letter u with acute
|
236 |
+
û û û û latin small letter u with circumflex
|
237 |
+
ü ü ü ü latin small letter u with diaeresis
|
238 |
+
ý ý ý ý latin small letter y with acute
|
239 |
+
þ þ þ þ latin small letter thorn
|
240 |
+
ÿ ÿ ÿ ÿ latin small letter y with diaeresis
|
241 |
*/
|
|
|
242 |
function is_entity_letter($entity) {
|
243 |
+
|
244 |
+
$entnum = (int) substr($entity, 2);
|
245 |
+
if (($entnum >= 192 && $entnum <= 214) || ($entnum >= 216 && $entnum <= 246) || ($entnum >= 248 && $entnum <= 255)) {
|
246 |
+
return true;
|
247 |
+
}
|
248 |
+
$entities = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐ' .
|
249 |
+
'ÑÒÓÔÕÖØÙÚÛÜÝÞß' .
|
250 |
+
'øùÿ';
|
251 |
+
return (stripos($entities, $entity) !== FALSE);
|
252 |
}
|
253 |
|
254 |
/**
|
259 |
* @return int length of breaker if current position marks a break in sentence
|
260 |
*/
|
261 |
function is_sentence_breaker($char, $nextchar, $nextnextchar) {
|
262 |
+
if (($char == '.' || $char == '-') && ($this->is_white_space($nextchar)))
|
263 |
+
return 1;
|
264 |
+
//∙
|
265 |
+
if (ord($char) == 226 && ord($nextchar) == 136 && ord($nextnextchar) == 153)
|
266 |
+
return 3;
|
267 |
+
//·
|
268 |
+
if (ord($char) == 194 && ord($nextchar) == 183) return 2;
|
269 |
+
return (strpos(',?()[]"!:|;', $char) !== false) ? 1 : 0; // TODO: might need to add < and > here
|
270 |
}
|
271 |
|
272 |
/**
|
274 |
* @return int length of number.
|
275 |
*/
|
276 |
function is_number($page, $position) {
|
277 |
+
return strspn($page, '0123456789-+$%,.\\/', $position);
|
278 |
}
|
279 |
|
280 |
/**
|
282 |
* @param int $start - beginning of pharse in element
|
283 |
* @param int $end - end of pharse in element
|
284 |
*/
|
285 |
+
function tag_phrase($string, $start, $end) {
|
286 |
+
$phrase = trim(substr($string, $start, $end - $start));
|
287 |
+
if ($phrase) {
|
288 |
+
|
289 |
+
$node = new simple_html_dom_node($this->html);
|
290 |
+
$node->tag = 'phrase';
|
291 |
+
$node->parent = $this->currentnode;
|
292 |
+
$this->currentnode->nodes[] = $node;
|
293 |
+
$node->_[HDOM_INFO_OUTER] = '';
|
294 |
+
$node->phrase = $phrase;
|
295 |
+
if ($this->inbody) $node->inbody = $this->inbody;
|
296 |
+
if ($this->inselect) $node->inselect = true;
|
297 |
+
}
|
|
|
|
|
298 |
}
|
299 |
|
300 |
/**
|
302 |
* @param string $string - the string which is "broken" into smaller strings
|
303 |
*/
|
304 |
function parsetext($string) {
|
305 |
+
$pos = 0;
|
306 |
+
// $pos = skip_white_space($string, $pos);
|
307 |
+
// skip CDATA in feed_fix mode
|
308 |
+
if ($this->feed_fix) {
|
309 |
+
if (strpos($string, '<![CDATA[') === 0) {
|
310 |
+
$pos = 9; // CDATA length
|
311 |
+
$string = substr($string, 0, -3); // chop the last ]]>;
|
312 |
+
}
|
313 |
+
}
|
314 |
+
|
315 |
+
$start = $pos;
|
316 |
+
|
317 |
+
while ($pos < strlen($string)) {
|
318 |
+
// Some HTML entities make us break, almost all but apostrophies
|
319 |
+
if ($len_of_entity = $this->is_html_entity($string, $pos)) {
|
320 |
+
$entity = substr($string, $pos, $len_of_entity);
|
321 |
+
if (($this->is_white_space($string[$pos + $len_of_entity]) || $this->is_entity_breaker($entity)) && !$this->is_entity_letter($entity)) {
|
322 |
+
|
323 |
+
$this->tag_phrase($string, $start, $pos);
|
324 |
+
$start = $pos + $len_of_entity;
|
325 |
+
}
|
326 |
+
//skip past entity
|
327 |
+
$pos += $len_of_entity;
|
328 |
+
}
|
329 |
+
// we have a special case for <> tags which might have came to us (maybe in xml feeds) (we'll skip them...)
|
330 |
+
elseif ($string[$pos] == '<') {
|
331 |
+
$this->tag_phrase($string, $start, $pos);
|
332 |
+
while ($string[$pos] != '>' && $pos < strlen($string))
|
333 |
+
$pos++;
|
334 |
+
$pos++;
|
335 |
+
$start = $pos;
|
336 |
+
}
|
337 |
+
// will break translation unit when there's a breaker ",.[]()..."
|
338 |
+
elseif ($senb_len = $this->is_sentence_breaker($string[$pos], $string[$pos + 1], $string[$pos + 2])) {
|
339 |
+
$this->tag_phrase($string, $start, $pos);
|
340 |
+
$pos += $senb_len;
|
341 |
+
$start = $pos;
|
342 |
+
}
|
343 |
+
// Numbers also break, if they are followed by whitespace (or a sentence breaker) (don't break 42nd) // TODO: probably by breaking entities too...
|
344 |
+
// also prefixed by whitespace?
|
345 |
+
elseif ($num_len = $this->is_number($string, $pos)) {
|
346 |
+
// this is the case of B2 or B2,
|
347 |
+
if (($this->is_white_space($string[$pos - 1]) || ($start == $pos)
|
348 |
+
|| ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1]))) &&
|
349 |
+
($this->is_white_space($string[$pos + $num_len]) || $this->is_sentence_breaker($string[$pos + $num_len], $string[$pos + $num_len + 1], $string[$pos + $num_len + 2]))) {
|
350 |
+
// we will now compensate on the number followed by breaker case, if we need to
|
351 |
+
if (!($this->is_white_space($string[$pos - 1]) || ($start == $pos))) {
|
352 |
+
if ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1])) {
|
353 |
+
$num_len--; //this makes the added number shorter by one, and the pos will be at a sentence breaker next so we don't have to compensate
|
354 |
+
}
|
355 |
+
$pos += $num_len;
|
356 |
+
$num_len = 0; // we have already added this
|
357 |
+
}
|
358 |
+
$this->tag_phrase($string, $start, $pos);
|
359 |
+
$start = $pos + $num_len + 1;
|
360 |
+
}
|
361 |
+
$pos += $num_len + 1;
|
362 |
+
} else {
|
363 |
+
$pos++;
|
364 |
+
}
|
365 |
+
}
|
366 |
+
|
367 |
+
// the end is also some breaker
|
368 |
+
if ($pos > $start) {
|
369 |
+
$this->tag_phrase($string, $start, $pos);
|
370 |
+
}
|
371 |
}
|
372 |
|
373 |
/**
|
376 |
* @param simple_html_dom_node $node
|
377 |
*/
|
378 |
function translate_tagging($node, $level = 0) {
|
379 |
+
$this->currentnode = $node;
|
380 |
+
// we don't want to translate non-translatable classes
|
381 |
+
if (stripos($node->class, NO_TRANSLATE_CLASS) !== false ||
|
382 |
+
stripos($node->class, NO_TRANSLATE_CLASS_GOOGLE) !== false ||
|
383 |
+
strtolower($node->lang) === $this->lang) return;
|
384 |
+
|
385 |
+
if ($this->inselect && $level <= $this->inselect) $this->inselect = false;
|
386 |
+
|
387 |
+
if ($this->inlangnondef && $level <= $this->inlangnondef)
|
388 |
+
$this->inlangnondef = false;
|
389 |
+
|
390 |
+
if ($this->default_lang && $node->lang != '' && stripos($node->lang, $this->lang) === false)
|
391 |
+
$this->inlangnondef = $level;
|
392 |
+
|
393 |
+
// we can only do translation for elements which are in the body, not in other places, and this must
|
394 |
+
// move here due to the possibility of early recurse in default language
|
395 |
+
if ($node->tag == 'body') {
|
396 |
+
$this->inbody = true;
|
397 |
+
}
|
398 |
+
// this again should be here, the different behaviour on select and textarea
|
399 |
+
elseif ($node->tag == 'select' || $node->tag == 'textarea') {
|
400 |
+
$this->inselect = $level;
|
401 |
+
}
|
402 |
+
|
403 |
+
//support only_thislanguage class, (nulling the node if it should not display)
|
404 |
+
if (strtolower($node->lang) != $this->lang && stripos($node->class, ONLY_THISLANGUAGE_CLASS) !== false) {
|
405 |
+
$node->outertext = '';
|
406 |
+
return;
|
407 |
+
}
|
408 |
+
|
409 |
+
// if we are in the default lang, and we have no foreign langs classes, we'll recurse from here
|
410 |
+
if ($this->default_lang && !$this->inlangnondef) {
|
411 |
+
foreach ($node->nodes as $c) {
|
412 |
+
$this->translate_tagging($c, $level + 1);
|
413 |
+
}
|
414 |
+
return;
|
415 |
+
}
|
416 |
+
|
417 |
+
if (isset($this->ignore_tags[$node->tag])) return;
|
418 |
+
|
419 |
+
if ($node->tag == 'text') {
|
420 |
+
// this prevents translation of a link that just surrounds its address
|
421 |
+
if ($node->parent->tag == 'a' && $node->parent->href == $node->outertext) {
|
422 |
+
return;
|
423 |
+
}
|
424 |
+
// link tags inners are to be ignored
|
425 |
+
if ($node->parent->tag == 'link') {
|
426 |
+
return;
|
427 |
+
}
|
428 |
+
if (trim($node->outertext)) {
|
429 |
+
$this->parsetext($node->outertext);
|
430 |
+
}
|
431 |
+
}
|
432 |
+
// for anchors we will rewrite urls if we can
|
433 |
+
elseif ($node->tag == 'a') {
|
434 |
+
if ($this->url_rewrite_func != null) {
|
435 |
+
$node->href = call_user_func_array($this->url_rewrite_func, array($node->href));
|
436 |
+
}
|
437 |
+
}
|
438 |
+
// same for options, although normally not required (ticket #34)
|
439 |
+
elseif ($node->tag == 'option') {
|
440 |
+
if ($this->url_rewrite_func != null) {
|
441 |
+
$node->value = call_user_func_array($this->url_rewrite_func, array($node->value));
|
442 |
+
}
|
443 |
+
}
|
444 |
+
// in submit type inputs, we want to translate the value
|
445 |
+
elseif ($node->tag == 'input' && $node->type == 'submit') {
|
446 |
+
$this->parsetext($node->value);
|
447 |
+
}
|
448 |
+
|
449 |
+
// titles are also good places to translate, exist in a, img, abbr, acronym
|
450 |
+
if ($node->title) $this->parsetext($node->title);
|
451 |
+
|
452 |
+
// Meta content (keywords, description) are also good places to translate
|
453 |
+
if ($node->tag == 'meta' && $node->content) $this->parsetext($node->content);
|
454 |
+
|
455 |
+
// recurse
|
456 |
+
foreach ($node->nodes as $c) {
|
457 |
+
$this->translate_tagging($c, $level + 1);
|
458 |
+
}
|
|
|
459 |
}
|
460 |
|
461 |
/**
|
466 |
* @param boolean $for_hidden_element
|
467 |
* @return string
|
468 |
*/
|
469 |
+
function create_edit_span($original_text, $translated_text, $source, $for_hidden_element = false) {
|
470 |
+
// Use base64 encoding to make that when the page is translated (i.e. update_translation) we
|
471 |
+
// get back exactlly the same string without having the client decode/encode it in anyway.
|
472 |
+
$span = '<span class ="' . SPAN_PREFIX . '" id="' . SPAN_PREFIX . $this->segment_id . '" data-token="' . base64_url_encode($original_text) . "\" data-source=\"$source\"";
|
473 |
+
// those are needed for on the fly image creation / hidden elements translations
|
474 |
+
if ($this->is_edit_mode || $for_hidden_element) {
|
475 |
+
$span .= " data-orig=\"$original_text\"";
|
476 |
+
if ($for_hidden_element) {
|
477 |
+
$span.= ' data-hidden="y"';
|
478 |
+
// hidden elements currently have issues figuring what they translated in the JS
|
479 |
+
if ($translated_text != null) {
|
480 |
+
$span.= " data-trans=\"$translated_text\"";
|
481 |
+
}
|
482 |
+
}
|
483 |
+
}
|
484 |
+
$span .= '>';
|
485 |
+
++$this->segment_id;
|
486 |
+
return $span;
|
487 |
}
|
488 |
|
489 |
/**
|
492 |
* @return string Translated content is here
|
493 |
*/
|
494 |
function fix_html($string) {
|
495 |
+
// ready our stats
|
496 |
+
$this->stats = new parserstats();
|
497 |
+
// create our dom
|
498 |
+
$this->html = str_get_html($string);
|
499 |
+
// mark translateable elements
|
500 |
+
$this->translate_tagging($this->html->root);
|
501 |
+
|
502 |
+
// first fix the html tag itself - we might need to to the same for all such attributes with flipping
|
503 |
+
if ($this->dir_rtl) $this->html->find('html', 0)->dir = "rtl";
|
504 |
+
else $this->html->find('html', 0)->dir = "ltr";
|
505 |
+
|
506 |
+
if ($this->lang) {
|
507 |
+
$this->html->find('html', 0)->lang = $this->lang;
|
508 |
+
// add support for <meta name="language" content="<lang>">
|
509 |
+
if ($this->html->find('meta[name=language]')) {
|
510 |
+
$this->html->find('meta[name=language]')->content = $this->lang;
|
511 |
+
}
|
512 |
+
}
|
513 |
+
|
514 |
+
// not much point in further processing if we don't have a function that does it
|
515 |
+
if ($this->fetch_translate_func == null) {
|
516 |
+
return $this->html;
|
517 |
+
}
|
518 |
+
|
519 |
+
// fix feed
|
520 |
+
if ($this->feed_fix) {
|
521 |
+
// fix urls on feed
|
522 |
+
|
523 |
+
foreach (array('link', 'wfw:commentrss', 'comments') as $tag) {
|
524 |
+
foreach ($this->html->find($tag) as $e) {
|
525 |
+
$e->innertext = call_user_func_array($this->url_rewrite_func, array($e->innertext));
|
526 |
+
// no need to translate anything here
|
527 |
+
unset($e->nodes);
|
528 |
+
}
|
529 |
+
}
|
530 |
+
// guid is not really a url -- in some future, we can check if permalink is true and probably falsify it
|
531 |
+
foreach ($this->html->find('guid') as $e) {
|
532 |
+
$e->innertext = $e->innertext . '-' . $this->lang;
|
533 |
+
unset($e->nodes);
|
534 |
+
}
|
535 |
+
// fix feed language
|
536 |
+
$this->html->find('language', 0)->innertext = $this->lang;
|
537 |
+
unset($this->html->find('language', 0)->nodes);
|
538 |
+
} else {
|
539 |
+
// since this is not a feed, we might have references to such in the <link rel="alternate">
|
540 |
+
foreach ($this->html->find('link') as $e) {
|
541 |
+
if (strcasecmp($e->rel, 'alternate') == 0 || strcasecmp($e->rel, 'canonical') == 0) {
|
542 |
+
$e->href = call_user_func_array($this->url_rewrite_func, array($e->href));
|
543 |
+
}
|
544 |
+
}
|
545 |
+
}
|
546 |
+
|
547 |
+
// try some prefetching... (//todo - maybe move directly to the phrase create)
|
548 |
+
if ($this->prefetch_translate_func != null) {
|
549 |
+
foreach ($this->html->find('text') as $e) {
|
550 |
+
foreach ($e->nodes as $ep) {
|
551 |
+
$originals[] = $ep->phrase;
|
552 |
+
}
|
553 |
+
}
|
554 |
+
foreach (array('title', 'value') as $title) {
|
555 |
+
foreach ($this->html->find('[' . $title . ']') as $e) {
|
556 |
+
foreach ($e->nodes as $ep) {
|
557 |
+
$originals[] = $ep->phrase;
|
558 |
+
}
|
559 |
+
}
|
560 |
+
}
|
561 |
+
foreach ($this->html->find('[content]') as $e) {
|
562 |
+
foreach ($e->nodes as $ep) {
|
563 |
+
$originals[] = $ep->phrase;
|
564 |
+
}
|
565 |
+
}
|
566 |
+
call_user_func_array($this->prefetch_translate_func, array($originals, $this->lang));
|
567 |
+
}
|
568 |
+
|
569 |
+
// actually translate tags
|
570 |
+
// texts are first
|
571 |
+
foreach ($this->html->find('text') as $e) {
|
572 |
+
$right = '';
|
573 |
+
$newtext = '';
|
574 |
+
foreach ($e->nodes as $ep) {
|
575 |
+
list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
|
576 |
+
//stats
|
577 |
+
$this->stats->total_phrases++;
|
578 |
+
if ($translated_text) {
|
579 |
+
$this->stats->translated_phrases++;
|
580 |
+
if ($source == 0) $this->stats->human_translated_phrases++;
|
581 |
+
}
|
582 |
+
if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null))/* && $ep->inbody */) {
|
583 |
+
$spanend = "</span>";
|
584 |
+
if ($ep->inselect || !$ep->inbody) {
|
585 |
+
$savedspan .= $this->create_edit_span($ep->phrase, $translated_text, $source, true) . $spanend;
|
586 |
+
$span = '';
|
587 |
+
$spanend = '';
|
588 |
+
} else {
|
589 |
+
$span = $this->create_edit_span($ep->phrase, $translated_text, $source);
|
590 |
+
if ($translated_text == null) $translated_text = $ep->phrase;
|
591 |
+
}
|
592 |
+
}
|
593 |
+
else {
|
594 |
+
$span = '';
|
595 |
+
$spanend = '';
|
596 |
+
}
|
597 |
+
if ($translated_text) {
|
598 |
+
list ($left, $right) = explode($ep->phrase, $e->outertext, 2);
|
599 |
+
$newtext .= $left . $span . $translated_text . $spanend;
|
600 |
+
$e->outertext = $right;
|
601 |
+
}
|
602 |
+
}
|
603 |
+
if ($newtext) {
|
604 |
+
$e->outertext = $newtext . $right;
|
605 |
+
|
606 |
+
}
|
607 |
+
// hmm?
|
608 |
+
if (!$ep->inselect && $savedspan && $ep->inbody) {
|
609 |
+
$e->outertext = $savedspan . $e->outertext;
|
610 |
+
$savedspan = "";
|
611 |
+
}
|
612 |
+
}
|
613 |
+
|
614 |
+
// now we handle the title attributes (and the value of submit buttons)
|
615 |
+
foreach (array('title', 'value') as $title) {
|
616 |
+
$hidden_phrases = array();
|
617 |
+
foreach ($this->html->find('[' . $title . ']') as $e) {
|
618 |
+
$span = '';
|
619 |
+
$spanend = '';
|
620 |
+
$right = '';
|
621 |
+
$newtext = '';
|
622 |
+
// when we already have a parent outertext we'll have to update it directly
|
623 |
+
if ($e->parent->_[HDOM_INFO_OUTER]) {
|
624 |
+
$saved_outertext = $e->outertext;
|
625 |
+
}
|
626 |
+
|
627 |
+
foreach ($e->nodes as $ep) {
|
628 |
+
if ($ep->tag == 'phrase') {
|
629 |
+
list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
|
630 |
+
// more stats
|
631 |
+
$this->stats->total_phrases++;
|
632 |
+
if ($ep->inbody) $this->stats->hidden_phrases++; else
|
633 |
+
$this->stats->meta_phrases++;
|
634 |
+
if ($translated_text) {
|
635 |
+
$this->stats->translated_phrases++;
|
636 |
+
if ($ep->inbody) $this->stats->hidden_translated_phrases++; else
|
637 |
+
$this->stats->meta_translated_phrases++;
|
638 |
+
if ($source == 0) $this->stats->human_translated_phrases++;
|
639 |
+
}
|
640 |
+
if (($this->is_edit_mode || ($this->is_auto_translate && $translated_text == null)) && $ep->inbody) {
|
641 |
+
// prevent duplicate translation (title = text)
|
642 |
+
if (strpos($e->innertext, base64_url_encode($ep->phrase)) === false) {
|
643 |
+
//no need to translate span the same hidden phrase more than once
|
644 |
+
if (!in_array($ep->phrase, $hidden_phrases)) {
|
645 |
+
$this->stats->hidden_translateable_phrases++;
|
646 |
+
$span .= $this->create_edit_span($ep->phrase, $translated_text, $source, true) . "</span>";
|
647 |
+
//
|
648 |
+
$hidden_phrases[] = $ep->phrase;
|
649 |
+
}
|
650 |
+
}
|
651 |
+
}
|
652 |
+
if ($translated_text) {
|
653 |
+
list ($left, $right) = explode($ep->phrase, $e->$title, 2);
|
654 |
+
$newtext .= $left . $translated_text;
|
655 |
+
$e->$title = $right;
|
656 |
+
}
|
657 |
+
}
|
658 |
+
}
|
659 |
+
if ($newtext) {
|
660 |
+
$e->$title = $newtext . $right;
|
661 |
+
|
662 |
+
}
|
663 |
+
|
664 |
+
$e->outertext .= $span;
|
665 |
+
// this is where we update in the outercase issue
|
666 |
+
if ($e->parent->_[HDOM_INFO_OUTER]) {
|
667 |
+
$e->parent->outertext = implode($e->outertext, explode($saved_outertext, $e->parent->outertext, 2));
|
668 |
+
}
|
669 |
+
}
|
670 |
+
}
|
671 |
+
|
672 |
+
// now we handle the meta content - which is simpler because they can't be edited or auto-translated
|
673 |
+
// we also don't expect any father modifications here
|
674 |
+
foreach ($this->html->find('[content]') as $e) {
|
675 |
+
$right = '';
|
676 |
+
$newtext = '';
|
677 |
+
|
678 |
+
foreach ($e->nodes as $ep) {
|
679 |
+
if ($ep->tag == 'phrase') {
|
680 |
+
// even more stats
|
681 |
+
$this->stats->total_phrases++;
|
682 |
+
$this->stats->meta_phrases++;
|
683 |
+
list ($translated_text, $source) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
|
684 |
+
if ($translated_text) {
|
685 |
+
$this->stats->translated_phrases++;
|
686 |
+
$this->stats->meta_translated_phrases++;
|
687 |
+
if ($source == 0) $this->stats->human_translated_phrases++;
|
688 |
+
list ($left, $right) = explode($ep->phrase, $e->content, 2);
|
689 |
+
$newtext .= $left . $translated_text;
|
690 |
+
$e->content = $right;
|
691 |
+
}
|
692 |
+
}
|
693 |
+
}
|
694 |
+
if ($newtext) {
|
695 |
+
$e->content = $newtext . $right;
|
696 |
+
|
697 |
+
}
|
698 |
+
}
|
699 |
+
|
700 |
+
// This adds a meta tag with our statistics json-encoded inside...
|
701 |
+
$this->stats->stop_timing();
|
702 |
+
$head = $this->html->find('head', 0);
|
703 |
+
if ($head != null)
|
704 |
+
$head->lastChild()->outertext .= "\n<meta name=\"translation-stats\" content='" . json_encode($this->stats) . "'/>";
|
705 |
+
|
706 |
+
// Changed because of places where tostring failed
|
707 |
+
//return $this->html;
|
708 |
+
return $this->html->outertext;
|
709 |
}
|
710 |
|
711 |
/**
|
715 |
* @since 0.3.5
|
716 |
*/
|
717 |
function get_phrases_list($string) {
|
718 |
+
$result = array();
|
719 |
+
// create our dom
|
720 |
+
$this->html = str_get_html($string);
|
721 |
+
// mark translateable elements
|
722 |
+
$this->translate_tagging($this->html->root);
|
723 |
+
foreach ($this->html->nodes as $ep) {
|
724 |
+
if ($ep->tag == 'phrase') {
|
725 |
+
$result[$ep->phrase] = $ep->phrase;
|
726 |
+
}
|
727 |
+
}
|
728 |
+
return $result;
|
729 |
}
|
730 |
+
|
731 |
}
|
732 |
?>
|
core/utils.php
CHANGED
@@ -1,77 +1,78 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*/
|
18 |
|
19 |
/**
|
20 |
*
|
21 |
* Contains utility functions which are shared across the plugin.
|
22 |
*
|
23 |
*/
|
24 |
-
|
25 |
require_once("constants.php");
|
26 |
|
27 |
|
28 |
-
|
29 |
* Remove from url any language (or editing) params that were added for our use.
|
30 |
* Return the scrubed url
|
31 |
-
*/
|
32 |
function cleanup_url($url, $home_url, $remove_host = false) {
|
33 |
|
34 |
$parsedurl = @parse_url($url);
|
35 |
//cleanup previous lang & edit parameter from url
|
36 |
|
37 |
if (isset($parsedurl['query'])) {
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
}
|
44 |
// clean the query
|
45 |
unset($parsedurl['query']);
|
46 |
-
if(isset($params) && $params) {
|
47 |
-
|
48 |
}
|
49 |
|
50 |
//cleanup lang identifier in permalinks
|
51 |
//remove the language from the url permalink (if in start of path, and is a defined language)
|
52 |
-
$home_path = rtrim(parse_url($home_url,PHP_URL_PATH),"/");
|
53 |
|
54 |
if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
}
|
59 |
|
60 |
if (strlen($parsedurl['path']) > 2) {
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
}
|
69 |
-
if ($gluebackhome) $parsedurl['path'] = $home_path
|
70 |
if ($remove_host) {
|
71 |
-
|
72 |
-
|
73 |
}
|
74 |
$url = glue_url($parsedurl);
|
|
|
75 |
return $url;
|
76 |
}
|
77 |
|
@@ -84,7 +85,7 @@ function cleanup_url($url, $home_url, $remove_host = false) {
|
|
84 |
*/
|
85 |
// Should send a transposh interface to here TODO - enable permalinks rewrite
|
86 |
// TODO - Should be able to not write default language for url (done with empty lang?)
|
87 |
-
function rewrite_url_lang_param($url
|
88 |
|
89 |
|
90 |
$newurl = str_replace('&', '&', $url);
|
@@ -92,70 +93,68 @@ function rewrite_url_lang_param($url,$home_url, $enable_permalinks_rewrite, $lan
|
|
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 |
-
|
97 |
}
|
98 |
|
99 |
//remove prev lang and edit params - from query string - reserve other params
|
100 |
if (isset($parsedurl['query'])) {
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
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 |
-
|
116 |
-
|
117 |
}
|
118 |
if (strlen($parsedurl['path']) > 2) {
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
}
|
127 |
|
128 |
-
//override the use only params - admin configured system to not touch permalinks
|
129 |
-
if(!$enable_permalinks_rewrite) {
|
130 |
-
|
131 |
}
|
132 |
|
133 |
//$params ="";
|
134 |
-
if($is_edit) {
|
135 |
-
|
136 |
}
|
137 |
|
138 |
-
if($use_params_only && $lang) {
|
139 |
-
|
140 |
-
}
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
}
|
146 |
}
|
147 |
-
if ($gluebackhome) $parsedurl['path'] = $home_path
|
148 |
|
149 |
-
//insert params to url
|
150 |
-
if(isset($params) && $params) {
|
151 |
-
|
152 |
-
|
153 |
}
|
154 |
|
155 |
// more cleanups
|
156 |
//$url = preg_replace("/&$/", "", $url);
|
157 |
//$url = preg_replace("/\?$/", "", $url);
|
158 |
-
|
159 |
// $url = htmlentities($url, ENT_NOQUOTES);
|
160 |
$url = glue_url($parsedurl);
|
161 |
|
@@ -168,36 +167,35 @@ function get_language_from_url($url, $home_url) {
|
|
168 |
|
169 |
//option 1, lanaguage is in the query ?lang=xx
|
170 |
if (isset($parsedurl['query'])) {
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
}
|
179 |
|
180 |
-
//option 2, language is in permalink
|
181 |
-
|
182 |
-
//
|
183 |
-
|
184 |
-
$home_path = rtrim(parse_url($home_url,PHP_URL_PATH),"/");
|
185 |
//
|
186 |
if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
|
187 |
//
|
188 |
-
|
189 |
// $gluebackhome = true;
|
190 |
}
|
191 |
|
192 |
if (strlen($parsedurl['path']) > 2) {
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
}
|
202 |
return false;
|
203 |
}
|
@@ -209,24 +207,25 @@ function get_language_from_url($url, $home_url) {
|
|
209 |
*/
|
210 |
function glue_url($parsed) {
|
211 |
if (!is_array($parsed)) {
|
212 |
-
|
213 |
}
|
214 |
|
215 |
-
$uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : '';
|
216 |
-
$uri .= isset($parsed['user']) ? $parsed['user'].(isset($parsed['pass']) ? ':'
|
217 |
$uri .= isset($parsed['host']) ? $parsed['host'] : '';
|
218 |
-
$uri .= isset($parsed['port']) ? ':'
|
219 |
|
220 |
if (isset($parsed['path'])) {
|
221 |
-
|
222 |
-
|
223 |
}
|
224 |
|
225 |
-
$uri .= isset($parsed['query']) ? '?'
|
226 |
-
$uri .= isset($parsed['fragment']) ? '#'
|
227 |
|
228 |
return $uri;
|
229 |
}
|
|
|
230 |
/**
|
231 |
* Encode a string as base 64 while avoiding characters which should be avoided
|
232 |
* in uri, e.g. + is interpeted as a space.
|
@@ -251,32 +250,28 @@ function base64_url_decode($input) {
|
|
251 |
* @param function $fetch_translation_func
|
252 |
* @return string translated url permalink
|
253 |
*/
|
254 |
-
function translate_url($href, $home_url, $target_language
|
255 |
// todo - check query part... sanitize
|
256 |
-
if (strpos($href,'?') !== false) {
|
257 |
-
|
258 |
-
|
259 |
}
|
260 |
-
$href = substr($href,strlen($home_url));
|
261 |
$parts = explode('/', $href);
|
262 |
foreach ($parts as $part) {
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
else
|
274 |
-
$url .= '/'.$part;
|
275 |
-
}
|
276 |
}
|
277 |
-
if (substr($href,strlen($href)-1) == '/')
|
278 |
-
|
279 |
-
return $home_url.$url.$querypart;
|
280 |
}
|
281 |
|
282 |
/**
|
@@ -287,29 +282,28 @@ function translate_url($href, $home_url, $target_language,$fetch_translation_fun
|
|
287 |
* @param function $fetch_translation_func
|
288 |
* @return string
|
289 |
*/
|
290 |
-
function get_original_url($href, $home_url, $target_language
|
291 |
-
$href = substr($href,strlen($home_url));
|
292 |
$url = urldecode($href);
|
293 |
-
$url = (($pos=strpos($url, '?')) ? substr($url, 0, $pos) : $url);
|
294 |
$parts = explode('/', $url);
|
295 |
foreach ($parts as $part) {
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
}
|
313 |
}
|
314 |
// TODO: Consider sanitize_title_with_dashes
|
315 |
// TODO : need to handle params....
|
@@ -318,9 +312,8 @@ function get_original_url($href, $home_url, $target_language,$fetch_translation_
|
|
318 |
//$url2 = rtrim($url2,'/');
|
319 |
//
|
320 |
//$href = $this->home_url.$url2;
|
321 |
-
if (substr($href,strlen($href)-1) == '/')
|
322 |
-
|
323 |
-
return $home_url.$url2;
|
324 |
}
|
325 |
|
326 |
/**
|
@@ -331,11 +324,11 @@ function get_original_url($href, $home_url, $target_language,$fetch_translation_
|
|
331 |
* @param boolean $css using css code?
|
332 |
* @return string Html with flag
|
333 |
*/
|
334 |
-
function display_flag
|
335 |
if (!$css) {
|
336 |
-
|
337 |
} else {
|
338 |
-
|
339 |
}
|
340 |
}
|
341 |
|
@@ -347,9 +340,10 @@ function display_flag ($path, $flag, $language, $css = false) {
|
|
347 |
* @param string $http_accept_language a HTTP_ACCEPT_LANGUAGE string (read from $_SERVER['HTTP_ACCEPT_LANGUAGE'] if left out)
|
348 |
* @return string
|
349 |
*/
|
350 |
-
function prefered_language
|
351 |
// if $http_accept_language was left out, read it from the HTTP-Header
|
352 |
-
if ($http_accept_language == "auto")
|
|
|
353 |
|
354 |
// standard for HTTP_ACCEPT_LANGUAGE is defined under
|
355 |
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
|
@@ -360,36 +354,36 @@ function prefered_language ($available_languages,$default_lang="auto",$http_acce
|
|
360 |
// qvalue = ( "0" [ "." 0*3DIGIT ] )
|
361 |
// | ( "1" [ "." 0*3("0") ] )
|
362 |
preg_match_all("/([[:alpha:]]{1,8})(-([[:alpha:]|-]{1,8}))?" .
|
363 |
-
|
364 |
-
|
365 |
|
366 |
// default language (in case of no hits) is the first in the array
|
367 |
-
if ($default_lang=='auto') $bestlang = $available_languages[0]; else
|
|
|
368 |
$bestqval = 0;
|
369 |
|
370 |
foreach ($hits as $arr) {
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
}
|
392 |
return $bestlang;
|
393 |
}
|
394 |
-
|
395 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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 utility functions which are shared across the plugin.
|
23 |
*
|
24 |
*/
|
|
|
25 |
require_once("constants.php");
|
26 |
|
27 |
|
28 |
+
/**
|
29 |
* Remove from url any language (or editing) params that were added for our use.
|
30 |
* Return the scrubed url
|
31 |
+
*/
|
32 |
function cleanup_url($url, $home_url, $remove_host = false) {
|
33 |
|
34 |
$parsedurl = @parse_url($url);
|
35 |
//cleanup previous lang & edit parameter from url
|
36 |
|
37 |
if (isset($parsedurl['query'])) {
|
38 |
+
$params = explode('&', $parsedurl['query']);
|
39 |
+
foreach ($params as $key => $param) {
|
40 |
+
if (stripos($param, LANG_PARAM) === 0) unset($params[$key]);
|
41 |
+
if (stripos($param, EDIT_PARAM) === 0) unset($params[$key]);
|
42 |
+
}
|
43 |
}
|
44 |
// clean the query
|
45 |
unset($parsedurl['query']);
|
46 |
+
if (isset($params) && $params) {
|
47 |
+
$parsedurl['query'] = implode('&', $params);
|
48 |
}
|
49 |
|
50 |
//cleanup lang identifier in permalinks
|
51 |
//remove the language from the url permalink (if in start of path, and is a defined language)
|
52 |
+
$home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/");
|
53 |
|
54 |
if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
|
55 |
+
|
56 |
+
$parsedurl['path'] = substr($parsedurl['path'], strlen($home_path));
|
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'], $secondslashpos);
|
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 |
|
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 |
$newurl = str_replace('&', '&', $url);
|
93 |
$parsedurl = parse_url($newurl);
|
94 |
|
95 |
// if we are dealing with some other url, we won't touch it!
|
96 |
+
if (isset($parsedurl['host']) && !($parsedurl['host'] == parse_url($home_url, PHP_URL_HOST))) {
|
97 |
+
return $url;
|
98 |
}
|
99 |
|
100 |
//remove prev lang and edit params - from query string - reserve other params
|
101 |
if (isset($parsedurl['query'])) {
|
102 |
+
$params = explode('&', $parsedurl['query']);
|
103 |
+
foreach ($params as $key => $param) {
|
104 |
+
if (stripos($param, LANG_PARAM) === 0) unset($params[$key]);
|
105 |
+
if (stripos($param, EDIT_PARAM) === 0) unset($params[$key]);
|
106 |
+
}
|
107 |
}
|
108 |
// clean the query
|
109 |
unset($parsedurl['query']);
|
110 |
|
111 |
+
// remove the language from the url permalink (if in start of path, and is a defined language)
|
112 |
+
$home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/");
|
113 |
|
114 |
if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
|
115 |
+
|
116 |
+
$parsedurl['path'] = substr($parsedurl['path'], strlen($home_path));
|
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'], $secondslashpos);
|
126 |
+
}
|
127 |
}
|
128 |
|
129 |
+
// override the use only params - admin configured system to not touch permalinks
|
130 |
+
if (!$enable_permalinks_rewrite) {
|
131 |
+
$use_params_only = TRUE;
|
132 |
}
|
133 |
|
134 |
//$params ="";
|
135 |
+
if ($is_edit) {
|
136 |
+
$params[edit] = EDIT_PARAM . '=1';
|
137 |
}
|
138 |
|
139 |
+
if ($use_params_only && $lang) {
|
140 |
+
$params['lang'] = LANG_PARAM . "=$lang";
|
141 |
+
} else {
|
142 |
+
if ($lang) {
|
143 |
+
if (!$parsedurl['path']) $parsedurl['path'] = "/";
|
144 |
+
$parsedurl['path'] = "/" . $lang . $parsedurl['path'];
|
145 |
+
}
|
|
|
146 |
}
|
147 |
+
if ($gluebackhome) $parsedurl['path'] = $home_path . $parsedurl['path'];
|
148 |
|
149 |
+
// insert params to url
|
150 |
+
if (isset($params) && $params) {
|
151 |
+
$parsedurl['query'] = implode('&', $params);
|
152 |
+
|
153 |
}
|
154 |
|
155 |
// more cleanups
|
156 |
//$url = preg_replace("/&$/", "", $url);
|
157 |
//$url = preg_replace("/\?$/", "", $url);
|
|
|
158 |
// $url = htmlentities($url, ENT_NOQUOTES);
|
159 |
$url = glue_url($parsedurl);
|
160 |
|
167 |
|
168 |
//option 1, lanaguage is in the query ?lang=xx
|
169 |
if (isset($parsedurl['query'])) {
|
170 |
+
$params = explode('&', $parsedurl['query']);
|
171 |
+
foreach ($params as $key => $param) {
|
172 |
+
if (stripos($param, LANG_PARAM) === 0) {
|
173 |
+
$langa = explode("=", $params[$key]);
|
174 |
+
return ($langa[1]);
|
175 |
+
}
|
176 |
+
}
|
177 |
}
|
178 |
|
179 |
+
// option 2, language is in permalink
|
180 |
+
// cleanup lang identifier in permalinks
|
181 |
+
// remove the language from the url permalink (if in start of path, and is a defined language)
|
182 |
+
$home_path = rtrim(parse_url($home_url, PHP_URL_PATH), "/");
|
|
|
183 |
//
|
184 |
if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
|
185 |
//
|
186 |
+
$parsedurl['path'] = substr($parsedurl['path'], strlen($home_path));
|
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 |
}
|
207 |
*/
|
208 |
function glue_url($parsed) {
|
209 |
if (!is_array($parsed)) {
|
210 |
+
return false;
|
211 |
}
|
212 |
|
213 |
+
$uri = isset($parsed['scheme']) ? $parsed['scheme'] . ':' . ((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : '';
|
214 |
+
$uri .= isset($parsed['user']) ? $parsed['user'] . (isset($parsed['pass']) ? ':' . $parsed['pass'] : '') . '@' : '';
|
215 |
$uri .= isset($parsed['host']) ? $parsed['host'] : '';
|
216 |
+
$uri .= isset($parsed['port']) ? ':' . $parsed['port'] : '';
|
217 |
|
218 |
if (isset($parsed['path'])) {
|
219 |
+
$uri .= ( substr($parsed['path'], 0, 1) == '/') ?
|
220 |
+
$parsed['path'] : ((!empty($uri) ? '/' : '' ) . $parsed['path']);
|
221 |
}
|
222 |
|
223 |
+
$uri .= isset($parsed['query']) ? '?' . $parsed['query'] : '';
|
224 |
+
$uri .= isset($parsed['fragment']) ? '#' . $parsed['fragment'] : '';
|
225 |
|
226 |
return $uri;
|
227 |
}
|
228 |
+
|
229 |
/**
|
230 |
* Encode a string as base 64 while avoiding characters which should be avoided
|
231 |
* in uri, e.g. + is interpeted as a space.
|
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 |
+
$href = substr($href, strlen($home_url));
|
260 |
$parts = explode('/', $href);
|
261 |
foreach ($parts as $part) {
|
262 |
+
if (!$part) continue;
|
263 |
+
list($translated_text, $old_source) = call_user_func_array($fetch_translation_func, array($part, $target_language));
|
264 |
+
if ($translated_text) $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) $url .= '/' . str_replace(' ', '-', $translated_text);
|
270 |
+
else $url .= '/' . $part;
|
271 |
+
}
|
|
|
|
|
|
|
272 |
}
|
273 |
+
if (substr($href, strlen($href) - 1) == '/') $url.='/';
|
274 |
+
return $home_url . $url . $querypart;
|
|
|
275 |
}
|
276 |
|
277 |
/**
|
282 |
* @param function $fetch_translation_func
|
283 |
* @return string
|
284 |
*/
|
285 |
+
function get_original_url($href, $home_url, $target_language, $fetch_translation_func) {
|
286 |
+
$href = substr($href, strlen($home_url));
|
287 |
$url = urldecode($href);
|
288 |
+
$url = (($pos = strpos($url, '?')) ? substr($url, 0, $pos) : $url);
|
289 |
$parts = explode('/', $url);
|
290 |
foreach ($parts as $part) {
|
291 |
+
if (!$part) continue;
|
292 |
+
// don't attempt for lang or numbers
|
293 |
+
if ($part == $target_language || is_numeric($part)) {
|
294 |
+
$url2 .= '/' . $part;
|
295 |
+
continue;
|
296 |
+
}
|
297 |
+
|
298 |
+
$original_text = call_user_func_array($fetch_translation_func, array($part, $target_language));
|
299 |
+
if ($original_text)
|
300 |
+
$url2 .= '/' . strtolower(str_replace(' ', '-', $original_text)); //? CHECK
|
301 |
+
else {
|
302 |
+
$original_text = call_user_func_array($fetch_translation_func, array(str_replace('-', ' ', $part), $target_language));
|
303 |
+
if ($original_text)
|
304 |
+
$url2 .= '/' . strtolower(str_replace(' ', '-', $original_text)); //? CHECK
|
305 |
+
else $url2 .= '/' . $part;
|
306 |
+
}
|
|
|
307 |
}
|
308 |
// TODO: Consider sanitize_title_with_dashes
|
309 |
// TODO : need to handle params....
|
312 |
//$url2 = rtrim($url2,'/');
|
313 |
//
|
314 |
//$href = $this->home_url.$url2;
|
315 |
+
if (substr($href, strlen($href) - 1) == '/') $url2.='/';
|
316 |
+
return $home_url . $url2;
|
|
|
317 |
}
|
318 |
|
319 |
/**
|
324 |
* @param boolean $css using css code?
|
325 |
* @return string Html with flag
|
326 |
*/
|
327 |
+
function display_flag($path, $flag, $language, $css = false) {
|
328 |
if (!$css) {
|
329 |
+
return "<img src=\"$path/$flag.png\" title=\"$language\" alt=\"$language\"/>";
|
330 |
} else {
|
331 |
+
return "<span title=\"$language\" class=\"trf trf-{$flag}\"></span>";
|
332 |
}
|
333 |
}
|
334 |
|
340 |
* @param string $http_accept_language a HTTP_ACCEPT_LANGUAGE string (read from $_SERVER['HTTP_ACCEPT_LANGUAGE'] if left out)
|
341 |
* @return string
|
342 |
*/
|
343 |
+
function prefered_language($available_languages, $default_lang="auto", $http_accept_language="auto") {
|
344 |
// if $http_accept_language was left out, read it from the HTTP-Header
|
345 |
+
if ($http_accept_language == "auto")
|
346 |
+
$http_accept_language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
347 |
|
348 |
// standard for HTTP_ACCEPT_LANGUAGE is defined under
|
349 |
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
|
354 |
// qvalue = ( "0" [ "." 0*3DIGIT ] )
|
355 |
// | ( "1" [ "." 0*3("0") ] )
|
356 |
preg_match_all("/([[:alpha:]]{1,8})(-([[:alpha:]|-]{1,8}))?" .
|
357 |
+
"(\s*;\s*q\s*=\s*(1\.0{0,3}|0\.\d{0,3}))?\s*(,|$)/i",
|
358 |
+
$http_accept_language, $hits, PREG_SET_ORDER);
|
359 |
|
360 |
// default language (in case of no hits) is the first in the array
|
361 |
+
if ($default_lang == 'auto') $bestlang = $available_languages[0]; else
|
362 |
+
$bestlang = $default_lang;
|
363 |
$bestqval = 0;
|
364 |
|
365 |
foreach ($hits as $arr) {
|
366 |
+
// read data from the array of this hit
|
367 |
+
$langprefix = strtolower($arr[1]);
|
368 |
+
if (!empty($arr[3])) {
|
369 |
+
$langrange = strtolower($arr[3]);
|
370 |
+
$language = $langprefix . "-" . $langrange;
|
371 |
+
}
|
372 |
+
else $language = $langprefix;
|
373 |
+
$qvalue = 1.0;
|
374 |
+
if (!empty($arr[5])) $qvalue = floatval($arr[5]);
|
375 |
+
|
376 |
+
// find q-maximal language
|
377 |
+
if (in_array($language, $available_languages) && ($qvalue > $bestqval)) {
|
378 |
+
$bestlang = $language;
|
379 |
+
$bestqval = $qvalue;
|
380 |
+
}
|
381 |
+
// if no direct hit, try the prefix only but decrease q-value by 10% (as http_negotiate_language does)
|
382 |
+
else if (in_array($languageprefix, $available_languages) && (($qvalue * 0.9) > $bestqval)) {
|
383 |
+
$bestlang = $languageprefix;
|
384 |
+
$bestqval = $qvalue * 0.9;
|
385 |
+
}
|
386 |
}
|
387 |
return $bestlang;
|
388 |
}
|
|
|
389 |
?>
|
css/transposh_flags.css
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
.transposh_flags{direction:ltr;line-height:0;}.transposh_flags a{display:inline;}.transposh_flags a:hover{background:transparent;}.transposh_flags a span,.transposh_flags a img{border-color:transparent;border-style:solid;border-width:1px 3px;padding:0;}.transposh_flags a span:hover,.transposh_flags a img:hover{border-color:blue;}.trf{background-image:url(../img/flags53.png);height:11px;width:16px;background-repeat:no-repeat;overflow:hidden;display:inline-block;}.trf-za{background-position:-24px 0;}.trf-al{background-position:-48px 0;}.trf-sa{background-position:-72px 0;}.trf-by{background-position:-96px 0;}.trf-bg{background-position:-120px 0;}.trf-catalonia{background-position:-144px 0;}.trf-cn{background-position:-168px 0;}.trf-tw{background-position:-192px 0;}.trf-hr{background-position:-216px 0;}.trf-cz{background-position:-240px 0;}.trf-dk{background-position:-264px 0;}.trf-nl{background-position:-288px 0;}.trf-ee{background-position:-312px 0;}.trf-fi{background-position:-336px 0;}.trf-fr{background-position:-360px 0;}.trf-galicia{background-position:-384px 0;}.trf-de{background-position:-408px 0;}.trf-gr{background-position:-432px 0;}.trf-ht{background-position:-456px 0;}.trf-il{background-position:-480px 0;}.trf-in{background-position:-504px 0;}.trf-hu{background-position:-528px 0;}.trf-id{background-position:-552px 0;}.trf-it{background-position:-576px 0;}.trf-is{background-position:-600px 0;}.trf-ie{background-position:-624px 0;}.trf-jp{background-position:-648px 0;}.trf-kr{background-position:-672px 0;}.trf-lv{background-position:-696px 0;}.trf-lt{background-position:-720px 0;}.trf-mk{background-position:-744px 0;}.trf-my{background-position:-768px 0;}.trf-mt{background-position:-792px 0;}.trf-no{background-position:-816px 0;}.trf-ir{background-position:-840px 0;}.trf-pl{background-position:-864px 0;}.trf-pt{background-position:-888px 0;}.trf-ro{background-position:-912px 0;}.trf-ru{background-position:-936px 0;}.trf-rs{background-position:-960px 0;}.trf-sk{background-position:-984px 0;}.trf-sl{background-position:-1008px 0;}.trf-es{background-position:-1032px 0;}.trf-ke{background-position:-1056px 0;}.trf-se{background-position:-1080px 0;}.trf-ph{background-position:-1104px 0;}.trf-th{background-position:-1128px 0;}.trf-tr{background-position:-1152px 0;}.trf-ua{background-position:-1176px 0;}.trf-vn{background-position:-1200px 0;}.trf-wales{background-position:-1224px 0;}.trf-europeanunion{background-position:-1248px 0;}
|
|
css/transposh_widget.css
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
.transposh_flags{direction:ltr;line-height:0;}.transposh_flags a{display:inline;}.transposh_flags a:hover{background:transparent;}.transposh_flags a span,.transposh_flags a img{border-color:transparent;border-style:solid;border-width:1px 3px;padding:0;}.transposh_flags a span:hover,.transposh_flags a img:hover{border-color:blue;}
|
|
img/flags/basque.png
ADDED
Binary file
|
img/flags58.png
ADDED
Binary file
|
js/lazy.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
(function(b){function s(){function h(a,
|
2 |
-
b.each(n,function(d
|
3 |
-
e.setAttribute("type","text/javascript");e.setAttribute("src",a);e.setAttribute("id",
|
4 |
-
a+'"]').length)
|
5 |
-
|
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*="'+
|
4 |
+
a+'"]').length)c();else{var f=b('<link rel="stylesheet" type="text/css" media="all" href="'+a+'" id="'+d+'"></link>')[0];if(b.browser.msie)f.onreadystatechange=function(){/loaded|complete/.test(f.readyState)&&c()};else if(b.browser.opera)f.onload=c;else{location.hostname.replace("www.","");/http:/.test(a)&&/^(\w+:)?\/\/([^\/?#]+)/.exec(a);c()}m.appendChild(f)}};this.img=function(a,c){var d=new Image;d.onload=c;d.onerror=q;d.src=a};this.disable=function(a){b("#lazy-loaded-"+a,m).attr("disabled","disabled")};
|
5 |
+
this.enable=function(a){b("#lazy-loaded-"+a,m).removeAttr("disabled")};this.destroy=function(a){b("#lazy-loaded-"+a,m).remove()}}b.xLazyLoader=function(h,j){if(typeof h=="object"){j=h;h="init"}(new s)[h](j)};b.xLazyLoader.defaults={js:[],css:[],img:[],name:null,timeout:2E4,success:function(){},error:function(){},complete:function(){},each:function(){}};var m=document.getElementsByTagName("head")[0]})(jQuery);
|
js/transposh.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
(function(a){function w(d,c){if(a.trim(c).length!==0){var f=function(){var b=a(this).attr("id").substr(a(this).attr("id").lastIndexOf("_")+1),p=a("#"+e+"img_"+b);a("#"+e+b).attr("data-source",1);p.removeClass("tr-icon-yellow").removeClass("tr-icon-green").addClass("tr-icon-yellow")};a("*[data-token='"+d+"'][data-hidden!='y']").html(c).each(f);a("*[data-token='"+d+"'][data-hidden='y']").attr("data-trans",c).each(f)}}function l(d,c){t_jp.progress&&a("#"+d).progressbar("value",c)}function q(d,c){clearTimeout(r);
|
2 |
-
h.push(d);m.push(c);w(d,c);r=setTimeout(function(){var f={ln0:t_jp.lang,sr0:s,translation_posted:"2",items:h.length},b;for(b=0;b<h.length;b+=1){f["tk"+b]=h[b];f["tr"+b]=m[b];t+=a("*[data-token='"+h[b]+"']").size()}a.ajax({type:"POST",url:t_jp.post_url,data:f,success:function(){l(j,t/g*100)}});m=[];h=[]},200)}function
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
1 |
(function(a){function w(d,c){if(a.trim(c).length!==0){var f=function(){var b=a(this).attr("id").substr(a(this).attr("id").lastIndexOf("_")+1),p=a("#"+e+"img_"+b);a("#"+e+b).attr("data-source",1);p.removeClass("tr-icon-yellow").removeClass("tr-icon-green").addClass("tr-icon-yellow")};a("*[data-token='"+d+"'][data-hidden!='y']").html(c).each(f);a("*[data-token='"+d+"'][data-hidden='y']").attr("data-trans",c).each(f)}}function l(d,c){t_jp.progress&&a("#"+d).progressbar("value",c)}function q(d,c){clearTimeout(r);
|
2 |
+
h.push(d);m.push(c);w(d,c);r=setTimeout(function(){var f={ln0:t_jp.lang,sr0:s,translation_posted:"2",items:h.length},b;for(b=0;b<h.length;b+=1){f["tk"+b]=h[b];f["tr"+b]=m[b];t+=a("*[data-token='"+h[b]+"']").size()}a.ajax({type:"POST",url:t_jp.post_url,data:f,success:function(){l(j,t/g*100)}});m=[];h=[]},200)}function u(){var d=[],c=t_jp.lang;a("."+e+'[data-source=""]').each(function(){var f=a(this).attr("data-token"),b=a(this).attr("data-orig");if(b===undefined)b=a(this).html();if(d[b]!==1){d[b]=
|
3 |
+
1;if(typeof Microsoft!=="undefined"){if(c==="zh")c="zh-chs";else if(c==="zh-tw")c="zh-cht";try{Microsoft.Translator.translate(b,"",c,function(k){q(f,a("<div>"+k+"</div>").text());l(i,(g-a("."+e+'[data-source=""]').size())/g*100)})}catch(p){}}else google.language.translate(b,"",t_jp.lang,function(k){if(!k.error){q(f,a("<div>"+k.translation+"</div>").text());l(i,(g-a("."+e+'[data-source=""]').size())/g*100)}})}})}var n,v,o,g,e=t_jp.prefix,i=e+"pbar",j=i+"_s",s=1,t=0,r,h=[],m=[];v=function(){google.load("language",
|
4 |
+
"1",{callback:n})};a(document).ready(function(){a("#"+e+"setdeflang").click(function(){a.get(t_jp.post_url+"?tr_cookie="+Math.random());a(this).hide("slow");return false});var d;g=a("."+e+'[data-source=""]').size();d=new Date;a.ajaxSetup({cache:true});if((g>5||d.getHours()===4&&g>0)&&(t_jp.google||t_jp.msn)){n=function(){if(t_jp.progress){var c=function(){a.xLazyLoader({js:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.3/jquery-ui.min.js",css:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.3/themes/ui-lightness/jquery-ui.css",
|
5 |
+
success:function(){a("#"+e+"credit").css({overflow:"auto"}).append('<div style="float: left;width: 90%;height: 10px" id="'+i+'"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="'+j+'"/>');a("#"+i).progressbar({value:0});a("#"+j).progressbar({value:0});a("#"+j+" > div").css({background:"#28F828",border:"#08A908 1px solid"});u()}})};typeof a.xLazyLoader==="function"?c():a.getScript(t_jp.plugin_url+"/js/lazy.js",c)}else u()};if(t_jp.msn&&t_jp.preferred===2||!t_jp.google){s=2;o=
|
6 |
+
function(){a.getScript("http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId="+t_jp.msnkey,n)};t_jp.edit&&t_jp.progress?a.getScript(t_jp.plugin_url+"/js/lazy.js",o):o()}else a.getScript("http://www.google.com/jsapi",v)}t_jp.edit&&a.getScript(t_jp.plugin_url+"/js/transposhedit.js")})})(jQuery);
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://transposh.org/donate/
|
|
4 |
Tags: translation, widget, filter, bilingual, multilingual, transposh, translate, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
|
5 |
Requires at least: 2.7
|
6 |
Tested up to: 3.0
|
7 |
-
Stable tag: 0.5.
|
8 |
|
9 |
Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
|
10 |
|
@@ -179,19 +179,25 @@ This version provides integration with google-sitemaps-xml and wp-super-cache
|
|
179 |
This version allows sorting of languages within the widget
|
180 |
|
181 |
== Changelog ==
|
182 |
-
|
183 |
-
*
|
184 |
-
*
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
* Fix some issues with the widget regarding url translation
|
187 |
* Fix some inclusion issue with transposh_ajax.php file
|
188 |
-
|
189 |
* Support translation of URLs
|
190 |
* Mark language used to comment
|
191 |
* Improved wp-super-cache integration
|
192 |
* Fixed issues with widget generating urls containing default language
|
193 |
* Upgrade jQueryUI to 1.7.3
|
194 |
-
|
195 |
* support the google notranslate class notation (as an addition to no_translate)
|
196 |
* support for lang tagging on paragraphs
|
197 |
* changed translation of default language to just translate paragraphs explicitly marked with a different language
|
4 |
Tags: translation, widget, filter, bilingual, multilingual, transposh, translate, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
|
5 |
Requires at least: 2.7
|
6 |
Tested up to: 3.0
|
7 |
+
Stable tag: 0.5.6
|
8 |
|
9 |
Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
|
10 |
|
179 |
This version allows sorting of languages within the widget
|
180 |
|
181 |
== Changelog ==
|
182 |
+
= 2010/07/11 - 0.5.6 =
|
183 |
+
* Pluggable widgets - read all about them on http://trac.transposh.org/wiki/WidgetWritingGuide
|
184 |
+
* Avoid translation of trashed and draft post on translate all
|
185 |
+
* Fix MSN as default translator and add two new languages to the list of supported languages
|
186 |
+
* Fix bug with problematic !@require
|
187 |
+
* Code cleanups
|
188 |
+
= 2010/06/18 - 0.5.5 =
|
189 |
+
* Add support for buddypress URLs
|
190 |
+
* Fix UI issues when jQuery tools were used on the page
|
191 |
+
= 2010/06/06 - 0.5.4 =
|
192 |
* Fix some issues with the widget regarding url translation
|
193 |
* Fix some inclusion issue with transposh_ajax.php file
|
194 |
+
= 2010/05/30 - 0.5.3 =
|
195 |
* Support translation of URLs
|
196 |
* Mark language used to comment
|
197 |
* Improved wp-super-cache integration
|
198 |
* Fixed issues with widget generating urls containing default language
|
199 |
* Upgrade jQueryUI to 1.7.3
|
200 |
+
= 2010/04/11 - 0.5.2 =
|
201 |
* support the google notranslate class notation (as an addition to no_translate)
|
202 |
* support for lang tagging on paragraphs
|
203 |
* changed translation of default language to just translate paragraphs explicitly marked with a different language
|
transposh.php
CHANGED
@@ -1,33 +1,34 @@
|
|
1 |
<?php
|
|
|
2 |
/*
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
*/
|
11 |
|
12 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*
|
18 |
*
|
19 |
-
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
*
|
24 |
-
*
|
25 |
-
*
|
26 |
-
*
|
27 |
-
*/
|
28 |
|
29 |
//avoid direct calls to this file where wp core files not present
|
30 |
-
if (!function_exists
|
31 |
header('Status: 403 Forbidden');
|
32 |
header('HTTP/1.1 403 Forbidden');
|
33 |
exit();
|
@@ -50,86 +51,91 @@ require_once("wp/transposh_backup.php");
|
|
50 |
*/
|
51 |
class transposh_plugin {
|
52 |
// List of contained objects
|
53 |
-
|
|
|
54 |
public $options;
|
55 |
-
/** @var transposh_plugin_admin Admin page*/
|
56 |
private $admin;
|
57 |
-
/** @var transposh_plugin_widget Widget control*/
|
58 |
public $widget;
|
59 |
-
/** @var transposh_database The database class*/
|
60 |
public $database;
|
61 |
-
/** @var transposh_postpublish Happens after editing*/
|
62 |
public $postpublish;
|
63 |
|
64 |
// list of properties
|
65 |
-
/** @var string The site url*/
|
66 |
public $home_url;
|
67 |
-
/** @var string Where the javascript should post to*/
|
68 |
public $post_url;
|
69 |
-
/** @var string The url to the plugin directory*/
|
70 |
public $transposh_plugin_url;
|
71 |
-
/** @var
|
|
|
|
|
72 |
public $enable_permalinks_rewrite;
|
73 |
-
/** @var string The language to translate the page to*/
|
74 |
public $target_language;
|
75 |
-
/** @var boolean Are we currently editing the page
|
76 |
public $edit_mode;
|
77 |
-
/** @var string Error message displayed for the admin in case of failure*/
|
78 |
private $admin_msg;
|
79 |
-
/** @var string Saved search variables*/
|
80 |
private $search_s;
|
81 |
|
82 |
/**
|
83 |
* class constructor
|
84 |
*/
|
85 |
function transposh_plugin() {
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
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 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
124 |
// add_action('wp_head', array(&$this,'add_transposh_async'));
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
}
|
134 |
|
135 |
/**
|
@@ -138,9 +144,9 @@ class transposh_plugin {
|
|
138 |
* @return boolean Is it a special page?
|
139 |
*/
|
140 |
function is_special_page($url) {
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
}
|
145 |
|
146 |
/**
|
@@ -150,49 +156,48 @@ class transposh_plugin {
|
|
150 |
*/
|
151 |
function process_page(&$buffer) {
|
152 |
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
return $buffer;
|
196 |
}
|
197 |
|
198 |
/**
|
@@ -200,24 +205,25 @@ class transposh_plugin {
|
|
200 |
* Once processing is completed the buffer will go into the translation process.
|
201 |
*/
|
202 |
function on_init() {
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
214 |
}
|
215 |
|
216 |
/**
|
217 |
* Page generation completed - flush buffer.
|
218 |
*/
|
219 |
function on_shutdown() {
|
220 |
-
|
221 |
}
|
222 |
|
223 |
/**
|
@@ -226,47 +232,47 @@ class transposh_plugin {
|
|
226 |
* @return array New rewrite rules
|
227 |
*/
|
228 |
function update_rewrite_rules($rules) {
|
229 |
-
|
230 |
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
|
236 |
-
|
237 |
-
|
238 |
|
239 |
-
|
240 |
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
|
249 |
-
|
250 |
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
|
257 |
-
|
258 |
|
259 |
-
|
260 |
|
261 |
|
262 |
-
|
263 |
-
|
264 |
|
265 |
-
|
266 |
-
|
267 |
|
268 |
-
|
269 |
-
|
270 |
}
|
271 |
|
272 |
/**
|
@@ -275,11 +281,11 @@ class transposh_plugin {
|
|
275 |
* @return array Modified array
|
276 |
*/
|
277 |
function parameter_queryvars($vars) {
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
}
|
284 |
|
285 |
/**
|
@@ -287,138 +293,141 @@ class transposh_plugin {
|
|
287 |
* @param WP $wp - here we get the WP class
|
288 |
*/
|
289 |
function on_parse_request($wp) {
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
|
|
|
|
|
|
356 |
}
|
357 |
|
358 |
// TODO ? move to options?
|
|
|
359 |
/**
|
360 |
* Determine if the current user is allowed to translate.
|
361 |
* @return boolean Is allowed to translate?
|
362 |
*/
|
363 |
function is_translator() {
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
}
|
373 |
|
374 |
/**
|
375 |
* Plugin activation
|
376 |
*/
|
377 |
function plugin_activate() {
|
378 |
-
|
379 |
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
}
|
390 |
|
391 |
/**
|
392 |
* Plugin deactivation
|
393 |
*/
|
394 |
function plugin_deactivate() {
|
395 |
-
|
396 |
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
|
401 |
-
|
402 |
}
|
403 |
|
404 |
/**
|
405 |
* Callback from admin_notices - display error message to the admin.
|
406 |
*/
|
407 |
function plugin_install_error() {
|
408 |
-
|
409 |
|
410 |
-
|
411 |
-
|
|
|
412 |
|
413 |
-
|
|
|
|
|
|
|
|
|
414 |
|
415 |
-
|
416 |
-
// FIXME :wtf?
|
417 |
-
deactivate_plugins(array(&$this,'get_plugin_name'), "translate.php");
|
418 |
-
echo '<br> This plugin has been automatically deactivated.';
|
419 |
-
}
|
420 |
-
|
421 |
-
echo '</p></div>';
|
422 |
}
|
423 |
|
424 |
/**
|
@@ -428,30 +437,30 @@ class transposh_plugin {
|
|
428 |
* TODO - needs revisiting!
|
429 |
*/
|
430 |
function plugin_loaded() {
|
431 |
-
|
432 |
|
433 |
-
|
434 |
-
|
435 |
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
|
445 |
-
|
446 |
-
|
447 |
|
448 |
-
|
449 |
-
|
450 |
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
}
|
456 |
|
457 |
/**
|
@@ -462,101 +471,58 @@ class transposh_plugin {
|
|
462 |
* @return string
|
463 |
*/
|
464 |
function get_plugin_name() {
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
return $file;
|
473 |
}
|
474 |
|
475 |
/**
|
476 |
* Add custom css, i.e. transposh.css
|
477 |
*/
|
478 |
function add_transposh_css() {
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
}
|
491 |
|
492 |
/**
|
493 |
* Insert references to the javascript files used in the translated version of the page.
|
494 |
*/
|
495 |
function add_transposh_js() {
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
// those two options show if the script can support said engines
|
515 |
-
'msn' => (in_array($this->target_language,$GLOBALS['bing_languages']) && $this->options->get_msn_key() ? '1' : ''),
|
516 |
-
'google' => (in_array($this->target_language,$GLOBALS['google_languages']) ? '1' : ''),
|
517 |
-
'prefix' => SPAN_PREFIX,
|
518 |
-
'msnkey'=>$this->options->get_msn_key(),
|
519 |
-
'preferred'=> $this->options->get_preferred_translator(),
|
520 |
-
'progress'=>$this->edit_mode || $this->options->get_widget_progressbar() ? '1' : '')
|
521 |
// 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
|
522 |
-
|
523 |
-
|
524 |
-
// toying around - for later...
|
525 |
-
// wp_enqueue_script("jquery","http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js",array(),'1.4.1');
|
526 |
-
}
|
527 |
}
|
528 |
|
529 |
-
/**
|
530 |
-
* Inserts the transposh async loading in the head.
|
531 |
-
* @return nothing
|
532 |
-
*/
|
533 |
-
// lost in compatability
|
534 |
-
/* function add_transposh_async() {
|
535 |
-
if (!$this->edit_mode && !$this->is_auto_translate_permitted()) {
|
536 |
-
return;
|
537 |
-
}
|
538 |
-
|
539 |
-
echo "<script type=\"text/javascript\">";
|
540 |
-
echo "var t_jp=t_jp || [];";
|
541 |
-
echo "t_jp.post_url='{$this->post_url}';";
|
542 |
-
echo "t_jp.plugin_url='{$this->transposh_plugin_url}';";
|
543 |
-
echo "t_jp.edit=".($this->edit_mode? 'true' : 'false').";";
|
544 |
-
//echo "t_jp.rtl=".(in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : 'false').";";
|
545 |
-
echo "t_jp.lang='{$this->target_language}';";
|
546 |
-
// those two options show if the script can support said engines
|
547 |
-
echo "t_jp.msn=".(in_array($this->target_language,$GLOBALS['bing_languages']) && $this->options->get_msn_key() ? 'true' : 'false').";";
|
548 |
-
echo "t_jp.google=".(in_array($this->target_language,$GLOBALS['google_languages']) ? 'true' : 'false').";";
|
549 |
-
echo "t_jp.prefix='".SPAN_PREFIX."';";
|
550 |
-
echo "t_jp.msnkey='{$this->options->get_msn_key()}';";
|
551 |
-
echo "t_jp.preferred='{$this->options->get_preferred_translator()}';";
|
552 |
-
echo "t_jp.progress=".($this->edit_mode || $this->options->get_widget_progressbar() ? 'true' : 'false').";";
|
553 |
-
|
554 |
-
echo "var tp = document.createElement('script'); tp.type = 'text/javascript'; tp.async = true;";
|
555 |
-
echo "tp.src = '{$this->transposh_plugin_url}/js/transposh.js?ver=".TRANSPOSH_PLUGIN_VER."';";
|
556 |
-
echo "(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(tp);";
|
557 |
-
echo"</script>";
|
558 |
-
}*/
|
559 |
-
|
560 |
/**
|
561 |
* Determine if the currently selected language (taken from the query parameters) is in the admin's list
|
562 |
* of editable languages and the current user is allowed to translate.
|
@@ -564,12 +530,13 @@ class transposh_plugin {
|
|
564 |
*/
|
565 |
// TODO????
|
566 |
function is_editing_permitted() {
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
|
|
571 |
|
572 |
-
|
573 |
}
|
574 |
|
575 |
/**
|
@@ -577,15 +544,17 @@ class transposh_plugin {
|
|
577 |
* of editable languages and that automatic translation has been enabled.
|
578 |
* Note that any user can auto translate. i.e. ignore permissions.
|
579 |
* @return boolean Is automatic translation allowed?
|
|
|
580 |
*/
|
581 |
function is_auto_translate_permitted() {
|
582 |
-
|
583 |
|
584 |
-
|
585 |
-
|
586 |
-
|
|
|
587 |
|
588 |
-
|
589 |
}
|
590 |
|
591 |
/**
|
@@ -596,32 +565,32 @@ class transposh_plugin {
|
|
596 |
* @return boolean Modified href
|
597 |
*/
|
598 |
function rewrite_url($href) {
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
}
|
626 |
|
627 |
/**
|
@@ -629,23 +598,23 @@ class transposh_plugin {
|
|
629 |
* @param array $links Links that appear next to the plugin
|
630 |
* @return array Now with settings
|
631 |
*/
|
632 |
-
function plugin_action_links(
|
633 |
-
|
634 |
-
|
635 |
}
|
636 |
|
637 |
/**
|
638 |
* We use this to "steal" the search variables
|
639 |
* @param WP_Query $query
|
640 |
*/
|
641 |
-
function pre_post_search
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
}
|
650 |
|
651 |
/**
|
@@ -653,50 +622,50 @@ class transposh_plugin {
|
|
653 |
* @param string $where Original where clause for getting posts
|
654 |
* @return string Modified where
|
655 |
*/
|
656 |
-
function posts_where_request
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
}
|
701 |
|
702 |
/**
|
@@ -707,34 +676,34 @@ class transposh_plugin {
|
|
707 |
* @param GoogleSitemapGeneratorPage $sm_page Object containing the page information
|
708 |
*/
|
709 |
function add_sm_transposh_urls(&$sm_page) {
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
}
|
730 |
|
731 |
/**
|
732 |
* Runs a scheduled backup
|
733 |
*/
|
734 |
function run_backup() {
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
}
|
739 |
|
740 |
/**
|
@@ -743,8 +712,8 @@ class transposh_plugin {
|
|
743 |
* @param int $post_id
|
744 |
*/
|
745 |
function add_comment_meta_settings($post_id) {
|
746 |
-
|
747 |
-
|
748 |
}
|
749 |
|
750 |
/**
|
@@ -753,12 +722,12 @@ class transposh_plugin {
|
|
753 |
* @return string The url that buddypress should see
|
754 |
*/
|
755 |
function bp_uri_filter($uri) {
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
}
|
763 |
|
764 |
/**
|
@@ -767,12 +736,12 @@ class transposh_plugin {
|
|
767 |
* @return string
|
768 |
*/
|
769 |
function comment_text_wrap($text) {
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
}
|
777 |
|
778 |
/**
|
@@ -782,24 +751,23 @@ class transposh_plugin {
|
|
782 |
* @return <type>
|
783 |
*/
|
784 |
function request_filter($query) {
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
}
|
800 |
|
801 |
}
|
802 |
|
803 |
$my_transposh_plugin = new transposh_plugin();
|
804 |
-
|
805 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/*
|
4 |
+
Plugin Name: Transposh Translation Filter
|
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.5.6
|
9 |
+
Author URI: http://transposh.org/
|
10 |
+
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
+
*/
|
12 |
|
13 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
14 |
*
|
15 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* This program is distributed in the hope that it will be useful,
|
21 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
* GNU General Public License for more details.
|
24 |
*
|
25 |
+
* You should have received a copy of the GNU General Public License
|
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
|
31 |
+
if (!function_exists('add_action')) {
|
32 |
header('Status: 403 Forbidden');
|
33 |
header('HTTP/1.1 403 Forbidden');
|
34 |
exit();
|
51 |
*/
|
52 |
class transposh_plugin {
|
53 |
// List of contained objects
|
54 |
+
|
55 |
+
/** @var transposh_plugin_options An options object */
|
56 |
public $options;
|
57 |
+
/** @var transposh_plugin_admin Admin page */
|
58 |
private $admin;
|
59 |
+
/** @var transposh_plugin_widget Widget control */
|
60 |
public $widget;
|
61 |
+
/** @var transposh_database The database class */
|
62 |
public $database;
|
63 |
+
/** @var transposh_postpublish Happens after editing */
|
64 |
public $postpublish;
|
65 |
|
66 |
// list of properties
|
67 |
+
/** @var string The site url */
|
68 |
public $home_url;
|
69 |
+
/** @var string Where the javascript should post to */
|
70 |
public $post_url;
|
71 |
+
/** @var string The url to the plugin directory */
|
72 |
public $transposh_plugin_url;
|
73 |
+
/** @var string The directory of the plugin */
|
74 |
+
public $transposh_plugin_dir;
|
75 |
+
/** @var boolean Enable rewriting of URLs */
|
76 |
public $enable_permalinks_rewrite;
|
77 |
+
/** @var string The language to translate the page to */
|
78 |
public $target_language;
|
79 |
+
/** @var boolean Are we currently editing the page? */
|
80 |
public $edit_mode;
|
81 |
+
/** @var string Error message displayed for the admin in case of failure */
|
82 |
private $admin_msg;
|
83 |
+
/** @var string Saved search variables */
|
84 |
private $search_s;
|
85 |
|
86 |
/**
|
87 |
* class constructor
|
88 |
*/
|
89 |
function transposh_plugin() {
|
90 |
+
// create and initialize sub-objects
|
91 |
+
$this->options = new transposh_plugin_options();
|
92 |
+
$this->database = new transposh_database($this);
|
93 |
+
$this->admin = new transposh_plugin_admin($this);
|
94 |
+
$this->widget = new transposh_plugin_widget($this);
|
95 |
+
$this->postpublish = new transposh_postpublish($this);
|
96 |
+
|
97 |
+
// "global" vars
|
98 |
+
$this->home_url = get_option('home');
|
99 |
+
|
100 |
+
// Handle windows ('C:\wordpress')
|
101 |
+
$local_dir = preg_replace("/\\\\/", "/", dirname(__FILE__));
|
102 |
+
// Get last directory name
|
103 |
+
$local_dir = preg_replace("/.*\//", "", $local_dir);
|
104 |
+
$this->transposh_plugin_url = WP_PLUGIN_URL . '/' . $local_dir;
|
105 |
+
// TODO - test on more platforms - this failed in 2.7.1 so I am reverting for now...
|
106 |
+
//$tr_plugin_url= plugins_url('', __FILE__);
|
107 |
+
|
108 |
+
$this->transposh_plugin_dir = plugin_dir_path(__FILE__);
|
109 |
+
|
110 |
+
$this->post_url = "{$this->transposh_plugin_url}/wp/transposh_ajax.php";
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
+
//Register some functions into wordpress
|
115 |
+
// includes transposh dir and php
|
116 |
+
add_filter('plugin_action_links_' . preg_replace('|^' . preg_quote(WP_PLUGIN_DIR, '|') . '/|', '', __FILE__), array(&$this, 'plugin_action_links'));
|
117 |
+
add_filter('query_vars', array(&$this, 'parameter_queryvars'));
|
118 |
+
add_filter('rewrite_rules_array', array(&$this, 'update_rewrite_rules'));
|
119 |
+
if ($this->options->get_enable_url_translate()) {
|
120 |
+
add_filter('request', array(&$this, 'request_filter'));
|
121 |
+
}
|
122 |
+
add_filter('comment_text', array(&$this, 'comment_text_wrap'), 9999); // this is a late filter...
|
123 |
+
add_filter('bp_uri', array(&$this, 'bp_uri_filter')); // buddypress compatability
|
124 |
+
add_action('init', array(&$this, 'on_init'), 0); // really high priority
|
125 |
+
add_action('parse_request', array(&$this, 'on_parse_request'));
|
126 |
+
add_action('plugins_loaded', array(&$this, 'plugin_loaded'));
|
127 |
+
add_action('shutdown', array(&$this, 'on_shutdown'));
|
128 |
+
add_action('wp_print_styles', array(&$this, 'add_transposh_css'));
|
129 |
+
add_action('wp_print_scripts', array(&$this, 'add_transposh_js'));
|
130 |
// add_action('wp_head', array(&$this,'add_transposh_async'));
|
131 |
+
add_action("sm_addurl", array(&$this, 'add_sm_transposh_urls'));
|
132 |
+
add_action('transposh_backup_event', array(&$this, 'run_backup'));
|
133 |
+
add_action('comment_post', array(&$this, 'add_comment_meta_settings'), 1);
|
134 |
+
//TODO add_action('manage_comments_nav', array(&$this,'manage_comments_nav'));
|
135 |
+
//TODO comment_row_actions (filter)
|
136 |
+
|
137 |
+
register_activation_hook(__FILE__, array(&$this, 'plugin_activate'));
|
138 |
+
register_deactivation_hook(__FILE__, array(&$this, 'plugin_deactivate'));
|
139 |
}
|
140 |
|
141 |
/**
|
144 |
* @return boolean Is it a special page?
|
145 |
*/
|
146 |
function is_special_page($url) {
|
147 |
+
return ( stripos($url, '/wp-login.php') !== FALSE ||
|
148 |
+
stripos($url, '/wp-admin/') !== FALSE ||
|
149 |
+
stripos($url, '/xmlrpc.php') !== FALSE);
|
150 |
}
|
151 |
|
152 |
/**
|
156 |
*/
|
157 |
function process_page(&$buffer) {
|
158 |
|
159 |
+
$start_time = microtime(TRUE);
|
160 |
+
|
161 |
+
// Refrain from touching the administrative interface and important pages
|
162 |
+
if ($this->is_special_page($_SERVER['REQUEST_URI'])) {
|
163 |
+
|
164 |
+
return $buffer;
|
165 |
+
}
|
166 |
+
|
167 |
+
// This one fixed a bug transposh created with other pages (xml generator for other plugins - such as the nextgen gallery)
|
168 |
+
// TODO: need to further investigate (will it be needed?)
|
169 |
+
if ($this->target_language == '') return $buffer;
|
170 |
+
// Don't translate the default language unless specifically allowed to...
|
171 |
+
if ($this->options->is_default_language($this->target_language) && !$this->options->get_enable_default_translate()) {
|
172 |
+
|
173 |
+
return $buffer;
|
174 |
+
}
|
175 |
+
|
176 |
+
|
177 |
+
|
178 |
+
//translate the entire page
|
179 |
+
$parse = new parser();
|
180 |
+
$parse->fetch_translate_func = array(&$this->database, 'fetch_translation');
|
181 |
+
$parse->prefetch_translate_func = array(&$this->database, 'prefetch_translations');
|
182 |
+
$parse->url_rewrite_func = array(&$this, 'rewrite_url');
|
183 |
+
$parse->dir_rtl = (in_array($this->target_language, $GLOBALS['rtl_languages']));
|
184 |
+
$parse->lang = $this->target_language;
|
185 |
+
$parse->default_lang = $this->options->is_default_language($this->target_language);
|
186 |
+
$parse->is_edit_mode = $this->edit_mode;
|
187 |
+
$parse->is_auto_translate = $this->is_auto_translate_permitted();
|
188 |
+
// TODO - check this!
|
189 |
+
if (stripos($_SERVER['REQUEST_URI'], '/feed/') !== FALSE) {
|
190 |
+
|
191 |
+
$parse->is_auto_translate = false;
|
192 |
+
$parse->is_edit_mode = false;
|
193 |
+
$parse->feed_fix = true;
|
194 |
+
}
|
195 |
+
$buffer = $parse->fix_html($buffer);
|
196 |
+
|
197 |
+
$end_time = microtime(TRUE);
|
198 |
+
|
199 |
+
|
200 |
+
return $buffer;
|
|
|
201 |
}
|
202 |
|
203 |
/**
|
205 |
* Once processing is completed the buffer will go into the translation process.
|
206 |
*/
|
207 |
function on_init() {
|
208 |
+
|
209 |
+
|
210 |
+
// the wp_rewrite is not available earlier so we can only set the enable_permalinks here
|
211 |
+
if (is_object($GLOBALS['wp_rewrite'])) {
|
212 |
+
if ($GLOBALS['wp_rewrite']->using_permalinks() && $this->options->get_enable_permalinks()) {
|
213 |
+
|
214 |
+
$this->enable_permalinks_rewrite = TRUE;
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
//set the callback for translating the page when it's done
|
219 |
+
ob_start(array(&$this, "process_page"));
|
220 |
}
|
221 |
|
222 |
/**
|
223 |
* Page generation completed - flush buffer.
|
224 |
*/
|
225 |
function on_shutdown() {
|
226 |
+
ob_flush();
|
227 |
}
|
228 |
|
229 |
/**
|
232 |
* @return array New rewrite rules
|
233 |
*/
|
234 |
function update_rewrite_rules($rules) {
|
235 |
+
|
236 |
|
237 |
+
if (!$this->options->get_enable_permalinks()) {
|
238 |
+
|
239 |
+
return $rules;
|
240 |
+
}
|
241 |
|
242 |
+
$newRules = array();
|
243 |
+
$lang_prefix = "([a-z]{2,2}(\-[a-z]{2,2})?)/";
|
244 |
|
245 |
+
$lang_parameter = "&" . LANG_PARAM . '=$matches[1]';
|
246 |
|
247 |
+
//catch the root url
|
248 |
+
$newRules[$lang_prefix . "?$"] = "index.php?lang=\$matches[1]";
|
249 |
+
|
250 |
|
251 |
+
foreach ($rules as $key => $value) {
|
252 |
+
$original_key = $key;
|
253 |
+
$original_value = $value;
|
254 |
|
255 |
+
$key = $lang_prefix . $key;
|
256 |
|
257 |
+
//Shift existing matches[i] two step forward as we pushed new elements
|
258 |
+
//in the beginning of the expression
|
259 |
+
for ($i = 6; $i > 0; $i--) {
|
260 |
+
$value = str_replace('[' . $i . ']', '[' . ($i + 2) . ']', $value);
|
261 |
+
}
|
262 |
|
263 |
+
$value .= $lang_parameter;
|
264 |
|
265 |
+
|
266 |
|
267 |
|
268 |
+
$newRules[$key] = $value;
|
269 |
+
$newRules[$original_key] = $original_value;
|
270 |
|
271 |
+
|
272 |
+
}
|
273 |
|
274 |
+
|
275 |
+
return $newRules;
|
276 |
}
|
277 |
|
278 |
/**
|
281 |
* @return array Modified array
|
282 |
*/
|
283 |
function parameter_queryvars($vars) {
|
284 |
+
|
285 |
+
$vars[] = LANG_PARAM;
|
286 |
+
$vars[] = EDIT_PARAM;
|
287 |
+
|
288 |
+
return $vars;
|
289 |
}
|
290 |
|
291 |
/**
|
293 |
* @param WP $wp - here we get the WP class
|
294 |
*/
|
295 |
function on_parse_request($wp) {
|
296 |
+
|
297 |
+
|
298 |
+
|
299 |
+
// fix for custom-permalink (and others that might be double parsing?)
|
300 |
+
if ($this->target_language) return;
|
301 |
+
|
302 |
+
// first we get the target language
|
303 |
+
$this->target_language = $wp->query_vars[LANG_PARAM];
|
304 |
+
if (!$this->target_language)
|
305 |
+
$this->target_language = $this->options->get_default_language();
|
306 |
+
|
307 |
+
|
308 |
+
// we'll go into this code of redirection only if we have options that need it (and no bot is involved, for the non-cookie) and this is not a special page or one that is refered by our site
|
309 |
+
if (($this->options->get_enable_detect_language() || $this->options->get_widget_allow_set_default_language()) &&
|
310 |
+
!($this->is_special_page($_SERVER['REQUEST_URI']) || strpos($_SERVER['HTTP_REFERER'], $this->home_url) !== false)) {
|
311 |
+
// we are starting a session if needed
|
312 |
+
if (!session_id()) session_start();
|
313 |
+
// no redirections if we already redirected in this session or we suspect cyclic redirections
|
314 |
+
if (!$_SESSION['TR_REDIRECTED'] && !($_SERVER['HTTP_REFERER'] == $_SERVER['REQUEST_URI'])) {
|
315 |
+
|
316 |
+
// we redirect once per session
|
317 |
+
$_SESSION['TR_REDIRECTED'] = true;
|
318 |
+
// redirect according to stored lng cookie, and than according to detection
|
319 |
+
if (isset($_COOKIE['TR_LNG']) && $this->options->get_widget_allow_set_default_language()) {
|
320 |
+
if ($_COOKIE['TR_LNG'] != $this->target_language) {
|
321 |
+
$url = rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, $_COOKIE['TR_LNG'], $this->edit_mode);
|
322 |
+
if ($this->options->is_default_language($_COOKIE['TR_LNG']))
|
323 |
+
$url = cleanup_url($_SERVER["REQUEST_URI"], $this->home_url);
|
324 |
+
|
325 |
+
wp_redirect($url);
|
326 |
+
exit;
|
327 |
+
}
|
328 |
+
} else {
|
329 |
+
$bestlang = prefered_language(explode(',', $this->options->get_viewable_langs()), $this->options->get_default_language());
|
330 |
+
// we won't redirect if we should not, or this is a presumable bot
|
331 |
+
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']))) {
|
332 |
+
$url = rewrite_url_lang_param($_SERVER['REQUEST_URI'], $this->home_url, $this->enable_permalinks_rewrite, $bestlang, $this->edit_mode);
|
333 |
+
if ($this->options->is_default_language($bestlang))
|
334 |
+
$url = cleanup_url($_SERVER['REQUEST_URI'], $this->home_url);
|
335 |
+
|
336 |
+
wp_redirect($url);
|
337 |
+
exit;
|
338 |
+
}
|
339 |
+
}
|
340 |
+
} else {
|
341 |
+
|
342 |
+
}
|
343 |
+
}
|
344 |
+
// this method allows posts from the search box to maintain the language,
|
345 |
+
// TODO - it has a bug of returning to original language following search, which can be resolved by removing search from widget urls, but maybe later...
|
346 |
+
if (isset($wp->query_vars['s'])) {
|
347 |
+
if ($this->options->get_enable_search_translate()) {
|
348 |
+
add_action('pre_get_posts', array(&$this, 'pre_post_search'));
|
349 |
+
add_action('posts_where_request', array(&$this, 'posts_where_request'));
|
350 |
+
}
|
351 |
+
if (get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url) && !get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url)) {
|
352 |
+
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");
|
353 |
+
exit;
|
354 |
+
}
|
355 |
+
}
|
356 |
+
if (isset($wp->query_vars[EDIT_PARAM]) && $wp->query_vars[EDIT_PARAM] && $this->is_editing_permitted()) {
|
357 |
+
$this->edit_mode = true;
|
358 |
+
} else {
|
359 |
+
$this->edit_mode = false;
|
360 |
+
}
|
361 |
+
// We are removing our query vars since they are no longer needed and also make issues when a user select a static page as his home
|
362 |
+
unset($wp->query_vars[LANG_PARAM]);
|
363 |
+
unset($wp->query_vars[EDIT_PARAM]);
|
364 |
+
|
365 |
}
|
366 |
|
367 |
// TODO ? move to options?
|
368 |
+
|
369 |
/**
|
370 |
* Determine if the current user is allowed to translate.
|
371 |
* @return boolean Is allowed to translate?
|
372 |
*/
|
373 |
function is_translator() {
|
374 |
+
//if anonymous translation is allowed - let anyone enjoy it
|
375 |
+
if ($this->options->get_anonymous_translation()) {
|
376 |
+
return TRUE;
|
377 |
+
}
|
378 |
+
if (is_user_logged_in() && current_user_can(TRANSLATOR)) {
|
379 |
+
return TRUE;
|
380 |
+
}
|
381 |
+
return FALSE;
|
382 |
}
|
383 |
|
384 |
/**
|
385 |
* Plugin activation
|
386 |
*/
|
387 |
function plugin_activate() {
|
388 |
+
|
389 |
|
390 |
+
$this->database->setup_db();
|
391 |
+
// is it needed? the filter is already there? // TODO
|
392 |
+
add_filter('rewrite_rules_array', array(&$this, 'update_rewrite_rules'));
|
393 |
+
$GLOBALS['wp_rewrite']->flush_rules();
|
394 |
|
395 |
+
|
396 |
+
|
397 |
+
|
398 |
+
//activate_plugin($plugin);
|
399 |
}
|
400 |
|
401 |
/**
|
402 |
* Plugin deactivation
|
403 |
*/
|
404 |
function plugin_deactivate() {
|
405 |
+
|
406 |
|
407 |
+
// is it needed? the filter is already there? // TODO
|
408 |
+
add_filter('rewrite_rules_array', array(&$this, 'update_rewrite_rules'));
|
409 |
+
$GLOBALS['wp_rewrite']->flush_rules();
|
410 |
|
411 |
+
|
412 |
}
|
413 |
|
414 |
/**
|
415 |
* Callback from admin_notices - display error message to the admin.
|
416 |
*/
|
417 |
function plugin_install_error() {
|
418 |
+
|
419 |
|
420 |
+
echo '<div class="updated"><p>';
|
421 |
+
echo 'Error has occured in the installation process of the translation plugin: <br>';
|
422 |
+
echo $this->admin_msg;
|
423 |
|
424 |
+
if (function_exists('deactivate_plugins')) {
|
425 |
+
// FIXME :wtf?
|
426 |
+
deactivate_plugins(array(&$this, 'get_plugin_name'), "translate.php");
|
427 |
+
echo '<br> This plugin has been automatically deactivated.';
|
428 |
+
}
|
429 |
|
430 |
+
echo '</p></div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
}
|
432 |
|
433 |
/**
|
437 |
* TODO - needs revisiting!
|
438 |
*/
|
439 |
function plugin_loaded() {
|
440 |
+
|
441 |
|
442 |
+
//TODO: fix this...
|
443 |
+
$db_version = get_option(TRANSPOSH_DB_VERSION);
|
444 |
|
445 |
+
if ($db_version != DB_VERSION) {
|
446 |
+
$this->database->setup_db();
|
447 |
+
//$this->admin_msg = "Translation database version ($db_version) is not comptabile with this plugin (". DB_VERSION . ") <br>";
|
448 |
|
449 |
+
|
450 |
+
//Some error occured - notify admin and deactivate plugin
|
451 |
+
//add_action('admin_notices', 'plugin_install_error');
|
452 |
+
}
|
453 |
|
454 |
+
//TODO: fix this too...
|
455 |
+
$db_version = get_option(TRANSPOSH_DB_VERSION);
|
456 |
|
457 |
+
if ($db_version != DB_VERSION) {
|
458 |
+
$this->admin_msg = "Failed to locate the translation table <em> " . TRANSLATIONS_TABLE . "</em> in local database. <br>";
|
459 |
|
460 |
+
|
461 |
+
//Some error occured - notify admin and deactivate plugin
|
462 |
+
add_action('admin_notices', array(&$this, 'plugin_install_error'));
|
463 |
+
}
|
464 |
}
|
465 |
|
466 |
/**
|
471 |
* @return string
|
472 |
*/
|
473 |
function get_plugin_name() {
|
474 |
+
$file = __FILE__;
|
475 |
+
$file = str_replace('\\', '/', $file); // sanitize for Win32 installs
|
476 |
+
$file = preg_replace('|/+|', '/', $file); // remove any duplicate slash
|
477 |
+
//keep only the file name and its parent directory
|
478 |
+
$file = preg_replace('/.*\/([^\/]+\/[^\/]+)$/', '$1', $file);
|
479 |
+
|
480 |
+
return $file;
|
|
|
481 |
}
|
482 |
|
483 |
/**
|
484 |
* Add custom css, i.e. transposh.css
|
485 |
*/
|
486 |
function add_transposh_css() {
|
487 |
+
//translation not allowed - no need for the transposh.css
|
488 |
+
if (!$this->is_editing_permitted() && !$this->is_auto_translate_permitted())
|
489 |
+
return;
|
490 |
+
// actually - this is only needed when editing
|
491 |
+
if (!$this->edit_mode) return;
|
492 |
+
|
493 |
+
//include the transposh.css
|
494 |
+
wp_enqueue_style('transposh', $this->transposh_plugin_url . '/' . TRANSPOSH_DIR_CSS . '/transposh.css', array(), TRANSPOSH_PLUGIN_VER);
|
495 |
+
|
496 |
+
|
|
|
497 |
}
|
498 |
|
499 |
/**
|
500 |
* Insert references to the javascript files used in the translated version of the page.
|
501 |
*/
|
502 |
function add_transposh_js() {
|
503 |
+
//not in any translation mode - no need for any js.
|
504 |
+
if (!($this->edit_mode || $this->is_auto_translate_permitted())) return;
|
505 |
+
|
506 |
+
wp_enqueue_script('transposh', $this->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposh.js', array('jquery'), TRANSPOSH_PLUGIN_VER);
|
507 |
+
// true -> 1, false -> nothing
|
508 |
+
wp_localize_script('transposh', 't_jp', array(
|
509 |
+
'post_url' => $this->post_url,
|
510 |
+
'plugin_url' => $this->transposh_plugin_url,
|
511 |
+
'edit' => ($this->edit_mode ? '1' : ''),
|
512 |
+
//'rtl' => (in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : ''),
|
513 |
+
'lang' => $this->target_language,
|
514 |
+
// those two options show if the script can support said engines
|
515 |
+
'msn' => (in_array($this->target_language, $GLOBALS['bing_languages']) && $this->options->get_msn_key() ? '1' : ''),
|
516 |
+
'google' => (in_array($this->target_language, $GLOBALS['google_languages']) ? '1' : ''),
|
517 |
+
'prefix' => SPAN_PREFIX,
|
518 |
+
'msnkey' => $this->options->get_msn_key(),
|
519 |
+
'preferred' => $this->options->get_preferred_translator(),
|
520 |
+
'progress' => $this->edit_mode || $this->options->get_widget_progressbar() ? '1' : '')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
521 |
// 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
|
522 |
+
);
|
523 |
+
|
|
|
|
|
|
|
524 |
}
|
525 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
526 |
/**
|
527 |
* Determine if the currently selected language (taken from the query parameters) is in the admin's list
|
528 |
* of editable languages and the current user is allowed to translate.
|
530 |
*/
|
531 |
// TODO????
|
532 |
function is_editing_permitted() {
|
533 |
+
// editing is permitted for translators only
|
534 |
+
if (!$this->is_translator()) return false;
|
535 |
+
// and only on the non-default lang (unless strictly specified)
|
536 |
+
if (!$this->options->get_enable_default_translate() && $this->options->is_default_language($this->target_language))
|
537 |
+
return false;
|
538 |
|
539 |
+
return $this->options->is_editable_language($this->target_language);
|
540 |
}
|
541 |
|
542 |
/**
|
544 |
* of editable languages and that automatic translation has been enabled.
|
545 |
* Note that any user can auto translate. i.e. ignore permissions.
|
546 |
* @return boolean Is automatic translation allowed?
|
547 |
+
* TODO: move to options
|
548 |
*/
|
549 |
function is_auto_translate_permitted() {
|
550 |
+
|
551 |
|
552 |
+
if (!$this->options->get_enable_auto_translate()) return false;
|
553 |
+
// auto translate is not enabled for default target language when enable default is disabled
|
554 |
+
if (!$this->options->get_enable_default_translate() && $this->options->is_default_language($this->target_language))
|
555 |
+
return false;
|
556 |
|
557 |
+
return $this->options->is_editable_language($this->target_language);
|
558 |
}
|
559 |
|
560 |
/**
|
565 |
* @return boolean Modified href
|
566 |
*/
|
567 |
function rewrite_url($href) {
|
568 |
+
$use_params = FALSE;
|
569 |
+
|
570 |
+
|
571 |
+
// Ignore urls not from this site
|
572 |
+
if (stripos($href, $this->home_url) === FALSE) {
|
573 |
+
return $href;
|
574 |
+
}
|
575 |
+
|
576 |
+
// don't fix links pointing to real files as it will cause that the
|
577 |
+
// web server will not be able to locate them
|
578 |
+
if (stripos($href, '/wp-admin') !== FALSE ||
|
579 |
+
stripos($href, WP_CONTENT_URL) !== FALSE ||
|
580 |
+
stripos($href, '/wp-login') !== FALSE ||
|
581 |
+
stripos($href, '/.php') !== FALSE) {
|
582 |
+
return $href;
|
583 |
+
}
|
584 |
+
$use_params = !$this->enable_permalinks_rewrite;
|
585 |
+
|
586 |
+
// some hackery needed for url translations
|
587 |
+
// first cut home
|
588 |
+
if ($this->options->get_enable_url_translate()) {
|
589 |
+
$href = translate_url($href, $this->home_url, $this->target_language, array(&$this->database, 'fetch_translation'));
|
590 |
+
}
|
591 |
+
$href = rewrite_url_lang_param($href, $this->home_url, $this->enable_permalinks_rewrite, $this->target_language, $this->edit_mode, $use_params);
|
592 |
+
|
593 |
+
return $href;
|
594 |
}
|
595 |
|
596 |
/**
|
598 |
* @param array $links Links that appear next to the plugin
|
599 |
* @return array Now with settings
|
600 |
*/
|
601 |
+
function plugin_action_links($links) {
|
602 |
+
|
603 |
+
return array_merge(array('<a href="' . admin_url('options-general.php?page=' . TRANSPOSH_ADMIN_PAGE_NAME) . '">Settings</a>'), $links);
|
604 |
}
|
605 |
|
606 |
/**
|
607 |
* We use this to "steal" the search variables
|
608 |
* @param WP_Query $query
|
609 |
*/
|
610 |
+
function pre_post_search($query) {
|
611 |
+
|
612 |
+
|
613 |
+
// we hide the search query var from further proccesing, because we do this later
|
614 |
+
if ($query->query_vars['s']) {
|
615 |
+
$this->search_s = $query->query_vars['s'];
|
616 |
+
$query->query_vars['s'] = '';
|
617 |
+
}
|
618 |
}
|
619 |
|
620 |
/**
|
622 |
* @param string $where Original where clause for getting posts
|
623 |
* @return string Modified where
|
624 |
*/
|
625 |
+
function posts_where_request($where) {
|
626 |
+
|
627 |
+
|
628 |
+
// from query.php line 1742 (v2.8.6)
|
629 |
+
// If a search pattern is specified, load the posts that match
|
630 |
+
$q = &$GLOBALS['wp_query']->query_vars;
|
631 |
+
// returning the saved query strings
|
632 |
+
$q['s'] = $this->search_s;
|
633 |
+
if (!empty($q['s'])) {
|
634 |
+
// added slashes screw with quote grouping when done early, so done later
|
635 |
+
$q['s'] = stripslashes($q['s']);
|
636 |
+
if (!empty($q['sentence'])) {
|
637 |
+
$q['search_terms'] = array($q['s']);
|
638 |
+
} else {
|
639 |
+
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q['s'], $matches);
|
640 |
+
$q['search_terms'] = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
|
641 |
+
}
|
642 |
+
$n = !empty($q['exact']) ? '' : '%';
|
643 |
+
$searchand = '';
|
644 |
+
foreach ((array) $q['search_terms'] as $term) {
|
645 |
+
// now we'll get possible translations for this term
|
646 |
+
$possible_original_terms = $this->database->get_orignal_phrases_for_search_term($term, $this->target_language);
|
647 |
+
$term = addslashes_gpc($term);
|
648 |
+
$search .= "{$searchand}(({$GLOBALS['wpdb']->posts}.post_title LIKE '{$n}{$term}{$n}') OR ({$GLOBALS['wpdb']->posts}.post_content LIKE '{$n}{$term}{$n}')";
|
649 |
+
foreach ((array) $possible_original_terms as $term) {
|
650 |
+
$term = addslashes_gpc($term);
|
651 |
+
$search .= " OR ({$GLOBALS['wpdb']->posts}.post_title LIKE '{$n}{$term}{$n}') OR ({$GLOBALS['wpdb']->posts}.post_content LIKE '{$n}{$term}{$n}')";
|
652 |
+
}
|
653 |
+
// we moved this to here, so it really closes all of them
|
654 |
+
$search .= ")";
|
655 |
+
$searchand = ' AND ';
|
656 |
+
}
|
657 |
+
$term = $GLOBALS['wpdb']->escape($q['s']);
|
658 |
+
if (empty($q['sentence']) && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'])
|
659 |
+
$search .= " OR ({$GLOBALS['wpdb']->posts}.post_title LIKE '{$n}{$term}{$n}') OR ({$GLOBALS['wpdb']->posts}.post_content LIKE '{$n}{$term}{$n}')";
|
660 |
+
|
661 |
+
if (!empty($search)) {
|
662 |
+
$search = " AND ({$search}) ";
|
663 |
+
if (!is_user_logged_in())
|
664 |
+
$search .= " AND ({$GLOBALS['wpdb']->posts}.post_password = '') ";
|
665 |
+
}
|
666 |
+
}
|
667 |
+
|
668 |
+
return $search . $where;
|
669 |
}
|
670 |
|
671 |
/**
|
676 |
* @param GoogleSitemapGeneratorPage $sm_page Object containing the page information
|
677 |
*/
|
678 |
function add_sm_transposh_urls(&$sm_page) {
|
679 |
+
|
680 |
+
// we need the generator object (we know it must exist...)
|
681 |
+
$generatorObject = &GoogleSitemapGenerator::GetInstance();
|
682 |
+
// we reduce the priorty by 0.2, but not below zero
|
683 |
+
$sm_page->SetProprity(max($sm_page->GetPriority() - 0.2, 0));
|
684 |
+
|
685 |
+
$viewable_langs = explode(',', $this->options->get_viewable_langs());
|
686 |
+
$orig_url = $sm_page->GetUrl();
|
687 |
+
foreach ($viewable_langs as $lang) {
|
688 |
+
if (!$this->options->is_default_language($lang)) {
|
689 |
+
$newloc = $orig_url;
|
690 |
+
if ($this->options->get_enable_url_translate()) {
|
691 |
+
$newloc = translate_url($newloc, $this->home_url, $lang, array(&$this->database, 'fetch_translation'));
|
692 |
+
}
|
693 |
+
$newloc = rewrite_url_lang_param($newloc, $this->home_url, $this->enable_permalinks_rewrite, $lang, false);
|
694 |
+
$sm_page->SetUrl($newloc);
|
695 |
+
$generatorObject->AddElement($sm_page);
|
696 |
+
}
|
697 |
+
}
|
698 |
}
|
699 |
|
700 |
/**
|
701 |
* Runs a scheduled backup
|
702 |
*/
|
703 |
function run_backup() {
|
704 |
+
|
705 |
+
$my_transposh_backup = new transposh_backup($this);
|
706 |
+
$my_transposh_backup->do_backup();
|
707 |
}
|
708 |
|
709 |
/**
|
712 |
* @param int $post_id
|
713 |
*/
|
714 |
function add_comment_meta_settings($post_id) {
|
715 |
+
if (get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url))
|
716 |
+
add_comment_meta($post_id, 'tp_language', get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), true);
|
717 |
}
|
718 |
|
719 |
/**
|
722 |
* @return string The url that buddypress should see
|
723 |
*/
|
724 |
function bp_uri_filter($uri) {
|
725 |
+
$lang = get_language_from_url($uri, $this->home_url);
|
726 |
+
$uri = cleanup_url($uri, $this->home_url);
|
727 |
+
if ($this->options->get_enable_url_translate()) {
|
728 |
+
$uri = get_original_url($uri, '', $lang, array($this->database, 'fetch_original'));
|
729 |
+
}
|
730 |
+
return $uri;
|
731 |
}
|
732 |
|
733 |
/**
|
736 |
* @return string
|
737 |
*/
|
738 |
function comment_text_wrap($text) {
|
739 |
+
$comment_lang = get_comment_meta(get_comment_ID(), 'tp_language', true);
|
740 |
+
if ($comment_lang) {
|
741 |
+
$text = "<span lang =\"$comment_lang\">" . $text . "</span>";
|
742 |
+
}
|
743 |
+
|
744 |
+
return $text;
|
745 |
}
|
746 |
|
747 |
/**
|
751 |
* @return <type>
|
752 |
*/
|
753 |
function request_filter($query) {
|
754 |
+
//no need to handle non-lang
|
755 |
+
if (!$query['lang']) return $query;
|
756 |
+
|
757 |
+
// the trick is to replace the URI and put it back afterwards
|
758 |
+
$oldRequestUri = $_SERVER['REQUEST_URI'];
|
759 |
+
$_SERVER['REQUEST_URI'] = get_original_url($_SERVER['REQUEST_URI'], '', $query['lang'], array($this->database, 'fetch_original'));
|
760 |
+
remove_filter('request', array(&$this, 'request_filter'));
|
761 |
+
global $wp;
|
762 |
+
$wp->parse_request();
|
763 |
+
$query = $wp->query_vars;
|
764 |
+
|
765 |
+
$_SERVER['REQUEST_URI'] = $oldRequestUri;
|
766 |
+
|
767 |
+
return $query;
|
768 |
}
|
769 |
|
770 |
}
|
771 |
|
772 |
$my_transposh_plugin = new transposh_plugin();
|
|
|
773 |
?>
|
widgets/dropdown/arrow.png
ADDED
Binary file
|
widgets/dropdown/tpw_image_dropdown.css
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Widget's css
|
3 |
+
*/
|
4 |
+
.transposh_flags {
|
5 |
+
direction: ltr;
|
6 |
+
line-height: 0;
|
7 |
+
}
|
8 |
+
.transposh_flags a {
|
9 |
+
/* line-height:11px;*/
|
10 |
+
display: inline;
|
11 |
+
/*background: transparent;*/ /* ie8 quirk */
|
12 |
+
}
|
13 |
+
|
14 |
+
.transposh_flags a:hover {
|
15 |
+
/* ie8 quirk */
|
16 |
+
background:transparent
|
17 |
+
}
|
18 |
+
|
19 |
+
.transposh_flags a span, .transposh_flags a img {
|
20 |
+
border-color:transparent;
|
21 |
+
border-style:solid;
|
22 |
+
border-width:1px 3px;
|
23 |
+
padding: 0;
|
24 |
+
}
|
25 |
+
|
26 |
+
.transposh_flags a span:hover, .transposh_flags a img:hover {
|
27 |
+
border-color:blue
|
28 |
+
}
|
29 |
+
|
30 |
+
/* Code adapted from: http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx */
|
31 |
+
|
32 |
+
.dropdown dd, .dropdown dt, .dropdown ul { margin:0px; padding:0px; }
|
33 |
+
.dropdown dd { position:relative; }
|
34 |
+
.dropdown a, .dropdown a:visited { color:#816c5b; text-decoration:none; outline:none;}
|
35 |
+
.dropdown a:hover { color:#5d4617;}
|
36 |
+
.dropdown dt a:hover, .dropdown dt a:focus { color:#5d4617; border: 1px solid #5d4617;}
|
37 |
+
.dropdown dt a {background:#e4dfcb url(arrow.png) no-repeat scroll right center; display:block; padding-right:20px;
|
38 |
+
border:1px solid #d4ca9a; width:150px;}
|
39 |
+
.dropdown dt a span {cursor:pointer; display:block; padding:5px;}
|
40 |
+
.dropdown dd ul { background:#e4dfcb none repeat scroll 0 0; border:1px solid #d4ca9a; color:#C5C0B0; display:none;
|
41 |
+
left:0px; padding:5px 0px; position:absolute; top:2px; width:auto; min-width:170px; list-style:none;}
|
42 |
+
.dropdown span.value { display:none;}
|
43 |
+
.dropdown dd ul li a { padding:5px; display:block;}
|
44 |
+
.dropdown dd ul li a:hover { background-color:#d0c9af;}
|
45 |
+
|
46 |
+
.dropdown img.flag { border:none; vertical-align:middle; margin-left:10px; }
|
widgets/dropdown/tpw_image_dropdown.js
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Code adapted from: http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx
|
2 |
+
|
3 |
+
(function ($) { // closure
|
4 |
+
|
5 |
+
$(document).ready(function() {
|
6 |
+
$(".dropdown dt a").click(function() {
|
7 |
+
$(".dropdown dd ul").toggle();
|
8 |
+
});
|
9 |
+
|
10 |
+
$(".dropdown dd ul li a").click(function() {
|
11 |
+
var text = $(this).html();
|
12 |
+
$(".dropdown dt a span").html(text);
|
13 |
+
$(".dropdown dd ul").hide();
|
14 |
+
//$()
|
15 |
+
$("form #lang").val( getSelectedValue("tp_dropdown"));
|
16 |
+
$("#tp_form").submit();
|
17 |
+
});
|
18 |
+
|
19 |
+
function getSelectedValue(id) {
|
20 |
+
return $("#" + id).find("dt a span.value").html();
|
21 |
+
}
|
22 |
+
|
23 |
+
$(document).bind('click', function(e) {
|
24 |
+
var $clicked = $(e.target);
|
25 |
+
if (! $clicked.parents().hasClass("dropdown"))
|
26 |
+
$(".dropdown dd ul").hide();
|
27 |
+
});
|
28 |
+
});
|
29 |
+
}(jQuery)); // end of closure
|
widgets/dropdown/tpw_image_dropdown.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Plugin Name: Dropdown selection with image
|
5 |
+
Plugin URI: http://transposh.org/
|
6 |
+
Description: A widget using javascript to present a dropdown selection box with images - adapted from: http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.asp
|
7 |
+
Author: Team Transposh
|
8 |
+
Version: 1.0
|
9 |
+
Author URI: http://transposh.org/
|
10 |
+
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
+
*/
|
12 |
+
|
13 |
+
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
14 |
+
*
|
15 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* This program is distributed in the hope that it will be useful,
|
21 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
* GNU General Public License for more details.
|
24 |
+
*
|
25 |
+
* You should have received a copy of the GNU General Public License
|
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 |
+
/**
|
31 |
+
* This function makes sure that the jquery dependency will be met
|
32 |
+
* @global transposh_plugin $my_transposh_plugin
|
33 |
+
*/
|
34 |
+
function tp_widget_js() {
|
35 |
+
global $my_transposh_plugin;
|
36 |
+
wp_enqueue_script("transposh_widget", "{$my_transposh_plugin->transposh_plugin_url}/widgets/{$my_transposh_plugin->widget->base_widget_file_name}.js", array('jquery'), TRANSPOSH_PLUGIN_VER);
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* This function does the actual HTML for the widget
|
41 |
+
* @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs
|
42 |
+
*/
|
43 |
+
function tp_widget_do($args) {
|
44 |
+
global $my_transposh_plugin;
|
45 |
+
// we calculate the plugin path part, so we can link the images there
|
46 |
+
$plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH);
|
47 |
+
|
48 |
+
// we use this hidden field to later post the value
|
49 |
+
echo '<input type="hidden" name="lang" id="lang" value=""/>';
|
50 |
+
|
51 |
+
echo '<span class="' . NO_TRANSLATE_CLASS . '">';
|
52 |
+
echo '<dl id="tp_dropdown" class="dropdown">';
|
53 |
+
echo '<dt><a href="#"><span>Select language</span></a></dt><dd><ul>';
|
54 |
+
|
55 |
+
foreach ($args as $langrecord) {
|
56 |
+
$is_selected = $langrecord['active'] ? " selected=\"selected\"" : "";
|
57 |
+
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>';
|
58 |
+
}
|
59 |
+
|
60 |
+
echo '</ul></dd></dl>';
|
61 |
+
echo '</span>';
|
62 |
+
}
|
63 |
+
?>
|
widgets/flags/flags58.png
ADDED
Binary file
|
widgets/flags/tpw_flags.css
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Widget's css for flags
|
3 |
+
*/
|
4 |
+
.transposh_flags {
|
5 |
+
direction: ltr; /* we don't want the flags to change direction on rtl */
|
6 |
+
line-height: 0;
|
7 |
+
}
|
8 |
+
.transposh_flags a {
|
9 |
+
/* line-height:11px;*/
|
10 |
+
display: inline;
|
11 |
+
/*background: transparent;*/ /* ie8 quirk */
|
12 |
+
}
|
13 |
+
|
14 |
+
.transposh_flags a:hover {
|
15 |
+
/* ie8 quirk */
|
16 |
+
background:transparent
|
17 |
+
}
|
18 |
+
|
19 |
+
.transposh_flags a span, .transposh_flags a img {
|
20 |
+
border-color:transparent;
|
21 |
+
border-style:solid;
|
22 |
+
border-width:1px 3px;
|
23 |
+
padding: 0;
|
24 |
+
}
|
25 |
+
|
26 |
+
.transposh_flags a span:hover, .transposh_flags a img:hover {
|
27 |
+
border-color:blue
|
28 |
+
}
|
widgets/flags/tpw_flags.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Plugin Name: Flags
|
5 |
+
Plugin URI: http://transposh.org/
|
6 |
+
Description: Widget with flags links
|
7 |
+
Author: Team Transposh
|
8 |
+
Version: 1.0
|
9 |
+
Author URI: http://transposh.org/
|
10 |
+
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
+
*/
|
12 |
+
|
13 |
+
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
14 |
+
*
|
15 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* This program is distributed in the hope that it will be useful,
|
21 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
* GNU General Public License for more details.
|
24 |
+
*
|
25 |
+
* You should have received a copy of the GNU General Public License
|
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 |
+
/**
|
31 |
+
* This function allows the widget to tell the invoker if it needs to calculate different urls per language, here it is needed
|
32 |
+
* @return boolean
|
33 |
+
*/
|
34 |
+
function tp_widget_needs_post_url() {
|
35 |
+
return true;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Creates the list of flags
|
40 |
+
* @global transposh_plugin $my_transposh_plugin
|
41 |
+
* @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs
|
42 |
+
*/
|
43 |
+
function tp_widget_do($args) {
|
44 |
+
global $my_transposh_plugin;
|
45 |
+
// we calculate the plugin path part, so we can link the images there
|
46 |
+
$plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH);
|
47 |
+
|
48 |
+
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
49 |
+
foreach ($args as $langrecord) {
|
50 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .
|
51 |
+
display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) .
|
52 |
+
"</a>";
|
53 |
+
}
|
54 |
+
echo "</div>";
|
55 |
+
}
|
56 |
+
?>
|
widgets/flags/tpw_flags_css.css
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Widget's css (always needed in flags widget use)
|
3 |
+
*/
|
4 |
+
.transposh_flags {
|
5 |
+
direction: ltr; /* we don't want the flags to change direction on rtl */
|
6 |
+
line-height: 0;
|
7 |
+
}
|
8 |
+
.transposh_flags a {
|
9 |
+
/* line-height:11px;*/
|
10 |
+
display: inline;
|
11 |
+
/*background: transparent;*/ /* ie8 quirk */
|
12 |
+
}
|
13 |
+
|
14 |
+
.transposh_flags a:hover {
|
15 |
+
/* ie8 quirk */
|
16 |
+
background:transparent
|
17 |
+
}
|
18 |
+
|
19 |
+
.transposh_flags a span, .transposh_flags a img {
|
20 |
+
border-color:transparent;
|
21 |
+
border-style:solid;
|
22 |
+
border-width:1px 3px;
|
23 |
+
padding: 0;
|
24 |
+
}
|
25 |
+
|
26 |
+
.transposh_flags a span:hover, .transposh_flags a img:hover {
|
27 |
+
border-color:blue
|
28 |
+
}
|
29 |
+
|
30 |
+
/* define the .css sprites here */
|
31 |
+
.trf {
|
32 |
+
background-image:url(flags58.png);
|
33 |
+
height:11px;
|
34 |
+
width:16px;
|
35 |
+
background-repeat:no-repeat;
|
36 |
+
overflow:hidden;
|
37 |
+
display:inline-block;
|
38 |
+
}
|
39 |
+
|
40 |
+
.trf-za {background-position: -24px 0}
|
41 |
+
.trf-al {background-position: -48px 0}
|
42 |
+
.trf-sa {background-position: -72px 0}
|
43 |
+
.trf-am {background-position: -96px 0}
|
44 |
+
.trf-az {background-position: -120px 0}
|
45 |
+
.trf-basque {background-position: -144px 0}
|
46 |
+
.trf-by {background-position: -168px 0}
|
47 |
+
.trf-bg {background-position: -192px 0}
|
48 |
+
.trf-catalonia {background-position: -216px 0}
|
49 |
+
.trf-cn {background-position: -240px 0}
|
50 |
+
.trf-tw {background-position: -264px 0}
|
51 |
+
.trf-hr {background-position: -288px 0}
|
52 |
+
.trf-cz {background-position: -312px 0}
|
53 |
+
.trf-dk {background-position: -336px 0}
|
54 |
+
.trf-nl {background-position: -360px 0}
|
55 |
+
.trf-ee {background-position: -384px 0}
|
56 |
+
.trf-fi {background-position: -408px 0}
|
57 |
+
.trf-fr {background-position: -432px 0}
|
58 |
+
.trf-galicia {background-position: -456px 0}
|
59 |
+
.trf-ge {background-position: -480px 0}
|
60 |
+
.trf-de {background-position: -504px 0}
|
61 |
+
.trf-gr {background-position: -528px 0}
|
62 |
+
.trf-ht {background-position: -552px 0}
|
63 |
+
.trf-il {background-position: -576px 0}
|
64 |
+
.trf-in {background-position: -600px 0}
|
65 |
+
.trf-hu {background-position: -624px 0}
|
66 |
+
.trf-is {background-position: -648px 0}
|
67 |
+
.trf-id {background-position: -672px 0}
|
68 |
+
.trf-ie {background-position: -696px 0}
|
69 |
+
.trf-it {background-position: -720px 0}
|
70 |
+
.trf-jp {background-position: -744px 0}
|
71 |
+
.trf-kr {background-position: -768px 0}
|
72 |
+
.trf-lv {background-position: -792px 0}
|
73 |
+
.trf-lt {background-position: -816px 0}
|
74 |
+
.trf-mk {background-position: -840px 0}
|
75 |
+
.trf-my {background-position: -864px 0}
|
76 |
+
.trf-mt {background-position: -888px 0}
|
77 |
+
.trf-no {background-position: -912px 0}
|
78 |
+
.trf-ir {background-position: -936px 0}
|
79 |
+
.trf-pl {background-position: -960px 0}
|
80 |
+
.trf-pt {background-position: -984px 0}
|
81 |
+
.trf-ro {background-position: -1008px 0}
|
82 |
+
.trf-ru {background-position: -1032px 0}
|
83 |
+
.trf-rs {background-position: -1056px 0}
|
84 |
+
.trf-sk {background-position: -1080px 0}
|
85 |
+
.trf-sl {background-position: -1104px 0}
|
86 |
+
.trf-es {background-position: -1128px 0}
|
87 |
+
.trf-ke {background-position: -1152px 0}
|
88 |
+
.trf-se {background-position: -1176px 0}
|
89 |
+
.trf-ph {background-position: -1200px 0}
|
90 |
+
.trf-th {background-position: -1224px 0}
|
91 |
+
.trf-tr {background-position: -1248px 0}
|
92 |
+
.trf-ua {background-position: -1272px 0}
|
93 |
+
.trf-pk {background-position: -1296px 0}
|
94 |
+
.trf-vn {background-position: -1320px 0}
|
95 |
+
.trf-wales {background-position: -1344px 0}
|
96 |
+
.trf-europeanunion {background-position: -1368px 0}
|
widgets/flags/tpw_flags_css.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Plugin Name: Flags (With CSS)
|
5 |
+
Plugin URI: http://transposh.org/
|
6 |
+
Description: Widget with flags links (Using css sprites)
|
7 |
+
Author: Team Transposh
|
8 |
+
Version: 1.0
|
9 |
+
Author URI: http://transposh.org/
|
10 |
+
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
+
*/
|
12 |
+
|
13 |
+
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
14 |
+
*
|
15 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* This program is distributed in the hope that it will be useful,
|
21 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
* GNU General Public License for more details.
|
24 |
+
*
|
25 |
+
* You should have received a copy of the GNU General Public License
|
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 |
+
/**
|
31 |
+
* This function allows the widget to tell the invoker if it needs to calculate different urls per language, here it is needed
|
32 |
+
* @return boolean
|
33 |
+
*/
|
34 |
+
function tp_widget_needs_post_url() {
|
35 |
+
return true;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Creates the list of flags (with css)
|
40 |
+
* @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs
|
41 |
+
*/
|
42 |
+
function tp_widget_do($args) {
|
43 |
+
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
44 |
+
foreach ($args as $langrecord) {
|
45 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .
|
46 |
+
display_flag("", $langrecord['flag'], $langrecord['langorig'], true) .
|
47 |
+
"</a>";
|
48 |
+
}
|
49 |
+
echo "</div>";
|
50 |
+
}
|
51 |
+
?>
|
widgets/flagslist/tpw_list_with_flags.php
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Plugin Name: List with flags
|
5 |
+
Plugin URI: http://transposh.org/
|
6 |
+
Description: Widget with flags links followed by language name
|
7 |
+
Author: Team Transposh
|
8 |
+
Version: 1.0
|
9 |
+
Author URI: http://transposh.org/
|
10 |
+
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
+
*/
|
12 |
+
|
13 |
+
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
14 |
+
*
|
15 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* This program is distributed in the hope that it will be useful,
|
21 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
* GNU General Public License for more details.
|
24 |
+
*
|
25 |
+
* You should have received a copy of the GNU General Public License
|
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 |
+
/**
|
31 |
+
* This function allows the widget to tell the invoker if it needs to calculate different urls per language
|
32 |
+
* @return boolean
|
33 |
+
*/
|
34 |
+
function tp_widget_needs_post_url() {
|
35 |
+
return true;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Instructs usage of a different .css file
|
40 |
+
* @global transposh_plugin $my_transposh_plugin
|
41 |
+
*/
|
42 |
+
function tp_widget_css() {
|
43 |
+
global $my_transposh_plugin;
|
44 |
+
wp_enqueue_style("transposh_widget", "{$my_transposh_plugin->transposh_plugin_url}/widgets/flags/tpw_flags.css", array(), TRANSPOSH_PLUGIN_VER);
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Creates the list of flags - followed by a language name link
|
49 |
+
* @global transposh_plugin $my_transposh_plugin
|
50 |
+
* @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs
|
51 |
+
*/
|
52 |
+
function tp_widget_do($args) {
|
53 |
+
global $my_transposh_plugin;
|
54 |
+
// we calculate the plugin path part, so we can link the images there
|
55 |
+
$plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH);
|
56 |
+
|
57 |
+
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
58 |
+
foreach ($args as $langrecord) {
|
59 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .
|
60 |
+
display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . "</a>";
|
61 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>";
|
62 |
+
}
|
63 |
+
echo "</div>";
|
64 |
+
}
|
65 |
+
?>
|
widgets/flagslist/tpw_list_with_flags_css.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Plugin Name: List with flags (css)
|
5 |
+
Plugin URI: http://transposh.org/
|
6 |
+
Description: Widget with flags links (using css sprites) followed by language name
|
7 |
+
Author: Team Transposh
|
8 |
+
Version: 1.0
|
9 |
+
Author URI: http://transposh.org/
|
10 |
+
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
+
*/
|
12 |
+
|
13 |
+
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
14 |
+
*
|
15 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* This program is distributed in the hope that it will be useful,
|
21 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
* GNU General Public License for more details.
|
24 |
+
*
|
25 |
+
* You should have received a copy of the GNU General Public License
|
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 |
+
/**
|
31 |
+
* This function allows the widget to tell the invoker if it needs to calculate different urls per language
|
32 |
+
* @return boolean
|
33 |
+
*/
|
34 |
+
function tp_widget_needs_post_url() {
|
35 |
+
return true;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Instructs usage of a different .css file
|
40 |
+
* @global transposh_plugin $my_transposh_plugin
|
41 |
+
*/
|
42 |
+
function tp_widget_css() {
|
43 |
+
global $my_transposh_plugin;
|
44 |
+
wp_enqueue_style("transposh_widget", "{$my_transposh_plugin->transposh_plugin_url}/widgets/flags/tpw_flags_css.css", array(), TRANSPOSH_PLUGIN_VER);
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Creates the list of flags (using css sprites) - followed by a language name link
|
49 |
+
* @global transposh_plugin $my_transposh_plugin
|
50 |
+
* @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs
|
51 |
+
*/
|
52 |
+
function tp_widget_do($args) {
|
53 |
+
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
54 |
+
foreach ($args as $langrecord) {
|
55 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' .
|
56 |
+
display_flag('', $langrecord['flag'], $langrecord['langorig'], false) . '</a>';
|
57 |
+
echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>";
|
58 |
+
}
|
59 |
+
echo "</div>";
|
60 |
+
}
|
61 |
+
?>
|
widgets/tpw_default.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Plugin Name: Default
|
5 |
+
Plugin URI: http://transposh.org/
|
6 |
+
Description: Default widget for transposh
|
7 |
+
Author: Team Transposh
|
8 |
+
Version: 1.0
|
9 |
+
Author URI: http://transposh.org/
|
10 |
+
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
11 |
+
*/
|
12 |
+
|
13 |
+
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
14 |
+
*
|
15 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* This program is distributed in the hope that it will be useful,
|
21 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
* GNU General Public License for more details.
|
24 |
+
*
|
25 |
+
* You should have received a copy of the GNU General Public License
|
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 |
+
/*
|
31 |
+
* Want to write your own widget? - visit the wiki page on widgets http://trac.transposh.org/wiki/WidgetWritingGuide
|
32 |
+
*/
|
33 |
+
|
34 |
+
/*
|
35 |
+
* This widget is the default langauge list widget, the one which provides a drop down select box which allows to choose a new target language
|
36 |
+
*/
|
37 |
+
|
38 |
+
/**
|
39 |
+
* This function does the actual HTML for the widget
|
40 |
+
* @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs
|
41 |
+
*/
|
42 |
+
function tp_widget_do($args) {
|
43 |
+
echo '<span class="' . NO_TRANSLATE_CLASS . '">'; // wrapping in no_translate to avoid translation of this list
|
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 |
+
$is_selected = $langrecord['active'] ? " selected=\"selected\"" : "";
|
48 |
+
echo "<option value=\"{$langrecord['isocode']}\"{$is_selected}>{$langrecord['langorig']}</option>";
|
49 |
+
}
|
50 |
+
echo "</select><br/>";
|
51 |
+
echo "</span>";
|
52 |
+
}
|
53 |
+
?>
|
wp/transposh_admin.php
CHANGED
@@ -1,345 +1,338 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
*
|
18 |
* adapted metabox sample code from http://www.code-styling.de/
|
19 |
-
*/
|
20 |
|
21 |
/*
|
22 |
* Provide the admin page for configuring the translation options. eg. what languages ?
|
23 |
* who is allowed to translate ?
|
24 |
-
*/
|
25 |
|
26 |
-
define
|
27 |
|
28 |
-
//class that reperesent the admin page
|
29 |
class transposh_plugin_admin {
|
|
|
30 |
/** @var transposh_plugin $transposh father class */
|
31 |
private $transposh;
|
32 |
-
|
|
|
33 |
function transposh_plugin_admin(&$transposh) {
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
}
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
function can_translate($role_name) {
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
return ($this->transposh->options->get_anonymous_translation()) ? 'checked="checked"' : '';
|
57 |
}
|
58 |
-
//
|
59 |
-
/*
|
60 |
-
* Handle newly posted admin options.
|
61 |
-
*/
|
62 |
-
function update_admin_options() {
|
63 |
-
|
64 |
-
|
65 |
-
$viewable_langs = array();
|
66 |
-
$editable_langs = array();
|
67 |
-
|
68 |
-
//update roles and capabilities
|
69 |
-
foreach($GLOBALS['wp_roles']->get_names() as $role_name => $something) {
|
70 |
-
$role = $GLOBALS['wp_roles']->get_role($role_name);
|
71 |
-
if($_POST[$role_name] == "1")
|
72 |
-
$role->add_cap(TRANSLATOR);
|
73 |
-
else
|
74 |
-
$role->remove_cap(TRANSLATOR);
|
75 |
-
}
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
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 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
}
|
134 |
|
135 |
-
|
136 |
-
//for WordPress 2.8 we have to tell, that we support 2 columns !
|
137 |
function on_screen_layout_columns($columns, $screen) {
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
}
|
143 |
|
144 |
//add some help
|
145 |
-
function on_contextual_help($filterVal
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
}
|
153 |
|
154 |
-
//extend the admin menu
|
155 |
function on_admin_menu() {
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
//register callback gets call prior your own page gets rendered
|
161 |
-
add_action('load-'.$this->pagehook, array(&$this, 'on_load_page'));
|
162 |
}
|
163 |
|
164 |
-
//will be executed if wordpress core detects this page has to be rendered
|
165 |
function on_load_page() {
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
|
|
188 |
// 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
}
|
207 |
|
208 |
//executed to show the plugins complete admin page
|
209 |
function on_show_page() {
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
<div id="transposh-general" class="wrap">
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
});
|
261 |
-
//]]>
|
262 |
-
</script>
|
263 |
-
|
264 |
-
<?php
|
265 |
}
|
266 |
|
267 |
-
//executed if the post arrives initiated by pressing the submit button of form
|
268 |
function on_save_changes() {
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
wp_redirect($_POST['_wp_http_referer']);
|
281 |
}
|
282 |
|
283 |
-
//below you will find for each registered metabox the callback method, that produces the content inside the boxes
|
284 |
-
//i did not describe each callback dedicated, what they do can be easily inspected and compare with the admin page displayed
|
285 |
|
286 |
function on_sidebox_about_content($data) {
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
}
|
295 |
|
296 |
function on_sidebox_widget_content($data) {
|
297 |
-
|
298 |
}
|
299 |
|
300 |
function on_sidebox_news_content($data) {
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
|
|
332 |
}
|
333 |
|
334 |
function on_sidebox_stats_content($data) {
|
335 |
-
|
336 |
}
|
337 |
|
338 |
function on_sidebox_translate_content($data) {
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
}
|
344 |
|
345 |
/**
|
@@ -347,8 +340,8 @@ class transposh_plugin_admin {
|
|
347 |
* @param string $data
|
348 |
*/
|
349 |
function on_contentbox_languages_content($data) {
|
350 |
-
|
351 |
-
|
352 |
#sortable { list-style-type: none; margin: 0; padding: 0; }
|
353 |
#sortable li, #default_lang li { margin: 3px 3px 3px 0; padding: 5px; float: left; width: 190px; height: 14px;}
|
354 |
.languages {
|
@@ -391,38 +384,41 @@ class transposh_plugin_admin {
|
|
391 |
}
|
392 |
</style>';
|
393 |
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
|
|
|
|
|
|
426 |
}
|
427 |
|
428 |
/**
|
@@ -431,133 +427,131 @@ class transposh_plugin_admin {
|
|
431 |
* @return string used for checkboxes
|
432 |
*/
|
433 |
private function checked($eval) {
|
434 |
-
|
435 |
}
|
436 |
|
437 |
function on_contentbox_translation_content($data) {
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
}
|
477 |
|
478 |
function on_contentbox_auto_translation_content($data) {
|
479 |
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
}
|
517 |
|
518 |
function on_contentbox_generic_content($data) {
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
}
|
551 |
|
552 |
function on_contentbox_community_content($data) {
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
}
|
561 |
-
}
|
562 |
|
|
|
563 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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 |
* adapted metabox sample code from http://www.code-styling.de/
|
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");
|
28 |
|
29 |
+
// class that reperesent the admin page
|
30 |
class transposh_plugin_admin {
|
31 |
+
|
32 |
/** @var transposh_plugin $transposh father class */
|
33 |
private $transposh;
|
34 |
+
|
35 |
+
// constructor of class, PHP4 compatible construction for backward compatibility
|
36 |
function transposh_plugin_admin(&$transposh) {
|
37 |
+
$this->transposh = &$transposh;
|
38 |
+
// add filter for WordPress 2.8 changed backend box system !
|
39 |
+
add_filter('screen_layout_columns', array(&$this, 'on_screen_layout_columns'), 10, 2);
|
40 |
+
// add some help
|
41 |
+
add_filter('contextual_help_list', array(&$this, 'on_contextual_help'), 100, 2);
|
42 |
+
// register callback for admin menu setup
|
43 |
+
add_action('admin_menu', array(&$this, 'on_admin_menu'));
|
44 |
+
// register the callback been used if options of page been submitted and needs to be processed
|
45 |
+
add_action('admin_post_save_transposh', array(&$this, 'on_save_changes'));
|
46 |
}
|
47 |
|
48 |
+
/**
|
49 |
+
* Indicates whether the given role can translate.
|
50 |
+
* Return either "checked" or ""
|
51 |
+
*/
|
52 |
function can_translate($role_name) {
|
53 |
+
if ($role_name != 'anonymous') {
|
54 |
+
$role = $GLOBALS['wp_roles']->get_role($role_name);
|
55 |
+
if (isset($role) && $role->has_cap(TRANSLATOR)) return 'checked="checked"';
|
56 |
+
}
|
57 |
+
else
|
58 |
+
return ($this->transposh->options->get_anonymous_translation()) ? 'checked="checked"' : '';
|
|
|
59 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
/**
|
62 |
+
* Handle newly posted admin options.
|
63 |
+
*/
|
64 |
+
function update_admin_options() {
|
65 |
+
|
66 |
+
|
67 |
+
$viewable_langs = array();
|
68 |
+
$editable_langs = array();
|
69 |
+
|
70 |
+
//update roles and capabilities
|
71 |
+
foreach ($GLOBALS['wp_roles']->get_names() as $role_name => $something) {
|
72 |
+
$role = $GLOBALS['wp_roles']->get_role($role_name);
|
73 |
+
if ($_POST[$role_name] == "1") $role->add_cap(TRANSLATOR);
|
74 |
+
else $role->remove_cap(TRANSLATOR);
|
75 |
+
}
|
76 |
+
|
77 |
+
// anonymous needs to be handled differently as it does not have a role
|
78 |
+
$this->transposh->options->set_anonymous_translation($_POST['anonymous']);
|
79 |
+
|
80 |
+
// first set the default language
|
81 |
+
list ($langcode, $viewable, $translateable) = explode(",", $_POST['languages'][0]);
|
82 |
+
$this->transposh->options->set_default_language($langcode);
|
83 |
+
unset($_POST['languages'][0]);
|
84 |
+
|
85 |
+
// update the list of supported/editable/sortable languages
|
86 |
+
|
87 |
+
foreach ($_POST['languages'] as $code => $lang) {
|
88 |
+
list ($langcode, $viewable, $translateable) = explode(",", $lang);
|
89 |
+
$sorted_langs[$langcode] = $langcode;
|
90 |
+
if ($viewable) {
|
91 |
+
$viewable_langs[$langcode] = $langcode;
|
92 |
+
// force that every viewable lang is editable
|
93 |
+
$editable_langs[$langcode] = $langcode;
|
94 |
+
}
|
95 |
+
|
96 |
+
if ($translateable) {
|
97 |
+
$editable_langs[$langcode] = $langcode;
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
$this->transposh->options->set_viewable_langs(implode(',', $viewable_langs));
|
102 |
+
$this->transposh->options->set_editable_langs(implode(',', $editable_langs));
|
103 |
+
$this->transposh->options->set_sorted_langs(implode(',', $sorted_langs));
|
104 |
+
|
105 |
+
if ($this->transposh->options->get_enable_permalinks() != $_POST[ENABLE_PERMALINKS]) {
|
106 |
+
$this->transposh->options->set_enable_permalinks($_POST[ENABLE_PERMALINKS]);
|
107 |
+
// rewrite rules - refresh. - because we want them set or unset upon this change
|
108 |
+
add_filter('rewrite_rules_array', 'update_rewrite_rules');
|
109 |
+
$GLOBALS['wp_rewrite']->flush_rules();
|
110 |
+
}
|
111 |
+
|
112 |
+
$this->transposh->options->set_enable_footer_scripts($_POST[ENABLE_FOOTER_SCRIPTS]);
|
113 |
+
$this->transposh->options->set_enable_detect_language($_POST[ENABLE_DETECT_LANG_AND_REDIRECT]);
|
114 |
+
$this->transposh->options->set_enable_auto_translate($_POST[ENABLE_AUTO_TRANSLATE]);
|
115 |
+
$this->transposh->options->set_enable_auto_post_translate($_POST[ENABLE_AUTO_POST_TRANSLATE]);
|
116 |
+
$this->transposh->options->set_enable_default_translate($_POST[ENABLE_DEFAULT_TRANSLATE]);
|
117 |
+
$this->transposh->options->set_enable_search_translate($_POST[ENABLE_SEARCH_TRANSLATE]);
|
118 |
+
$this->transposh->options->set_enable_url_translate($_POST[ENABLE_URL_TRANSLATE]);
|
119 |
+
$this->transposh->options->set_enable_msn_translate($_POST[ENABLE_MSN_TRANSLATE]);
|
120 |
+
$this->transposh->options->set_preferred_translator($_POST[PREFERRED_TRANSLATOR]);
|
121 |
+
$this->transposh->options->set_msn_key($_POST[MSN_TRANSLATE_KEY]);
|
122 |
+
$this->transposh->options->set_transposh_key($_POST[TRANSPOSH_KEY]);
|
123 |
+
|
124 |
+
// handle change of schedule for backup to daily
|
125 |
+
if ($_POST[TRANSPOSH_BACKUP_SCHEDULE] != $this->transposh->options->get_transposh_backup_schedule()) {
|
126 |
+
wp_clear_scheduled_hook('transposh_backup_event');
|
127 |
+
if ($_POST[TRANSPOSH_BACKUP_SCHEDULE] == 1)
|
128 |
+
wp_schedule_event(time(), 'daily', 'transposh_backup_event');
|
129 |
+
}
|
130 |
+
$this->transposh->options->set_transposh_backup_schedule($_POST[TRANSPOSH_BACKUP_SCHEDULE]);
|
131 |
+
|
132 |
+
$this->transposh->options->update_options();
|
133 |
}
|
134 |
|
135 |
+
// for WordPress 2.8 we have to tell, that we support 2 columns !
|
|
|
136 |
function on_screen_layout_columns($columns, $screen) {
|
137 |
+
if ($screen == $this->pagehook) {
|
138 |
+
$columns[$this->pagehook] = 2;
|
139 |
+
}
|
140 |
+
return $columns;
|
141 |
}
|
142 |
|
143 |
//add some help
|
144 |
+
function on_contextual_help($filterVal, $screen) {
|
145 |
+
if ($screen == 'settings_page_transposh') {
|
146 |
+
$filterVal['settings_page_transposh'] = '<p>Transposh makes your blog translatable</p>' .
|
147 |
+
'<a href="http://transposh.org/">Plugin homepage</a><br/>' .
|
148 |
+
'<a href="http://transposh.org/faq/">Frequently asked questions</a>';
|
149 |
+
}
|
150 |
+
return $filterVal;
|
151 |
}
|
152 |
|
153 |
+
// extend the admin menu
|
154 |
function on_admin_menu() {
|
155 |
+
//add our own option page, you can also add it to different sections or use your own one
|
156 |
+
$this->pagehook = add_options_page('Transposh control center', 'Transposh', 'manage_options', TRANSPOSH_ADMIN_PAGE_NAME, array(&$this, 'on_show_page'));
|
157 |
+
// register callback gets call prior your own page gets rendered
|
158 |
+
add_action('load-' . $this->pagehook, array(&$this, 'on_load_page'));
|
|
|
|
|
159 |
}
|
160 |
|
161 |
+
// will be executed if wordpress core detects this page has to be rendered
|
162 |
function on_load_page() {
|
163 |
+
//ensure, that the needed javascripts been loaded to allow drag/drop, expand/collapse and hide/show of boxes
|
164 |
+
wp_enqueue_script('common');
|
165 |
+
wp_enqueue_script('wp-lists');
|
166 |
+
wp_enqueue_script('postbox');
|
167 |
+
|
168 |
+
//TODO - make up my mind on using .css flags here (currently no)
|
169 |
+
//if ($this->transposh->options->get_widget_css_flags())
|
170 |
+
// wp_enqueue_style("transposh_flags",$this->transposh->transposh_plugin_url."/widgets/flags/tpw_flags.css",array(),TRANSPOSH_PLUGIN_VER);
|
171 |
+
wp_enqueue_script('jquery-ui-droppable');
|
172 |
+
wp_enqueue_script('transposh_control', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhcontrol.js', array(), TRANSPOSH_PLUGIN_VER, true);
|
173 |
+
wp_localize_script('transposh_control', 't_jp', array(
|
174 |
+
'post_url' => $this->transposh->post_url/* ,
|
175 |
+
'plugin_url' => $this->transposh_plugin_url,
|
176 |
+
'edit' => ($this->edit_mode? '1' : ''),
|
177 |
+
//'rtl' => (in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : ''),
|
178 |
+
'lang' => $this->target_language,
|
179 |
+
// those two options show if the script can support said engines
|
180 |
+
'msn' => (in_array($this->target_language,$GLOBALS['bing_languages']) && $this->options->get_msn_key() ? '1' : ''),
|
181 |
+
'google' => (in_array($this->target_language,$GLOBALS['google_languages']) ? '1' : ''),
|
182 |
+
'prefix' => SPAN_PREFIX,
|
183 |
+
'msnkey'=>$this->options->get_msn_key(),
|
184 |
+
'preferred'=> $this->options->get_preferred_translator(),
|
185 |
+
'progress'=>$this->edit_mode || $this->options->get_widget_progressbar() ? '1' : '') */
|
186 |
// 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
|
187 |
+
));
|
188 |
+
wp_enqueue_script('google', "http://www.google.com/jsapi", array(), '1', true);
|
189 |
+
wp_enqueue_script('transposh_admin', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhadmin.js', array(), TRANSPOSH_PLUGIN_VER, true);
|
190 |
+
wp_enqueue_style('jquery', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css', array(), '1.0');
|
191 |
+
wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js', array('jquery'), '1.7.2', true);
|
192 |
+
|
193 |
+
|
194 |
+
//add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore
|
195 |
+
add_meta_box('transposh-sidebox-about', 'About this plugin', array(&$this, 'on_sidebox_about_content'), $this->pagehook, 'side', 'core');
|
196 |
+
add_meta_box('transposh-sidebox-widget', 'Widget settings', array(&$this, 'on_sidebox_widget_content'), $this->pagehook, 'side', 'core');
|
197 |
+
add_meta_box('transposh-sidebox-news', 'Plugin news', array(&$this, 'on_sidebox_news_content'), $this->pagehook, 'side', 'core');
|
198 |
+
add_meta_box('transposh-sidebox-stats', 'Plugin stats', array(&$this, 'on_sidebox_stats_content'), $this->pagehook, 'side', 'core');
|
199 |
+
add_meta_box('transposh-sidebox-translate', 'Translate all', array(&$this, 'on_sidebox_translate_content'), $this->pagehook, 'side', 'core');
|
200 |
+
add_meta_box('transposh-contentbox-languages', 'Supported languages', array(&$this, 'on_contentbox_languages_content'), $this->pagehook, 'normal', 'core');
|
201 |
+
add_meta_box('transposh-contentbox-translation', 'Translation settings', array(&$this, 'on_contentbox_translation_content'), $this->pagehook, 'normal', 'core');
|
202 |
+
add_meta_box('transposh-contentbox-autotranslation', 'Automatic translation settings', array(&$this, 'on_contentbox_auto_translation_content'), $this->pagehook, 'normal', 'core');
|
203 |
+
add_meta_box('transposh-contentbox-general', 'Generic settings', array(&$this, 'on_contentbox_generic_content'), $this->pagehook, 'normal', 'core');
|
204 |
}
|
205 |
|
206 |
//executed to show the plugins complete admin page
|
207 |
function on_show_page() {
|
208 |
+
//we need the global screen column value to beable to have a sidebar in WordPress 2.8
|
209 |
+
//global $screen_layout_columns;
|
210 |
+
//add a 3rd content box now for demonstration purpose, boxes added at start of page rendering can't be switched on/off,
|
211 |
+
//may be needed to ensure that a special box is always available
|
212 |
+
add_meta_box('transposh-contentbox-community', 'Transposh community features', array(&$this, 'on_contentbox_community_content'), $this->pagehook, 'normal', 'core');
|
213 |
+
//define some data can be given to each metabox during rendering - not used now
|
214 |
+
//$data = array('My Data 1', 'My Data 2', 'Available Data 1');
|
215 |
+
|
216 |
+
echo '<div id="transposh-general" class="wrap">';
|
217 |
+
screen_icon('options-general');
|
218 |
+
|
219 |
+
echo '<h2>Transposh</h2>' .
|
220 |
+
'<form action="admin-post.php" method="post">';
|
221 |
+
|
222 |
+
wp_nonce_field(TR_NONCE);
|
223 |
+
wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
|
224 |
+
wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
|
225 |
+
|
226 |
+
echo '<input type="hidden" name="action" value="save_transposh" />' .
|
227 |
+
'<div id="poststuff" class="metabox-holder' . ((2 == $GLOBALS['screen_layout_columns']) ? ' has-right-sidebar' : '') . '">' .
|
228 |
+
'<div id="side-info-column" class="inner-sidebar">';
|
229 |
+
do_meta_boxes($this->pagehook, 'side', '');
|
230 |
+
|
231 |
+
echo '</div>' .
|
232 |
+
'<div id="post-body" class="has-sidebar">' .
|
233 |
+
'<div id="post-body-content" class="has-sidebar-content"> ';
|
234 |
+
|
235 |
+
do_meta_boxes($this->pagehook, 'normal', '');
|
236 |
+
/* Maybe add static content here later */
|
237 |
+
//do_meta_boxes($this->pagehook, 'additional', $data);
|
238 |
+
|
239 |
+
echo '<p>' .
|
240 |
+
'<input type="submit" value="Save Changes" class="button-primary" name="Submit"/>' .
|
241 |
+
'</p>' .
|
242 |
+
'</div>' .
|
243 |
+
'</div>' .
|
244 |
+
'<br class="clear"/>' .
|
245 |
+
'</div>' .
|
246 |
+
'</form>' .
|
247 |
+
'</div>' .
|
248 |
+
'<script type="text/javascript">' . "\n" .
|
249 |
+
'//<![CDATA[' . "\n" .
|
250 |
+
'jQuery(document).ready( function($) {';
|
251 |
+
// close postboxes that should be closed
|
252 |
+
echo "$('.if-js-closed').removeClass('if-js-closed').addClass('closed');";
|
253 |
+
// postboxes setup
|
254 |
+
echo "postboxes.add_postbox_toggles('" . $this->pagehook . "');" .
|
255 |
+
'}); ' . "\n" .
|
256 |
+
'//]]>' . "\n" .
|
257 |
+
'</script>';
|
|
|
|
|
|
|
|
|
|
|
258 |
}
|
259 |
|
260 |
+
// executed if the post arrives initiated by pressing the submit button of form
|
261 |
function on_save_changes() {
|
262 |
+
//user permission check
|
263 |
+
if (!current_user_can('manage_options')) wp_die(__('Problems?'));
|
264 |
+
// cross check the given referer
|
265 |
+
check_admin_referer(TR_NONCE);
|
266 |
+
|
267 |
+
// process here your on $_POST validation and / or option saving
|
268 |
+
$this->transposh->widget->transposh_widget_post(FALSE);
|
269 |
+
$this->update_admin_options();
|
270 |
+
|
271 |
+
// lets redirect the post request into get request (you may add additional params at the url, if you need to show save results
|
272 |
+
wp_redirect($_POST['_wp_http_referer']);
|
|
|
273 |
}
|
274 |
|
275 |
+
// below you will find for each registered metabox the callback method, that produces the content inside the boxes
|
276 |
+
// i did not describe each callback dedicated, what they do can be easily inspected and compare with the admin page displayed
|
277 |
|
278 |
function on_sidebox_about_content($data) {
|
279 |
+
echo '<ul style="list-style-type:disc;margin-left:20px;">';
|
280 |
+
echo '<li><a href="http://transposh.org/">Plugin Homepage</a></li>';
|
281 |
+
echo '<li><a href="http://transposh.org/redir/newfeature">Suggest a Feature</a></li>';
|
282 |
+
// support Forum
|
283 |
+
echo '<li><a href="http://transposh.org/redir/newticket">Report a Bug</a></li>';
|
284 |
+
// donate with PayPal
|
285 |
+
echo '</ul>';
|
286 |
}
|
287 |
|
288 |
function on_sidebox_widget_content($data) {
|
289 |
+
$this->transposh->widget->transposh_widget_control();
|
290 |
}
|
291 |
|
292 |
function on_sidebox_news_content($data) {
|
293 |
+
require_once(ABSPATH . WPINC . '/rss.php');
|
294 |
+
|
295 |
+
// ugly hack copy of RSS because of Unicode chars misprinting
|
296 |
+
function wp_rss2($url, $num_items = -1) {
|
297 |
+
if ($rss = fetch_rss($url)) {
|
298 |
+
echo '<ul>';
|
299 |
+
|
300 |
+
if ($num_items !== -1) {
|
301 |
+
$rss->items = array_slice($rss->items, 0, $num_items);
|
302 |
+
}
|
303 |
+
|
304 |
+
foreach ((array) $rss->items as $item) {
|
305 |
+
printf(
|
306 |
+
'<li><a href="%1$s" title="%2$s">%3$s</a></li>',
|
307 |
+
//esc_url( $item['link'] ),
|
308 |
+
//esc_attr( strip_tags( $item['description'] ) ),
|
309 |
+
// TODO - check Switched to 2.7 compatability functions
|
310 |
+
clean_url($item['link']),
|
311 |
+
attribute_escape(strip_tags($item['description'])),
|
312 |
+
htmlentities($item['title'], ENT_COMPAT, 'UTF-8')
|
313 |
+
);
|
314 |
+
}
|
315 |
+
|
316 |
+
echo '</ul>';
|
317 |
+
} else {
|
318 |
+
_e('An error has occurred, which probably means the feed is down. Try again later.');
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
echo '<div style="margin:6px">';
|
323 |
+
wp_rss2('http://feeds2.feedburner.com/transposh', 5);
|
324 |
+
echo '</div>';
|
325 |
}
|
326 |
|
327 |
function on_sidebox_stats_content($data) {
|
328 |
+
$this->transposh->database->db_stats();
|
329 |
}
|
330 |
|
331 |
function on_sidebox_translate_content($data) {
|
332 |
+
echo '<div id="progress_bar_all"></div><div id="tr_translate_title"></div>';
|
333 |
+
echo '<div id="tr_loading" style="margin: 0 0 10px 0">Translate by clicking the button below</div>';
|
334 |
+
echo '<a id="transposh-translate" href="' . $this->transposh->post_url . '?translate_all&offset=1" onclick="return false;" class="button">Translate All Now</a><br/>';
|
335 |
+
//get_posts
|
336 |
}
|
337 |
|
338 |
/**
|
340 |
* @param string $data
|
341 |
*/
|
342 |
function on_contentbox_languages_content($data) {
|
343 |
+
// we need some styles
|
344 |
+
echo '<style type="text/css">
|
345 |
#sortable { list-style-type: none; margin: 0; padding: 0; }
|
346 |
#sortable li, #default_lang li { margin: 3px 3px 3px 0; padding: 5px; float: left; width: 190px; height: 14px;}
|
347 |
.languages {
|
384 |
}
|
385 |
</style>';
|
386 |
|
387 |
+
// this is the default language location
|
388 |
+
list ($langname, $langorigname, $flag) = explode(",", $GLOBALS['languages'][$this->transposh->options->get_default_language()]);
|
389 |
+
echo '<div id="default_lang" style="overflow:auto;padding-bottom:10px;">Default Language (drag another language here to make it default)';
|
390 |
+
echo '<ul id="default_list"><li id="' . $this->transposh->options->get_default_language() . '" class="languages">'
|
391 |
+
. display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, $langorigname, false/* $this->transposh->options->get_widget_css_flags() */)
|
392 |
+
. '<input type="hidden" name="languages[]" value="' . $this->transposh->options->get_default_language() . '" />'
|
393 |
+
. ' <span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></li>';
|
394 |
+
echo '</ul></div>';
|
395 |
+
// list of languages
|
396 |
+
echo '<div style="overflow:auto; clear: both;">Available Languages (Click to toggle language state - Drag to sort in the widget)';
|
397 |
+
echo '<ul id="sortable">';
|
398 |
+
foreach ($this->transposh->options->get_sorted_langs() as $langcode => $langrecord) {
|
399 |
+
list ($langname, $langorigname, $flag) = explode(",", $langrecord);
|
400 |
+
echo '<li id="' . $langcode . '" class="languages ' . ($this->transposh->options->is_viewable_language($langcode) || $this->transposh->options->is_default_language($langcode) ? "active" : "")
|
401 |
+
. (!$this->transposh->options->is_viewable_language($langcode) && $this->transposh->options->is_editable_language($langcode) ? "translateable" : "") . '"><div style="float:left">'
|
402 |
+
. display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, false /* $langorigname,$this->transposh->options->get_widget_css_flags() */)
|
403 |
+
. '<input type="hidden" name="languages[]" value="' . $langcode . ($this->transposh->options->is_viewable_language($langcode) ? ",v" : ",") . ($this->transposh->options->is_viewable_language($langcode) ? ",t" : ",") . '" />'
|
404 |
+
. ' <span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></div>';
|
405 |
+
if (in_array($langcode, $GLOBALS['google_languages']))
|
406 |
+
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"/>';
|
407 |
+
if (in_array($langcode, $GLOBALS['bing_languages']))
|
408 |
+
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"/>';
|
409 |
+
if (in_array($langcode, $GLOBALS['rtl_languages']))
|
410 |
+
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"/>';
|
411 |
+
echo '</li>';
|
412 |
+
}
|
413 |
+
echo "</ul></div>";
|
414 |
+
// options to play with
|
415 |
+
echo '<div style="clear: both;">Display options:<br/><ul style="list-style-type: disc; margin-left: 20px;font-size:11px">';
|
416 |
+
echo '<li><a href="#" id="changename">Toggle names of languages between English and Original</a></li>';
|
417 |
+
echo '<li><a href="#" id="selectall">Make all languages active</a></li>';
|
418 |
+
echo '<li><a href="#" id="sortname">Sort by language name</a></li>';
|
419 |
+
echo '<li><a href="#" id="sortiso">Sort by lSO code</a></li></ul>';
|
420 |
+
echo 'Legend: Green - active, <span id="yellowcolor"' . ($this->transposh->options->get_anonymous_translation() ? ' class ="hidden"' : '') . '>Yellow - translateable (only translators will see this language), </span>blank - inactive';
|
421 |
+
echo '</div>';
|
422 |
}
|
423 |
|
424 |
/**
|
427 |
* @return string used for checkboxes
|
428 |
*/
|
429 |
private function checked($eval) {
|
430 |
+
return $eval ? 'checked="checked"' : '';
|
431 |
}
|
432 |
|
433 |
function on_contentbox_translation_content($data) {
|
434 |
+
/*
|
435 |
+
* Insert permissions section in the admin page
|
436 |
+
*/
|
437 |
+
echo '<h4>Who can translate ?</h4>';
|
438 |
+
//display known roles and their permission to translate
|
439 |
+
foreach ($GLOBALS['wp_roles']->get_names() as $role_name => $something) {
|
440 |
+
echo '<input type="checkbox" value="1" name="' . $role_name . '" ' . $this->can_translate($role_name) .
|
441 |
+
'/> ' . ucfirst($role_name) . ' ';
|
442 |
+
}
|
443 |
+
//Add our own custom role
|
444 |
+
echo '<input id="tr_anon" type="checkbox" value="1" name="anonymous" ' . $this->can_translate('anonymous') . '/> Anonymous';
|
445 |
+
|
446 |
+
/*
|
447 |
+
* Insert the option to enable/disable default language translation.
|
448 |
+
* Disabled by default.
|
449 |
+
*/
|
450 |
+
echo '<h4>Enable default language translation</h4>';
|
451 |
+
echo '<input type="checkbox" value="1" name="' . ENABLE_DEFAULT_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_default_translate()) . '/> ' .
|
452 |
+
'Allow translation of default language - useful for sites with more than one major language';
|
453 |
+
|
454 |
+
/**
|
455 |
+
* Insert the option to enable search in translated languages
|
456 |
+
* Enabled by default.
|
457 |
+
* @since 0.3.6
|
458 |
+
*/
|
459 |
+
echo '<h4>Enable search in translated languages</h4>';
|
460 |
+
echo '<input type="checkbox" value="1" name="' . ENABLE_SEARCH_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_search_translate()) . '/> ' .
|
461 |
+
'Allow search of translated languages, in those languages (and the original language)';
|
462 |
+
|
463 |
+
/**
|
464 |
+
* Insert the option to enable translation of urls
|
465 |
+
* Disbaled by default.
|
466 |
+
* @since 0.5.3
|
467 |
+
*/
|
468 |
+
echo '<h4>Enable url translation (experimental)</h4>';
|
469 |
+
echo '<input type="checkbox" value="1" name="' . ENABLE_URL_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_url_translate()) . '/> ' .
|
470 |
+
'Allow translation of permalinks and urls';
|
|
|
471 |
}
|
472 |
|
473 |
function on_contentbox_auto_translation_content($data) {
|
474 |
|
475 |
+
/*
|
476 |
+
* Insert the option to enable/disable automatic translation.
|
477 |
+
* Enabled by default.
|
478 |
+
*/
|
479 |
+
echo '<h4>Enable automatic translation</h4>';
|
480 |
+
echo '<input type="checkbox" value="1" name="' . ENABLE_AUTO_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_auto_translate()) . '/> ' .
|
481 |
+
'Allow automatic translation of pages';
|
482 |
+
|
483 |
+
/**
|
484 |
+
* Insert the option to enable/disable automatic translation upon publishing.
|
485 |
+
* Disabled by default.
|
486 |
+
* @since 0.3.5 */
|
487 |
+
echo '<h4>New - Enable automatic translation after posting</h4>';
|
488 |
+
echo '<input type="checkbox" value="1" name="' . ENABLE_AUTO_POST_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_auto_post_translate()) . '/> ' .
|
489 |
+
'Do automatic translation immediately after a post has been published';
|
490 |
+
|
491 |
+
/*
|
492 |
+
* Insert the option to enable/disable msn translations.
|
493 |
+
* Disabled by default because an API key is needed.
|
494 |
+
*/
|
495 |
+
echo '<h4>Support for Bing (MSN) translation</h4>';
|
496 |
+
echo '<input type="checkbox" value="1" name="' . ENABLE_MSN_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_msn_translate()) . '/> ' .
|
497 |
+
'Support MSN (Bing) translator (get key from <a href="http://www.microsofttranslator.com/Dev/Ajax/Default.aspx">here</a>)<br/>' .
|
498 |
+
'Key: <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_msn_key() . '" id="' . MSN_TRANSLATE_KEY . '" name="' . MSN_TRANSLATE_KEY . '"/>';
|
499 |
+
|
500 |
+
/*
|
501 |
+
* TODO - Change to v2 API and our key...
|
502 |
+
*/
|
503 |
+
echo '<h4>Select preferred auto translation engine</h4>';
|
504 |
+
echo '<label for="' . PREFERRED_TRANSLATOR . '">Translation engine:' .
|
505 |
+
'<select name="' . PREFERRED_TRANSLATOR . '">' .
|
506 |
+
'<option value="1"' . ($this->transposh->options->get_preferred_translator() == 1 ? ' selected="selected"' : '') . '>Google</option>' .
|
507 |
+
'<option value="2"' . ($this->transposh->options->get_preferred_translator() == 2 ? ' selected="selected"' : '') . '>Bing</option>' .
|
508 |
+
'</select>' .
|
509 |
+
'</label>';
|
|
|
510 |
}
|
511 |
|
512 |
function on_contentbox_generic_content($data) {
|
513 |
+
/*
|
514 |
+
* Insert the option to enable/disable rewrite of perlmalinks.
|
515 |
+
* When disabled only parameters will be used to identify the current language.
|
516 |
+
*/
|
517 |
+
echo '<h4>Rewrite URLs</h4>';
|
518 |
+
echo '<input type="checkbox" value="1" name="' . ENABLE_PERMALINKS . '" ' . $this->checked($this->transposh->options->get_enable_permalinks()) . '/> ' .
|
519 |
+
'Rewrite URLs to be search engine friendly, ' .
|
520 |
+
'e.g. (http://wordpress.org/<strong>en</strong>). ' .
|
521 |
+
'Requires that permalinks will be enabled.';
|
522 |
+
|
523 |
+
/*
|
524 |
+
* Insert the option to enable/disable pushing of scripts to footer.
|
525 |
+
* Works on wordpress 2.8 and up
|
526 |
+
*/
|
527 |
+
if (floatval($GLOBALS['wp_version']) >= 2.8) {
|
528 |
+
echo '<h4>Add scripts to footer</h4>';
|
529 |
+
echo '<input type="checkbox" value="1" name="' . ENABLE_FOOTER_SCRIPTS . '" ' . $this->checked($this->transposh->options->get_enable_footer_scripts()) . '/> ' .
|
530 |
+
'Push transposh scripts to footer of page instead of header, makes pages load faster. ' .
|
531 |
+
'Requires that your theme should have proper footer support.';
|
532 |
+
}
|
533 |
+
|
534 |
+
/**
|
535 |
+
* Insert the option to enable/disable language auto-detection
|
536 |
+
* @since 0.3.8 */
|
537 |
+
echo '<h4>Auto detect language for users</h4>';
|
538 |
+
echo '<input type="checkbox" value="1" name="' . ENABLE_DETECT_LANG_AND_REDIRECT . '" ' . $this->checked($this->transposh->options->get_enable_detect_language()) . '/> ' .
|
539 |
+
'This enables auto detection of language used by the user as defined in the ACCEPT_LANGUAGES they send. ' .
|
540 |
+
'This will redirect the first page accessed in the session to the same page with the detected language.';
|
541 |
+
|
542 |
+
/* WIP2
|
543 |
+
echo '<a href="http://transposh.org/services/index.php?flags='.$flags.'">Gen sprites</a>'; */
|
544 |
}
|
545 |
|
546 |
function on_contentbox_community_content($data) {
|
547 |
+
echo '<h4>Backup service for human translation</h4>';
|
548 |
+
echo '<input type="radio" value="1" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 1) . '/>Enable daily backup<br/>';
|
549 |
+
echo '<input type="radio" value="2" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 2) . '/>Enable live backup<br/>';
|
550 |
+
echo '<input type="radio" value="0" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 0) . '/>Disable backup (Can be run manually by clicking the button below)<br/>';
|
551 |
+
echo 'Service Key: <input type="text" size="32" class="regular-text" value="' . $this->transposh->options->get_transposh_key() . '" id="' . TRANSPOSH_KEY . '" name="' . TRANSPOSH_KEY . '"/> <a target="_blank" href="http://transposh.org/faq/#restore">How to restore?</a><br/>';
|
552 |
+
echo '<div id="backup_result"></div>';
|
553 |
+
echo '<div style="margin:10px 0"><a id="transposh-backup" href="#" class="button">Do Backup Now</a></div>';
|
554 |
}
|
|
|
555 |
|
556 |
+
}
|
557 |
?>
|
wp/transposh_ajax.php
CHANGED
@@ -1,24 +1,25 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*/
|
18 |
|
19 |
/*
|
20 |
* This file handles various AJAX needs of our plugin
|
21 |
-
*/
|
22 |
// The following headers allow for cross-domain posting here, which is useful for some weird sites
|
23 |
header('Access-Control-Allow-Origin: *');
|
24 |
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
@@ -34,8 +35,11 @@ if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
|
|
34 |
$root = $_SERVER["DOCUMENT_ROOT"];
|
35 |
$self = $_SERVER["SCRIPT_NAME"];
|
36 |
// go down 4 dirs...
|
37 |
-
for ($i = 0
|
38 |
-
|
|
|
|
|
|
|
39 |
// fallback plan
|
40 |
require_once('../../../../wp-load.php');
|
41 |
}
|
@@ -43,46 +47,45 @@ if (!@require_once $root.$self.'/wp-load.php') {
|
|
43 |
if (isset($_POST['translation_posted'])) {
|
44 |
// supercache invalidation of pages - first lets find if supercache is here
|
45 |
if (function_exists('wp_super_cache_init')) {
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
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 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
83 |
|
84 |
if ($_POST['translation_posted'] == 2) {
|
85 |
-
|
86 |
}
|
87 |
}
|
88 |
// getting translation history
|
@@ -95,29 +98,28 @@ elseif (isset($_GET['tr_phrases_post'])) {
|
|
95 |
}
|
96 |
// set the cookie with ajax, no redirect needed
|
97 |
elseif (isset($_GET['tr_cookie'])) {
|
98 |
-
setcookie('TR_LNG',get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url),time()+90*24*60*60,COOKIEPATH,COOKIE_DOMAIN);
|
99 |
|
100 |
}
|
101 |
// Set our cookie and return (if no js works - or we are in the default language)
|
102 |
elseif (isset($_GET['tr_cookie_bck'])) {
|
103 |
-
setcookie('TR_LNG',get_language_from_url($_SERVER['HTTP_REFERER'], $my_transposh_plugin->home_url),time()+90*24*60*60,COOKIEPATH,COOKIE_DOMAIN);
|
104 |
if ($_SERVER['HTTP_REFERER']) {
|
105 |
-
|
106 |
} else {
|
107 |
-
|
108 |
}
|
109 |
}
|
110 |
// Start full translation
|
111 |
elseif (isset($_GET['translate_all'])) {
|
112 |
// get all ids in need of translation
|
113 |
-
$page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type='page' OR post_type='post' ORDER BY ID DESC");
|
114 |
// only high capabilities users can...
|
115 |
-
if (!current_user_can('edit_post'
|
116 |
echo json_encode($page_ids);
|
117 |
}
|
118 |
// Start backup on demand
|
119 |
elseif (isset($_GET['backup'])) {
|
120 |
$my_transposh_plugin->run_backup();
|
121 |
}
|
122 |
-
|
123 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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 |
* This file handles various AJAX needs of our plugin
|
22 |
+
*/
|
23 |
// The following headers allow for cross-domain posting here, which is useful for some weird sites
|
24 |
header('Access-Control-Allow-Origin: *');
|
25 |
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
35 |
$root = $_SERVER["DOCUMENT_ROOT"];
|
36 |
$self = $_SERVER["SCRIPT_NAME"];
|
37 |
// go down 4 dirs...
|
38 |
+
for ($i = 0; $i < 5; $i++)
|
39 |
+
$self = substr($self, 0, -strlen(strrchr($self, '/')));
|
40 |
+
if (file_exists($root . $self . '/wp-load.php')) {
|
41 |
+
require_once $root . $self . '/wp-load.php';
|
42 |
+
} else {
|
43 |
// fallback plan
|
44 |
require_once('../../../../wp-load.php');
|
45 |
}
|
47 |
if (isset($_POST['translation_posted'])) {
|
48 |
// supercache invalidation of pages - first lets find if supercache is here
|
49 |
if (function_exists('wp_super_cache_init')) {
|
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
|
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 {
|
110 |
+
wp_redirect($my_transposh_plugin->home_url);
|
111 |
}
|
112 |
}
|
113 |
// Start full translation
|
114 |
elseif (isset($_GET['translate_all'])) {
|
115 |
// get all ids in need of translation
|
116 |
+
$page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_status='publish' OR post_status='private') ORDER BY ID DESC");
|
117 |
// only high capabilities users can...
|
118 |
+
if (!current_user_can('edit_post', $page_ids[0])) return;
|
119 |
echo json_encode($page_ids);
|
120 |
}
|
121 |
// Start backup on demand
|
122 |
elseif (isset($_GET['backup'])) {
|
123 |
$my_transposh_plugin->run_backup();
|
124 |
}
|
|
|
125 |
?>
|
wp/transposh_backup.php
CHANGED
@@ -1,95 +1,101 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
*
|
18 |
* adapted metabox sample code from http://www.code-styling.de/
|
19 |
-
*/
|
20 |
|
21 |
/*
|
22 |
* Provide the backup service class
|
23 |
-
*/
|
|
|
|
|
24 |
|
25 |
-
define ("TRANSPOSH_BACKUP_SERVICE_URL" , "http://svc.transposh.org/backup");
|
26 |
//define ("TRANSPOSH_BACKUP_SERVICE_URL" , "http://ofergen:8888/backup");
|
27 |
//class that reperesent the admin page
|
28 |
class transposh_backup {
|
|
|
29 |
/** @var transposh_plugin $transposh father class */
|
30 |
private $transposh;
|
|
|
31 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
32 |
function transposh_backup(&$transposh) {
|
33 |
-
|
34 |
}
|
35 |
|
36 |
function do_backup() {
|
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 |
}
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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 |
* adapted metabox sample code from http://www.code-styling.de/
|
20 |
+
*/
|
21 |
|
22 |
/*
|
23 |
* Provide the backup service class
|
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
|
30 |
class transposh_backup {
|
31 |
+
|
32 |
/** @var transposh_plugin $transposh father class */
|
33 |
private $transposh;
|
34 |
+
|
35 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
36 |
function transposh_backup(&$transposh) {
|
37 |
+
$this->transposh = &$transposh;
|
38 |
}
|
39 |
|
40 |
function do_backup() {
|
41 |
+
$body = array();
|
42 |
+
$body["home_url"] = $this->transposh->home_url;
|
43 |
+
$body["key"] = $this->transposh->options->get_transposh_key();
|
44 |
+
//Check if there are thing to backup, before even accessing the service
|
45 |
+
$rowstosend = $this->transposh->database->get_all_human_translation_history('null', 1);
|
46 |
+
if (empty($rowstosend)) {
|
47 |
+
echo "500 - No human translations to backup.";
|
48 |
+
return;
|
49 |
+
}
|
50 |
|
51 |
+
$result = wp_remote_post(TRANSPOSH_BACKUP_SERVICE_URL, array('body' => $body));
|
52 |
+
if (is_wp_error($result)) {
|
53 |
+
echo '500 - ' . $result->get_error_message();
|
54 |
+
return;
|
55 |
+
}
|
56 |
+
if ($result['headers']['fail']) {
|
57 |
+
echo '500 - ' . $result['headers']['fail'];
|
58 |
+
return;
|
59 |
+
}
|
60 |
+
if ($this->transposh->options->get_transposh_key() == "") {
|
61 |
+
$this->transposh->options->set_transposh_key($result['headers']['transposh-key']);
|
62 |
+
// TODO: deliever new gottenkey to client side?
|
63 |
+
//echo $this->transposh->options->get_transposh_key();
|
64 |
+
$this->transposh->options->update_options();
|
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 |
}
|
wp/transposh_db.php
CHANGED
@@ -1,20 +1,21 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*/
|
18 |
|
19 |
|
20 |
/**
|
@@ -22,28 +23,30 @@
|
|
22 |
* This implementation for use with mysql within wordpress
|
23 |
*
|
24 |
*/
|
25 |
-
|
26 |
//
|
27 |
//Constants
|
28 |
//
|
29 |
-
|
30 |
//Table name in database for storing translations
|
31 |
-
define(
|
32 |
-
define(
|
33 |
|
34 |
//Database version
|
35 |
-
define(
|
36 |
|
37 |
//Constant used as key in options database
|
38 |
-
define(
|
39 |
|
40 |
class transposh_database {
|
41 |
-
|
|
|
42 |
private $transposh;
|
43 |
private $translations;
|
44 |
-
|
|
|
|
|
|
|
45 |
function transposh_database(&$transposh) {
|
46 |
-
|
47 |
}
|
48 |
|
49 |
/**
|
@@ -52,27 +55,27 @@ class transposh_database {
|
|
52 |
* @param string $lang
|
53 |
*/
|
54 |
function prefetch_translations($originals, $lang) {
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
}
|
77 |
|
78 |
/**
|
@@ -84,53 +87,53 @@ class transposh_database {
|
|
84 |
* @return array list(translation,source)
|
85 |
*/
|
86 |
function fetch_translation($original, $lang) {
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
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 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
}
|
135 |
|
136 |
/**
|
@@ -142,52 +145,51 @@ class transposh_database {
|
|
142 |
* @return array list(translation,source)
|
143 |
*/
|
144 |
function fetch_original($translation, $lang) {
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
return $original;
|
191 |
}
|
192 |
|
193 |
/**
|
@@ -199,200 +201,198 @@ class transposh_database {
|
|
199 |
*/
|
200 |
function update_translation() {
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
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 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
$this->transposh->run_backup();
|
329 |
-
}
|
330 |
-
// this is a termination for the ajax sequence
|
331 |
-
exit;
|
332 |
}
|
333 |
|
334 |
/*
|
335 |
-
|
336 |
-
|
|
|
337 |
function get_translation_history($token, $lang) {
|
338 |
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
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 |
-
|
395 |
-
|
|
|
396 |
}
|
397 |
|
398 |
/**
|
@@ -402,60 +402,61 @@ class transposh_database {
|
|
402 |
*/
|
403 |
function get_all_human_translation_history($date ="null", $limit = "") {
|
404 |
|
405 |
-
|
406 |
-
|
407 |
|
408 |
-
|
409 |
// header("Transposh: v-".TRANSPOSH_PLUGIN_VER." db_version-". DB_VERSION);
|
410 |
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
|
419 |
-
|
420 |
-
|
421 |
}
|
422 |
|
423 |
/*
|
424 |
-
|
425 |
-
|
|
|
426 |
function setup_db() {
|
427 |
-
|
428 |
-
|
429 |
|
430 |
-
|
431 |
|
432 |
-
|
433 |
-
|
434 |
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
original TEXT NOT NULL,
|
440 |
lang CHAR(5) NOT NULL,
|
441 |
translated TEXT,
|
442 |
source TINYINT NOT NULL,
|
443 |
KEY original (original(6),lang)
|
444 |
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
|
451 |
-
|
452 |
|
453 |
-
|
454 |
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
original text NOT NULL,
|
460 |
lang CHAR(5) NOT NULL,
|
461 |
translated text,
|
@@ -464,49 +465,49 @@ class transposh_database {
|
|
464 |
timestamp TIMESTAMP,
|
465 |
KEY original (original(6),lang,timestamp)
|
466 |
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
}
|
481 |
|
482 |
-
function db_stats
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
}
|
511 |
|
512 |
/**
|
@@ -516,37 +517,38 @@ class transposh_database {
|
|
516 |
* @return array Original phrases in which $term appears
|
517 |
*/
|
518 |
function get_orignal_phrases_for_search_term($term, $language) {
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
FROM `$table_name`
|
524 |
WHERE `lang` LIKE '$language'
|
525 |
AND `translated` LIKE '{$n}{$term}{$n}'";
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
}
|
|
|
551 |
}
|
552 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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 |
/**
|
23 |
* This implementation for use with mysql within wordpress
|
24 |
*
|
25 |
*/
|
|
|
26 |
//
|
27 |
//Constants
|
28 |
//
|
|
|
29 |
//Table name in database for storing translations
|
30 |
+
define('TRANSLATIONS_TABLE', 'translations');
|
31 |
+
define('TRANSLATIONS_LOG', 'translations_log');
|
32 |
|
33 |
//Database version
|
34 |
+
define('DB_VERSION', '1.04');
|
35 |
|
36 |
//Constant used as key in options database
|
37 |
+
define('TRANSPOSH_DB_VERSION', "transposh_db_version");
|
38 |
|
39 |
class transposh_database {
|
40 |
+
|
41 |
+
/** @var transposh_plugin father class */
|
42 |
private $transposh;
|
43 |
private $translations;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* constructor of class, PHP4 compatible construction for backward compatibility
|
47 |
+
*/
|
48 |
function transposh_database(&$transposh) {
|
49 |
+
$this->transposh = &$transposh;
|
50 |
}
|
51 |
|
52 |
/**
|
55 |
* @param string $lang
|
56 |
*/
|
57 |
function prefetch_translations($originals, $lang) {
|
58 |
+
if (!$originals) return;
|
59 |
+
foreach ($originals as $original) {
|
60 |
+
$original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
|
61 |
+
if (ENABLE_APC && function_exists('apc_fetch')) {
|
62 |
+
$cached = apc_fetch($original . '___' . $lang, $rc);
|
63 |
+
if ($rc === TRUE) {
|
64 |
+
|
65 |
+
continue;
|
66 |
+
}
|
67 |
+
}
|
68 |
+
$where .= ( ($where) ? ' OR ' : '') . "original = '$original'";
|
69 |
+
}
|
70 |
+
if (!$where) return;
|
71 |
+
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
|
72 |
+
$query = "SELECT original, translated, source FROM $table_name WHERE ($where) and lang = '$lang' ";
|
73 |
+
$rows = $GLOBALS['wpdb']->get_results($query, ARRAY_A);
|
74 |
+
if (empty($rows)) return;
|
75 |
+
foreach ($rows as $row) {
|
76 |
+
$this->translations[$row['original']] = array(stripslashes($row['translated']), $row['source']);
|
77 |
+
}
|
78 |
+
|
79 |
}
|
80 |
|
81 |
/**
|
87 |
* @return array list(translation,source)
|
88 |
*/
|
89 |
function fetch_translation($original, $lang) {
|
90 |
+
$translated = NULL;
|
91 |
+
|
92 |
+
|
93 |
+
//The original is saved in db in its escaped form
|
94 |
+
$original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
|
95 |
+
|
96 |
+
if (ENABLE_APC && function_exists('apc_fetch')) {
|
97 |
+
$cached = apc_fetch($original . '___' . $lang, $rc);
|
98 |
+
if ($rc === TRUE) {
|
99 |
+
|
100 |
+
return $cached;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
if ($this->translations[$original]) {
|
105 |
+
$translated = $this->translations[$original];
|
106 |
+
|
107 |
+
} else {
|
108 |
+
|
109 |
+
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
|
110 |
+
$query = "SELECT * FROM $table_name WHERE original = '$original' and lang = '$lang' ";
|
111 |
+
$row = $GLOBALS['wpdb']->get_row($query);
|
112 |
+
|
113 |
+
if ($row !== FALSE) {
|
114 |
+
$translated_text = stripslashes($row->translated);
|
115 |
+
$translated = array($translated_text, $row->source);
|
116 |
+
|
117 |
+
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
if (ENABLE_APC && function_exists('apc_store')) {
|
122 |
+
//If we don't have translation still we want to have it in cache
|
123 |
+
$cache_entry = $translated;
|
124 |
+
if ($cache_entry == NULL) {
|
125 |
+
$cache_entry = "";
|
126 |
+
}
|
127 |
+
|
128 |
+
//update cache
|
129 |
+
$rc = apc_store($original . '___' . $lang, $cache_entry, 3600);
|
130 |
+
if ($rc === TRUE) {
|
131 |
+
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
|
136 |
+
return $translated;
|
137 |
}
|
138 |
|
139 |
/**
|
145 |
* @return array list(translation,source)
|
146 |
*/
|
147 |
function fetch_original($translation, $lang) {
|
148 |
+
$original = NULL;
|
149 |
+
|
150 |
+
|
151 |
+
//The original is saved in db in its escaped form
|
152 |
+
$translation = $GLOBALS['wpdb']->escape(html_entity_decode($translation, ENT_NOQUOTES, 'UTF-8'));
|
153 |
+
|
154 |
+
if (ENABLE_APC && function_exists('apc_fetch')) {
|
155 |
+
$cached = apc_fetch($translation . '_r_r_' . $lang, $rc);
|
156 |
+
if ($rc === TRUE) {
|
157 |
+
|
158 |
+
return $cached;
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
if ($this->translations[$translation]) {
|
163 |
+
$original = $this->translations[$translation];
|
164 |
+
|
165 |
+
} else {
|
166 |
+
|
167 |
+
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
|
168 |
+
$query = "SELECT * FROM $table_name WHERE translated = '$translation' and lang = '$lang' ";
|
169 |
+
$row = $GLOBALS['wpdb']->get_row($query);
|
170 |
+
|
171 |
+
if ($row !== FALSE) {
|
172 |
+
$original = stripslashes($row->original);
|
173 |
+
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
if (ENABLE_APC && function_exists('apc_store')) {
|
178 |
+
//If we don't have translation still we want to have it in cache
|
179 |
+
$cache_entry = $original;
|
180 |
+
if ($cache_entry == NULL) {
|
181 |
+
$cache_entry = "";
|
182 |
+
}
|
183 |
+
|
184 |
+
//update cache
|
185 |
+
$rc = apc_store($translation . '_r_r_' . $lang, $cache_entry, 3600);
|
186 |
+
if ($rc === TRUE) {
|
187 |
+
|
188 |
+
}
|
189 |
+
}
|
190 |
+
|
191 |
+
|
192 |
+
return $original;
|
|
|
193 |
}
|
194 |
|
195 |
/**
|
201 |
*/
|
202 |
function update_translation() {
|
203 |
|
204 |
+
$ref = getenv('HTTP_REFERER');
|
205 |
+
$items = $_POST['items'];
|
206 |
+
$lang = $_POST['ln0'];
|
207 |
+
$source = $_POST['sr0'];
|
208 |
+
// check params
|
209 |
+
|
210 |
+
if (!isset($items) || !isset($lang)) {
|
211 |
+
|
212 |
+
return;
|
213 |
+
}
|
214 |
+
|
215 |
+
//Check permissions, first the lanugage must be on the edit list. Then either the user
|
216 |
+
//is a translator or automatic translation if it is enabled.
|
217 |
+
// we must check that all sent languages are editable
|
218 |
+
$all_editable = true;
|
219 |
+
for ($i = 0; $i < $items; $i++) {
|
220 |
+
if (isset($_POST["ln$i"])) {
|
221 |
+
if (!$this->transposh->options->is_editable_language($_POST["ln$i"])) {
|
222 |
+
$all_editable = false;
|
223 |
+
break;
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
if (!($all_editable &&
|
229 |
+
($this->transposh->is_translator() || ($source == 1 && $this->transposh->options->get_enable_auto_translate())))) {
|
230 |
+
|
231 |
+
header("HTTP/1.0 401 Unauthorized translation");
|
232 |
+
exit;
|
233 |
+
}
|
234 |
+
|
235 |
+
//add our own custom header - so we will know that we got here
|
236 |
+
header("Transposh: v-" . TRANSPOSH_PLUGIN_VER . " db_version-" . DB_VERSION);
|
237 |
+
|
238 |
+
// transaction log stuff
|
239 |
+
global $user_ID;
|
240 |
+
get_currentuserinfo();
|
241 |
+
|
242 |
+
// log either the user ID or his IP
|
243 |
+
if ('' == $user_ID) {
|
244 |
+
$loguser = $_SERVER['REMOTE_ADDR'];
|
245 |
+
} else {
|
246 |
+
$loguser = $user_ID;
|
247 |
+
}
|
248 |
+
// end tl
|
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'));
|
256 |
+
}
|
257 |
+
if (isset($_POST["tr$i"])) {
|
258 |
+
$translation = $_POST["tr$i"];
|
259 |
+
//Decode & remove already escaped character to avoid double escaping
|
260 |
+
$translation = $GLOBALS['wpdb']->escape(htmlspecialchars(stripslashes(urldecode($translation))));
|
261 |
+
}
|
262 |
+
if (isset($_POST["ln$i"])) {
|
263 |
+
$lang = $_POST["ln$i"];
|
264 |
+
}
|
265 |
+
if (isset($_POST["sr$i"])) {
|
266 |
+
$source = $_POST["sr$i"];
|
267 |
+
}
|
268 |
+
// should we backup?
|
269 |
+
if ($source == 0) $backup_immidiate_possible = true;
|
270 |
+
|
271 |
+
//Here we check we are not redoing stuff
|
272 |
+
list($translated_text, $old_source) = $this->fetch_translation($original, $lang);
|
273 |
+
if ($translated_text) {
|
274 |
+
if ($source > 0) {
|
275 |
+
|
276 |
+
continue;
|
277 |
+
//return; // too harsh, we just need to get to the next in for
|
278 |
+
}
|
279 |
+
if ($translation == $GLOBALS['wpdb']->escape(htmlspecialchars(stripslashes(urldecode($translated_text)))) && $old_source == $source) {
|
280 |
+
|
281 |
+
continue;
|
282 |
+
//return; // too harsh, we just need to get to the next in for
|
283 |
+
}
|
284 |
+
}
|
285 |
+
// Setting the values string for the database (notice how concatanation is handled)
|
286 |
+
$values .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $source . "')" . (($items != $i + 1) ? ', ' : '');
|
287 |
+
$delvalues .= "(original ='$original' AND lang='$lang')" . (($items != $i + 1) ? ' OR ' : '');
|
288 |
+
// Setting the transaction log records
|
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('apc_store')) {
|
293 |
+
apc_delete($original . '___' . $lang);
|
294 |
+
}
|
295 |
+
}
|
296 |
+
|
297 |
+
// avoid empty work
|
298 |
+
if (!$values) return;
|
299 |
+
// perform insertion to the database, with one query :)
|
300 |
+
// since we have no primary key, replace made no sense
|
301 |
+
/* $update = "REPLACE INTO ".$GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE." (original, translated, lang, source)
|
302 |
+
VALUES $values"; */
|
303 |
+
//so we'll delete all values and insert them...
|
304 |
+
$update = "DELETE FROM " . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . " WHERE $delvalues";
|
305 |
+
|
306 |
+
$result = $GLOBALS['wpdb']->query($update);
|
307 |
+
$update = "INSERT INTO " . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . " (original, translated, lang, source) VALUES $values";
|
308 |
+
|
309 |
+
$result = $GLOBALS['wpdb']->query($update);
|
310 |
+
|
311 |
+
if ($result !== FALSE) {
|
312 |
+
// update the transaction log too
|
313 |
+
$log = "INSERT INTO " . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG . " (original, translated, lang, translated_by, source) " .
|
314 |
+
"VALUES $logvalues";
|
315 |
+
$result = $GLOBALS['wpdb']->query($log);
|
316 |
+
|
317 |
+
|
318 |
+
} else {
|
319 |
+
|
320 |
+
|
321 |
+
header("HTTP/1.0 404 Failed to update language database " . mysql_error());
|
322 |
+
}
|
323 |
+
|
324 |
+
// Should we backup now?
|
325 |
+
if ($backup_immidiate_possible && $this->transposh->options->get_transposh_backup_schedule() == 2) {
|
326 |
+
$this->transposh->run_backup();
|
327 |
+
}
|
328 |
+
// this is a termination for the ajax sequence
|
329 |
+
exit;
|
|
|
|
|
|
|
|
|
330 |
}
|
331 |
|
332 |
/*
|
333 |
+
* Get translation history for some translation.
|
334 |
+
*/
|
335 |
+
|
336 |
function get_translation_history($token, $lang) {
|
337 |
|
338 |
+
$ref = getenv('HTTP_REFERER');
|
339 |
+
$original = base64_url_decode($token);
|
340 |
+
|
341 |
+
|
342 |
+
// check params
|
343 |
+
|
344 |
+
if (!isset($original) || !isset($lang)) {
|
345 |
+
|
346 |
+
return;
|
347 |
+
}
|
348 |
+
|
349 |
+
|
350 |
+
//Check permissions, first the lanugage must be on the edit list. Then either the user
|
351 |
+
//is a translator or automatic translation if it is enabled.
|
352 |
+
if (!($this->transposh->options->is_editable_language($lang) && $this->transposh->is_translator())) {
|
353 |
+
|
354 |
+
header('HTTP/1.0 401 Unauthorized history');
|
355 |
+
exit;
|
356 |
+
}
|
357 |
+
|
358 |
+
|
359 |
+
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;
|
360 |
+
|
361 |
+
|
362 |
+
//The original content is encoded as base64 before it is sent (i.e. token), after we
|
363 |
+
//decode it should just the same after it was parsed.
|
364 |
+
$original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
|
365 |
+
|
366 |
+
//add our own custom header - so we will know that we got here
|
367 |
+
header('Transposh: v-' . TRANSPOSH_PLUGIN_VER . ' db_version-' . DB_VERSION);
|
368 |
+
|
369 |
+
$query = "SELECT translated, translated_by, timestamp, source, user_login " .
|
370 |
+
"FROM $table_name " .
|
371 |
+
"LEFT JOIN {$GLOBALS['wpdb']->prefix}users ON translated_by = {$GLOBALS['wpdb']->prefix}users.id " .
|
372 |
+
"WHERE original='$original' AND lang='$lang' " .
|
373 |
+
"ORDER BY timestamp DESC";
|
374 |
+
|
375 |
+
|
376 |
+
$rows = $GLOBALS['wpdb']->get_results($query);
|
377 |
+
// trying
|
378 |
+
//header("Content-type: text/javascript");
|
379 |
+
//echo json_encode($rows);
|
380 |
+
if ($rows !== FALSE) {
|
381 |
+
echo '<table>' .
|
382 |
+
'<thead>' .
|
383 |
+
'<tr>' .
|
384 |
+
'<th>Translated</th><th/><th>By</th><th>At</th>' .
|
385 |
+
'</tr>' .
|
386 |
+
'</thead>' .
|
387 |
+
'<tbody>';
|
388 |
+
foreach ($rows as $row) {
|
389 |
+
if (is_null($row->user_login)) $row->user_login = $row->translated_by;
|
390 |
+
echo "<tr><td>{$row->translated}</td><td source=\"{$row->source}\"/><td user_id=\"{$row->translated_by}\">{$row->user_login}</td><td>{$row->timestamp}</td></tr>";
|
391 |
+
}
|
392 |
+
echo '</tbody></table>';
|
393 |
+
}
|
394 |
+
|
395 |
+
exit;
|
396 |
}
|
397 |
|
398 |
/**
|
402 |
*/
|
403 |
function get_all_human_translation_history($date ="null", $limit = "") {
|
404 |
|
405 |
+
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;
|
406 |
+
|
407 |
|
408 |
+
//add our own custom header - so we will know that we got here
|
409 |
// header("Transposh: v-".TRANSPOSH_PLUGIN_VER." db_version-". DB_VERSION);
|
410 |
|
411 |
+
if ($date != "null") $dateterm = "and UNIX_TIMESTAMP(timestamp) > $date";
|
412 |
+
if ($limit) $limitterm = "LIMIT $limit";
|
413 |
+
$query = "SELECT original, lang, translated, translated_by, UNIX_TIMESTAMP(timestamp) as timestamp " .
|
414 |
+
"FROM $table_name " .
|
415 |
+
"WHERE source= 0 $dateterm " .
|
416 |
+
"ORDER BY timestamp ASC $limitterm";
|
417 |
+
|
418 |
|
419 |
+
$rows = $GLOBALS['wpdb']->get_results($query);
|
420 |
+
return $rows;
|
421 |
}
|
422 |
|
423 |
/*
|
424 |
+
* Setup the translation database.
|
425 |
+
*/
|
426 |
+
|
427 |
function setup_db() {
|
428 |
+
|
429 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
430 |
|
431 |
+
$installed_ver = get_option(TRANSPOSH_DB_VERSION);
|
432 |
|
433 |
+
if ($installed_ver != DB_VERSION) {
|
434 |
+
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
|
435 |
|
436 |
+
|
437 |
+
// notice - keep every field on a new line or dbdelta fails
|
438 |
+
$GLOBALS['wpdb']->query("ALTER TABLE $table_name DROP PRIMARY KEY");
|
439 |
+
$sql = "CREATE TABLE $table_name (
|
440 |
original TEXT NOT NULL,
|
441 |
lang CHAR(5) NOT NULL,
|
442 |
translated TEXT,
|
443 |
source TINYINT NOT NULL,
|
444 |
KEY original (original(6),lang)
|
445 |
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
|
446 |
+
/* $sql = "CREATE TABLE $table_name (original VARCHAR(255) NOT NULL,".
|
447 |
+
"lang CHAR(5) NOT NULL,".
|
448 |
+
"translated VARCHAR(255),".
|
449 |
+
"source TINYINT NOT NULL,".
|
450 |
+
"PRIMARY KEY (original, lang)) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"; */
|
451 |
|
452 |
+
dbDelta($sql);
|
453 |
|
454 |
+
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;
|
455 |
|
456 |
+
|
457 |
+
// notice - keep every field on a new line or dbdelta fails
|
458 |
+
$GLOBALS['wpdb']->query("ALTER TABLE $table_name DROP PRIMARY KEY");
|
459 |
+
$sql = "CREATE TABLE $table_name (
|
460 |
original text NOT NULL,
|
461 |
lang CHAR(5) NOT NULL,
|
462 |
translated text,
|
465 |
timestamp TIMESTAMP,
|
466 |
KEY original (original(6),lang,timestamp)
|
467 |
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
|
468 |
+
/* $sql = "CREATE TABLE $table_name (original VARCHAR(255) NOT NULL,".
|
469 |
+
"lang CHAR(5) NOT NULL,".
|
470 |
+
"translated VARCHAR(255),".
|
471 |
+
"translated_by VARCHAR(15),".
|
472 |
+
"source TINYINT NOT NULL,".
|
473 |
+
"timestamp TIMESTAMP,".
|
474 |
+
"PRIMARY KEY (original, lang, timestamp)) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"; */
|
475 |
+
|
476 |
+
dbDelta($sql);
|
477 |
+
update_option(TRANSPOSH_DB_VERSION, DB_VERSION);
|
478 |
+
}
|
479 |
+
|
480 |
+
|
481 |
}
|
482 |
|
483 |
+
function db_stats() {
|
484 |
+
echo "<h4>Database stats</h4>";
|
485 |
+
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
|
486 |
+
$log_table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;
|
487 |
+
$query = "SELECT count(*) as count FROM `$table_name`";
|
488 |
+
$rows = $GLOBALS['wpdb']->get_results($query);
|
489 |
+
foreach ($rows as $row) {
|
490 |
+
if ($row->count)
|
491 |
+
echo "<p>Total of <strong style=\"color:red\">{$row->count}</strong> translated phrases.</p>";
|
492 |
+
}
|
493 |
+
|
494 |
+
$query = "SELECT count(*) as count,lang FROM `$table_name` WHERE source='0' GROUP BY `lang` ORDER BY `count` DESC LIMIT 3";
|
495 |
+
$rows = $GLOBALS['wpdb']->get_results($query);
|
496 |
+
foreach ($rows as $row) {
|
497 |
+
if ($row->count)
|
498 |
+
echo "<p><strong>{$row->lang}</strong> has <strong style=\"color:red\">{$row->count}</strong> human translated phrases.</p>";
|
499 |
+
}
|
500 |
+
|
501 |
+
echo "<h4>Recent activity</h4>";
|
502 |
+
$query = "SELECT * FROM `$log_table_name` WHERE source='0' ORDER BY `timestamp` DESC LIMIT 3";
|
503 |
+
$rows = $GLOBALS['wpdb']->get_results($query);
|
504 |
+
foreach ($rows as $row) {
|
505 |
+
$td = mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $row->timestamp);
|
506 |
+
//the_date();
|
507 |
+
echo "<p>On <strong>{$td}</strong><br/>user <strong>{$row->translated_by}</strong> translated<br/>" .
|
508 |
+
"\"<strong>{$row->original}</strong>\"<br/>to " .
|
509 |
+
"<strong style=\"color:red\">{$row->lang}</strong><br/>\"<strong>{$row->translated}</strong>\"</p>";
|
510 |
+
}
|
511 |
}
|
512 |
|
513 |
/**
|
517 |
* @return array Original phrases in which $term appears
|
518 |
*/
|
519 |
function get_orignal_phrases_for_search_term($term, $language) {
|
520 |
+
$table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;
|
521 |
+
$n = '%';
|
522 |
+
$term = addslashes_gpc($term);
|
523 |
+
$query = "SELECT original
|
524 |
FROM `$table_name`
|
525 |
WHERE `lang` LIKE '$language'
|
526 |
AND `translated` LIKE '{$n}{$term}{$n}'";
|
527 |
+
//TODO wait for feedbacks to see if we should put a limit here.
|
528 |
+
|
529 |
+
|
530 |
+
$result = array();
|
531 |
+
$rows = $GLOBALS['wpdb']->get_results($query);
|
532 |
+
|
533 |
+
foreach ($rows as $row) {
|
534 |
+
$addme = true;
|
535 |
+
// now lets use the a-priori for reduction
|
536 |
+
// two possibilities for reduction, new is included in old, or some old includes this new
|
537 |
+
foreach ($result as $k => $r) {
|
538 |
+
// if our original is included in a string in the result, that is no longer needed...
|
539 |
+
if (stripos($r, $row->original) !== false) {
|
540 |
+
unset($result[$k]);
|
541 |
+
}
|
542 |
+
// if the other way around is true, we won't have to add it
|
543 |
+
if (stripos($row->original, $r) !== false) {
|
544 |
+
$addme = false;
|
545 |
+
}
|
546 |
+
}
|
547 |
+
if ($addme) $result[] = $row->original;
|
548 |
+
}
|
549 |
+
|
550 |
+
return $result;
|
551 |
}
|
552 |
+
|
553 |
}
|
554 |
?>
|
wp/transposh_options.php
CHANGED
@@ -1,47 +1,30 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*/
|
18 |
// OLD Options - To be removed
|
19 |
-
//
|
20 |
-
|
21 |
-
//Option defining the list of currentlly viewable languages
|
22 |
-
define("OLD_VIEWABLE_LANGS", "transposh_viewable_languages");
|
23 |
-
//Option defining the list of currentlly editable languages
|
24 |
-
define("OLD_EDITABLE_LANGS", "transposh_editable_languages");
|
25 |
-
//Option to enable/disable auto translation
|
26 |
-
define("OLD_ENABLE_AUTO_TRANSLATE", "transposh_enable_autotranslate");
|
27 |
-
//Option to enable/disable msn translation
|
28 |
-
define("OLD_ENABLE_MSN_TRANSLATE", "transposh_enable_msntranslate");
|
29 |
-
//Option to store the msn API key
|
30 |
-
define("OLD_MSN_TRANSLATE_KEY", "transposh_msn_key");
|
31 |
-
//Option to enable/disable rewrite of permalinks
|
32 |
-
define("OLD_ENABLE_PERMALINKS_REWRITE", "transposh_enable_permalinks");
|
33 |
-
//Option to enable/disable default language translation
|
34 |
-
define("OLD_ENABLE_DEFAULT_TRANSLATE", "transposh_enable_default_translate");
|
35 |
-
//Option to enable/disable footer scripts (2.8 and up)
|
36 |
-
define("OLD_ENABLE_FOOTER_SCRIPTS", "transposh_enable_footer_scripts");
|
37 |
-
//Use CSS sprites for flags if available
|
38 |
-
define("OLD_ENABLE_CSS_FLAGS", "transposh_enable_css_flags");
|
39 |
-
//Option defining the default language
|
40 |
-
define("OLD_DEFAULT_LANG", "transposh_default_language");
|
41 |
//Option defining transposh widget appearance
|
42 |
-
define("
|
43 |
-
//
|
44 |
-
define("
|
|
|
|
|
45 |
|
46 |
//defines are used to avoid typos
|
47 |
//Option defining whether anonymous translation is allowed.
|
@@ -76,91 +59,68 @@ define("ENABLE_FOOTER_SCRIPTS", "enable_footer_scripts");
|
|
76 |
define("ENABLE_DETECT_LANG_AND_REDIRECT", "enable_detect_redirect");
|
77 |
//Option defining the default language
|
78 |
define("DEFAULT_LANG", "default_language");
|
79 |
-
//Option defining transposh widget
|
80 |
-
define("
|
81 |
//Option allowing progress bar display
|
82 |
define("WIDGET_PROGRESSBAR", "widget_progressbar");
|
83 |
-
//Use CSS sprites for flags if available
|
84 |
-
define("WIDGET_CSS_FLAGS", "widget_css_flags");
|
85 |
-
//Wrap widget elements in an unordered list per #63 @since 0.3.7
|
86 |
-
define("WIDGET_IN_LIST", "widget_in_list");
|
87 |
//Allows user to set his default language per #63 @since 0.3.8
|
88 |
define("WIDGET_ALLOW_SET_DEFLANG", "widget_allow_set_deflang");
|
89 |
//Stores the site key to transposh services (backup @since 0.5.0)
|
90 |
-
define("TRANSPOSH_KEY","transposh_key");
|
91 |
//Stores the site key to transposh services (backup @since 0.5.0)
|
92 |
-
define("TRANSPOSH_BACKUP_SCHEDULE","transposh_backup_schedule");
|
93 |
-
|
94 |
|
95 |
class transposh_plugin_options {
|
96 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
|
|
97 |
/** @var array storing all our options */
|
98 |
private $options = array();
|
99 |
/** @var boolean set to true if any option was changed */
|
100 |
private $changed = false;
|
101 |
|
102 |
function transposh_plugin_options() {
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
}
|
109 |
|
110 |
-
private function old2new($key) {
|
111 |
-
// the substr removes the redundant transposh_ prefix
|
112 |
-
$this->options[substr($key,10)] = get_option($key);
|
113 |
-
delete_option($key);
|
114 |
-
}
|
115 |
// TODO: remove this function in a few versions (fix css, db version..., css flag
|
116 |
private function migrate_old_config() {
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
if (isset($this->options['widget'])) {
|
138 |
-
|
139 |
-
$this->set_widget_style($this->options['widget']['style']);
|
140 |
-
$this->set_widget_progressbar($this->options['widget']['progressbar']);
|
141 |
-
unset($this->options['widget']);
|
142 |
-
|
143 |
-
}
|
144 |
-
if (is_array($this->options) && array_key_exists('enable_css_flags',$this->options)) {
|
145 |
-
$this->set_widget_css_flags($this->options['enable_css_flags']);
|
146 |
-
unset($this->options['enable_css_flags']);
|
147 |
-
|
148 |
-
}
|
149 |
-
// this has deprecated at 0.3.9
|
150 |
-
unset ($this->options[OLD_ALTERNATE_POST]);
|
151 |
}
|
152 |
|
153 |
function get_anonymous_translation() {
|
154 |
-
|
155 |
-
|
156 |
}
|
157 |
|
158 |
function get_viewable_langs() {
|
159 |
-
|
160 |
}
|
161 |
|
162 |
function get_editable_langs() {
|
163 |
-
|
164 |
}
|
165 |
|
166 |
/**
|
@@ -169,76 +129,76 @@ class transposh_plugin_options {
|
|
169 |
* @return array sorted list of languages, pointing to names and flags
|
170 |
*/
|
171 |
function get_sorted_langs() {
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
}
|
176 |
|
177 |
function get_widget_progressbar() {
|
178 |
-
|
179 |
-
}
|
180 |
-
|
181 |
-
function get_widget_style() {
|
182 |
-
return $this->options[WIDGET_STYLE];
|
183 |
-
}
|
184 |
-
|
185 |
-
function get_widget_css_flags() {
|
186 |
-
return $this->options[WIDGET_CSS_FLAGS];
|
187 |
}
|
188 |
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
191 |
}
|
192 |
|
193 |
function get_widget_allow_set_default_language() {
|
194 |
-
|
195 |
}
|
196 |
|
197 |
function get_enable_permalinks() {
|
198 |
-
|
199 |
}
|
200 |
|
201 |
function get_enable_footer_scripts() {
|
202 |
-
|
203 |
}
|
204 |
|
205 |
function get_enable_detect_language() {
|
206 |
-
|
207 |
}
|
208 |
|
209 |
function get_enable_msn_translate() {
|
210 |
-
|
211 |
}
|
212 |
|
213 |
function get_enable_default_translate() {
|
214 |
-
|
215 |
}
|
216 |
|
217 |
function get_enable_search_translate() {
|
218 |
-
|
219 |
-
|
|
|
220 |
}
|
221 |
|
222 |
function get_enable_url_translate() {
|
223 |
-
|
224 |
}
|
225 |
|
226 |
function get_enable_auto_translate() {
|
227 |
-
|
228 |
-
|
|
|
229 |
}
|
230 |
|
231 |
function get_enable_auto_post_translate() {
|
232 |
-
|
233 |
}
|
234 |
|
235 |
function get_msn_key() {
|
236 |
-
|
237 |
}
|
238 |
|
239 |
function get_preferred_translator() {
|
240 |
-
|
241 |
-
|
|
|
242 |
}
|
243 |
|
244 |
/**
|
@@ -246,23 +206,23 @@ class transposh_plugin_options {
|
|
246 |
* @return string Default language
|
247 |
*/
|
248 |
function get_default_language() {
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
}
|
259 |
|
260 |
function get_transposh_key() {
|
261 |
-
|
262 |
}
|
263 |
|
264 |
function get_transposh_backup_schedule() {
|
265 |
-
|
266 |
}
|
267 |
|
268 |
/**
|
@@ -271,104 +231,99 @@ class transposh_plugin_options {
|
|
271 |
* @param pointer $option Points to the option in the options array
|
272 |
*/
|
273 |
private function set_value($val, &$option) {
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
}
|
279 |
|
280 |
function set_anonymous_translation($val) {
|
281 |
-
|
282 |
-
|
283 |
}
|
284 |
|
285 |
function set_viewable_langs($val) {
|
286 |
-
|
287 |
}
|
288 |
|
289 |
function set_editable_langs($val) {
|
290 |
-
|
291 |
}
|
292 |
|
293 |
function set_sorted_langs($val) {
|
294 |
-
|
295 |
}
|
296 |
|
297 |
function set_widget_progressbar($val) {
|
298 |
-
|
299 |
-
|
300 |
-
}
|
301 |
-
|
302 |
-
function set_widget_style($val) {
|
303 |
-
$this->set_value($val, $this->options[WIDGET_STYLE]);
|
304 |
}
|
305 |
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
function
|
312 |
-
|
313 |
-
$this->set_value($val, $this->options[WIDGET_IN_LIST]);
|
314 |
}
|
315 |
|
316 |
function set_widget_allow_set_default_language($val) {
|
317 |
-
|
318 |
-
|
319 |
}
|
320 |
|
321 |
function set_enable_permalinks($val) {
|
322 |
-
|
323 |
-
|
324 |
}
|
325 |
|
326 |
function set_enable_detect_language($val) {
|
327 |
-
|
328 |
-
|
329 |
}
|
330 |
|
331 |
function set_enable_footer_scripts($val) {
|
332 |
-
|
333 |
-
|
334 |
}
|
335 |
|
336 |
function set_enable_msn_translate($val) {
|
337 |
-
|
338 |
-
|
339 |
}
|
340 |
|
341 |
function set_enable_default_translate($val) {
|
342 |
-
|
343 |
-
|
344 |
}
|
345 |
|
346 |
function set_enable_search_translate($val) {
|
347 |
-
|
348 |
-
|
349 |
}
|
350 |
|
351 |
function set_enable_url_translate($val) {
|
352 |
-
|
353 |
-
|
354 |
}
|
355 |
|
356 |
function set_enable_auto_translate($val) {
|
357 |
-
|
358 |
-
|
359 |
}
|
360 |
|
361 |
function set_enable_auto_post_translate($val) {
|
362 |
-
|
363 |
-
|
364 |
}
|
365 |
|
366 |
function set_msn_key($val) {
|
367 |
-
|
368 |
}
|
369 |
|
370 |
function set_preferred_translator($val) {
|
371 |
-
|
372 |
}
|
373 |
|
374 |
/**
|
@@ -377,31 +332,30 @@ class transposh_plugin_options {
|
|
377 |
* @param string $val Language set as default
|
378 |
*/
|
379 |
function set_default_language($val) {
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
}
|
385 |
|
386 |
function set_transposh_key($val) {
|
387 |
-
|
388 |
}
|
389 |
|
390 |
function set_transposh_backup_schedule($val) {
|
391 |
-
|
392 |
}
|
393 |
|
394 |
/**
|
395 |
* Updates options at the wordpress options table if there was a change
|
396 |
*/
|
397 |
function update_options() {
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
$this->changed = false;
|
405 |
}
|
406 |
|
407 |
/**
|
@@ -410,7 +364,7 @@ class transposh_plugin_options {
|
|
410 |
* @return boolean Is this the default language?
|
411 |
*/
|
412 |
function is_default_language($language) {
|
413 |
-
|
414 |
}
|
415 |
|
416 |
/**
|
@@ -418,7 +372,7 @@ class transposh_plugin_options {
|
|
418 |
* @return boolean Is this language editable?
|
419 |
*/
|
420 |
function is_editable_language($language) {
|
421 |
-
|
422 |
}
|
423 |
|
424 |
/**
|
@@ -426,7 +380,7 @@ class transposh_plugin_options {
|
|
426 |
* @return boolean Is this language viewable?
|
427 |
*/
|
428 |
function is_viewable_language($language) {
|
429 |
-
|
430 |
}
|
431 |
|
432 |
}
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
//Option defining transposh widget appearance
|
23 |
+
define("OLD_WIDGET_STYLE", "widget_style");
|
24 |
+
//Use CSS sprites for flags if available
|
25 |
+
define("OLD_WIDGET_CSS_FLAGS", "widget_css_flags");
|
26 |
+
//Wrap widget elements in an unordered list per #63 @since 0.3.7
|
27 |
+
define("OLD_WIDGET_IN_LIST", "widget_in_list");
|
28 |
|
29 |
//defines are used to avoid typos
|
30 |
//Option defining whether anonymous translation is allowed.
|
59 |
define("ENABLE_DETECT_LANG_AND_REDIRECT", "enable_detect_redirect");
|
60 |
//Option defining the default language
|
61 |
define("DEFAULT_LANG", "default_language");
|
62 |
+
//Option defining transposh widget file used @since 0.5.6
|
63 |
+
define("WIDGET_FILE", "widget_file");
|
64 |
//Option allowing progress bar display
|
65 |
define("WIDGET_PROGRESSBAR", "widget_progressbar");
|
|
|
|
|
|
|
|
|
66 |
//Allows user to set his default language per #63 @since 0.3.8
|
67 |
define("WIDGET_ALLOW_SET_DEFLANG", "widget_allow_set_deflang");
|
68 |
//Stores the site key to transposh services (backup @since 0.5.0)
|
69 |
+
define("TRANSPOSH_KEY", "transposh_key");
|
70 |
//Stores the site key to transposh services (backup @since 0.5.0)
|
71 |
+
define("TRANSPOSH_BACKUP_SCHEDULE", "transposh_backup_schedule");
|
|
|
72 |
|
73 |
class transposh_plugin_options {
|
74 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
75 |
+
|
76 |
/** @var array storing all our options */
|
77 |
private $options = array();
|
78 |
/** @var boolean set to true if any option was changed */
|
79 |
private $changed = false;
|
80 |
|
81 |
function transposh_plugin_options() {
|
82 |
+
|
83 |
+
// load them here
|
84 |
+
$this->options = get_option(TRANSPOSH_OPTIONS);
|
85 |
+
$this->migrate_old_config();
|
86 |
+
|
87 |
}
|
88 |
|
|
|
|
|
|
|
|
|
|
|
89 |
// TODO: remove this function in a few versions (fix css, db version..., css flag
|
90 |
private function migrate_old_config() {
|
91 |
+
|
92 |
+
if ($this->options[OLD_WIDGET_STYLE]) {
|
93 |
+
if ($this->options[OLD_WIDGET_STYLE] == 1 && $this->options[OLD_WIDGET_CSS_FLAGS] == 0) {
|
94 |
+
$this->set_widget_file('flags/tpw_flags.php');
|
95 |
+
}
|
96 |
+
if ($this->options[OLD_WIDGET_STYLE] == 1 && $this->options[OLD_WIDGET_CSS_FLAGS] == 1) {
|
97 |
+
$this->set_widget_file('flags/tpw_flags_css.php');
|
98 |
+
}
|
99 |
+
if ($this->options[OLD_WIDGET_STYLE] == 2 && $this->options[OLD_WIDGET_CSS_FLAGS] == 0) {
|
100 |
+
$this->set_widget_file('flagslist/tpw_list_with_flags.php');
|
101 |
+
}
|
102 |
+
if ($this->options[OLD_WIDGET_STYLE] == 2 && $this->options[OLD_WIDGET_CSS_FLAGS] == 1) {
|
103 |
+
$this->set_widget_file('flagslist/tpw_list_with_flags_css.php');
|
104 |
+
}
|
105 |
+
unset($this->options[OLD_WIDGET_CSS_FLAGS]);
|
106 |
+
unset($this->options[OLD_WIDGET_IN_LIST]);
|
107 |
+
unset($this->options[OLD_WIDGET_STYLE]);
|
108 |
+
|
109 |
+
update_option(TRANSPOSH_OPTIONS, $this->options);
|
110 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
}
|
112 |
|
113 |
function get_anonymous_translation() {
|
114 |
+
if (!isset($this->options[ANONYMOUS_TRANSLATION])) 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])), $GLOBALS['languages']);
|
134 |
+
return $GLOBALS['languages'];
|
135 |
}
|
136 |
|
137 |
function get_widget_progressbar() {
|
138 |
+
return $this->options[WIDGET_PROGRESSBAR];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
}
|
140 |
|
141 |
+
/**
|
142 |
+
* return file name of the widget used
|
143 |
+
* @since 0.5.6
|
144 |
+
* @return string
|
145 |
+
*/
|
146 |
+
function get_widget_file() {
|
147 |
+
return $this->options[WIDGET_FILE];
|
148 |
}
|
149 |
|
150 |
function get_widget_allow_set_default_language() {
|
151 |
+
return $this->options[WIDGET_ALLOW_SET_DEFLANG];
|
152 |
}
|
153 |
|
154 |
function get_enable_permalinks() {
|
155 |
+
return $this->options[ENABLE_PERMALINKS];
|
156 |
}
|
157 |
|
158 |
function get_enable_footer_scripts() {
|
159 |
+
return $this->options[ENABLE_FOOTER_SCRIPTS];
|
160 |
}
|
161 |
|
162 |
function get_enable_detect_language() {
|
163 |
+
return $this->options[ENABLE_DETECT_LANG_AND_REDIRECT];
|
164 |
}
|
165 |
|
166 |
function get_enable_msn_translate() {
|
167 |
+
return $this->options[ENABLE_MSN_TRANSLATE]; // FIX
|
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_msn_key() {
|
195 |
+
return $this->options[MSN_TRANSLATE_KEY];
|
196 |
}
|
197 |
|
198 |
function get_preferred_translator() {
|
199 |
+
// default is google (2 is msn)
|
200 |
+
if (!isset($this->options[PREFERRED_TRANSLATOR])) return 1;
|
201 |
+
return $this->options[PREFERRED_TRANSLATOR];
|
202 |
}
|
203 |
|
204 |
/**
|
206 |
* @return string Default language
|
207 |
*/
|
208 |
function get_default_language() {
|
209 |
+
$default = $this->options[DEFAULT_LANG];
|
210 |
+
if (!$GLOBALS['languages'][$default]) {
|
211 |
+
if (defined('WPLANG') && $GLOBALS['languages'][WPLANG]) {
|
212 |
+
$default = WPLANG;
|
213 |
+
} else {
|
214 |
+
$default = "en";
|
215 |
+
}
|
216 |
+
}
|
217 |
+
return $default;
|
218 |
}
|
219 |
|
220 |
function get_transposh_key() {
|
221 |
+
return $this->options[TRANSPOSH_KEY];
|
222 |
}
|
223 |
|
224 |
function get_transposh_backup_schedule() {
|
225 |
+
return $this->options[TRANSPOSH_BACKUP_SCHEDULE];
|
226 |
}
|
227 |
|
228 |
/**
|
231 |
* @param pointer $option Points to the option in the options array
|
232 |
*/
|
233 |
private function set_value($val, &$option) {
|
234 |
+
if ($val !== $option) {
|
235 |
+
$option = $val;
|
236 |
+
$this->changed = true;
|
237 |
+
}
|
238 |
}
|
239 |
|
240 |
function set_anonymous_translation($val) {
|
241 |
+
$val = ($val) ? 1 : 0;
|
242 |
+
$this->set_value($val, $this->options[ANONYMOUS_TRANSLATION]);
|
243 |
}
|
244 |
|
245 |
function set_viewable_langs($val) {
|
246 |
+
$this->set_value($val, $this->options[VIEWABLE_LANGS]);
|
247 |
}
|
248 |
|
249 |
function set_editable_langs($val) {
|
250 |
+
$this->set_value($val, $this->options[EDITABLE_LANGS]);
|
251 |
}
|
252 |
|
253 |
function set_sorted_langs($val) {
|
254 |
+
$this->set_value($val, $this->options[SORTED_LANGS]);
|
255 |
}
|
256 |
|
257 |
function set_widget_progressbar($val) {
|
258 |
+
$val = ($val) ? 1 : 0;
|
259 |
+
$this->set_value($val, $this->options[WIDGET_PROGRESSBAR]);
|
|
|
|
|
|
|
|
|
260 |
}
|
261 |
|
262 |
+
/**
|
263 |
+
* Set the widget file used
|
264 |
+
* @since 0.5.6
|
265 |
+
* @param string $val
|
266 |
+
*/
|
267 |
+
function set_widget_file($val) {
|
268 |
+
$this->set_value($val, $this->options[WIDGET_FILE]);
|
|
|
269 |
}
|
270 |
|
271 |
function set_widget_allow_set_default_language($val) {
|
272 |
+
$val = ($val) ? 1 : 0;
|
273 |
+
$this->set_value($val, $this->options[WIDGET_ALLOW_SET_DEFLANG]);
|
274 |
}
|
275 |
|
276 |
function set_enable_permalinks($val) {
|
277 |
+
$val = ($val) ? 1 : 0;
|
278 |
+
$this->set_value($val, $this->options[ENABLE_PERMALINKS]);
|
279 |
}
|
280 |
|
281 |
function set_enable_detect_language($val) {
|
282 |
+
$val = ($val) ? 1 : 0;
|
283 |
+
$this->set_value($val, $this->options[ENABLE_DETECT_LANG_AND_REDIRECT]);
|
284 |
}
|
285 |
|
286 |
function set_enable_footer_scripts($val) {
|
287 |
+
$val = ($val) ? 1 : 0;
|
288 |
+
$this->set_value($val, $this->options[ENABLE_FOOTER_SCRIPTS]);
|
289 |
}
|
290 |
|
291 |
function set_enable_msn_translate($val) {
|
292 |
+
$val = ($val) ? 1 : 0;
|
293 |
+
$this->set_value($val, $this->options[ENABLE_MSN_TRANSLATE]); // FIX
|
294 |
}
|
295 |
|
296 |
function set_enable_default_translate($val) {
|
297 |
+
$val = ($val) ? 1 : 0;
|
298 |
+
$this->set_value($val, $this->options[ENABLE_DEFAULT_TRANSLATE]);
|
299 |
}
|
300 |
|
301 |
function set_enable_search_translate($val) {
|
302 |
+
$val = ($val) ? 1 : 0;
|
303 |
+
$this->set_value($val, $this->options[ENABLE_SEARCH_TRANSLATE]);
|
304 |
}
|
305 |
|
306 |
function set_enable_url_translate($val) {
|
307 |
+
$val = ($val) ? 1 : 0;
|
308 |
+
$this->set_value($val, $this->options[ENABLE_URL_TRANSLATE]);
|
309 |
}
|
310 |
|
311 |
function set_enable_auto_translate($val) {
|
312 |
+
$val = ($val) ? 1 : 0;
|
313 |
+
$this->set_value($val, $this->options[ENABLE_AUTO_TRANSLATE]);
|
314 |
}
|
315 |
|
316 |
function set_enable_auto_post_translate($val) {
|
317 |
+
$val = ($val) ? 1 : 0;
|
318 |
+
$this->set_value($val, $this->options[ENABLE_AUTO_POST_TRANSLATE]);
|
319 |
}
|
320 |
|
321 |
function set_msn_key($val) {
|
322 |
+
$this->set_value($val, $this->options[MSN_TRANSLATE_KEY]);
|
323 |
}
|
324 |
|
325 |
function set_preferred_translator($val) {
|
326 |
+
$this->set_value($val, $this->options[PREFERRED_TRANSLATOR]);
|
327 |
}
|
328 |
|
329 |
/**
|
332 |
* @param string $val Language set as default
|
333 |
*/
|
334 |
function set_default_language($val) {
|
335 |
+
if (!$GLOBALS['languages'][$val]) {
|
336 |
+
$val = "en";
|
337 |
+
}
|
338 |
+
$this->set_value($val, $this->options[DEFAULT_LANG]);
|
339 |
}
|
340 |
|
341 |
function set_transposh_key($val) {
|
342 |
+
$this->set_value($val, $this->options[TRANSPOSH_KEY]);
|
343 |
}
|
344 |
|
345 |
function set_transposh_backup_schedule($val) {
|
346 |
+
$this->set_value($val, $this->options[TRANSPOSH_BACKUP_SCHEDULE]);
|
347 |
}
|
348 |
|
349 |
/**
|
350 |
* Updates options at the wordpress options table if there was a change
|
351 |
*/
|
352 |
function update_options() {
|
353 |
+
if ($this->changed) {
|
354 |
+
update_option(TRANSPOSH_OPTIONS, $this->options);
|
355 |
+
} else {
|
356 |
+
|
357 |
+
}
|
358 |
+
$this->changed = false;
|
|
|
359 |
}
|
360 |
|
361 |
/**
|
364 |
* @return boolean Is this the default language?
|
365 |
*/
|
366 |
function is_default_language($language) {
|
367 |
+
return ($this->get_default_language() == $language);
|
368 |
}
|
369 |
|
370 |
/**
|
372 |
* @return boolean Is this language editable?
|
373 |
*/
|
374 |
function is_editable_language($language) {
|
375 |
+
return (strpos($this->get_editable_langs(), $language) !== false);
|
376 |
}
|
377 |
|
378 |
/**
|
380 |
* @return boolean Is this language viewable?
|
381 |
*/
|
382 |
function is_viewable_language($language) {
|
383 |
+
return (strpos($this->get_viewable_langs(), $language) !== false);
|
384 |
}
|
385 |
|
386 |
}
|
wp/transposh_postpublish.php
CHANGED
@@ -1,47 +1,50 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
*
|
18 |
-
*/
|
19 |
|
20 |
/*
|
21 |
* Provides the side widget in the page/edit pages which will do translations
|
22 |
-
*/
|
23 |
|
24 |
/**
|
25 |
* class that makes changed to the edit page and post page, adding our change to the side ba
|
26 |
*/
|
27 |
class transposh_postpublish {
|
|
|
28 |
/** @var transposh_plugin Container class */
|
29 |
private $transposh;
|
30 |
/** @var boolean Did we just edited/saved? */
|
31 |
private $just_published = false;
|
|
|
32 |
/**
|
33 |
*
|
34 |
* Construct our class
|
35 |
* @param transposh_plugin $transposh
|
36 |
*/
|
37 |
function transposh_postpublish(&$transposh) {
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
}
|
46 |
|
47 |
/**
|
@@ -49,35 +52,35 @@ class transposh_postpublish {
|
|
49 |
*/
|
50 |
function on_admin_menu() {
|
51 |
//add our metabox to the post and pubish pages
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
// 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
}
|
82 |
|
83 |
/**
|
@@ -85,81 +88,80 @@ class transposh_postpublish {
|
|
85 |
* @param int $postID
|
86 |
*/
|
87 |
function get_post_phrases($postID) {
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
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 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
echo json_encode($json);
|
148 |
}
|
149 |
|
150 |
/**
|
151 |
* This is the box that appears on the side
|
152 |
*/
|
153 |
function transposh_postpublish_box() {
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
}
|
164 |
|
165 |
/**
|
@@ -167,7 +169,7 @@ class transposh_postpublish {
|
|
167 |
* @param int $postID
|
168 |
*/
|
169 |
function on_edit($postID) {
|
170 |
-
|
171 |
}
|
172 |
|
173 |
/**
|
@@ -176,7 +178,8 @@ class transposh_postpublish {
|
|
176 |
* @return string redirected URL
|
177 |
*/
|
178 |
function inform_published($url) {
|
179 |
-
|
180 |
}
|
|
|
181 |
}
|
182 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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 |
* Provides the side widget in the page/edit pages which will do translations
|
23 |
+
*/
|
24 |
|
25 |
/**
|
26 |
* class that makes changed to the edit page and post page, adding our change to the side ba
|
27 |
*/
|
28 |
class transposh_postpublish {
|
29 |
+
|
30 |
/** @var transposh_plugin Container class */
|
31 |
private $transposh;
|
32 |
/** @var boolean Did we just edited/saved? */
|
33 |
private $just_published = false;
|
34 |
+
|
35 |
/**
|
36 |
*
|
37 |
* Construct our class
|
38 |
* @param transposh_plugin $transposh
|
39 |
*/
|
40 |
function transposh_postpublish(&$transposh) {
|
41 |
+
$this->transposh = &$transposh;
|
42 |
+
// we'll only do something if so configured to do
|
43 |
+
if ($this->transposh->options->get_enable_auto_post_translate()) {
|
44 |
+
add_action('edit_post', array(&$this, 'on_edit'));
|
45 |
+
// add_action('publish_post',array(&$this, 'on_publish'));
|
46 |
+
add_action('admin_menu', array(&$this, 'on_admin_menu'));
|
47 |
+
}
|
48 |
}
|
49 |
|
50 |
/**
|
52 |
*/
|
53 |
function on_admin_menu() {
|
54 |
//add our metabox to the post and pubish pages
|
55 |
+
|
56 |
+
add_meta_box('transposh_postpublish', 'Transposh', array(&$this, "transposh_postpublish_box"), 'post', 'side', 'core');
|
57 |
+
add_meta_box('transposh_postpublish', 'Transposh', array(&$this, "transposh_postpublish_box"), 'page', 'side', 'core');
|
58 |
+
if ($_GET['justedited']) {
|
59 |
+
wp_enqueue_script("google", "http://www.google.com/jsapi", array(), '1', true);
|
60 |
+
wp_enqueue_script("transposh", "{$this->transposh->transposh_plugin_url}/js/transposhadmin.js", array("jquery"), TRANSPOSH_PLUGIN_VER, true);
|
61 |
+
wp_localize_script("transposh", "t_jp", array(
|
62 |
+
'post_url' => $this->transposh->post_url,
|
63 |
+
'post' => $_GET['post'],
|
64 |
+
'msnkey' => $this->transposh->options->get_msn_key(),
|
65 |
+
'msn_langs' => json_encode($GLOBALS['bing_languages']),
|
66 |
+
'google_lang' => json_encode($GLOBALS['google_languages']),
|
67 |
+
'preferred' => $this->transposh->options->get_preferred_translator()/* ,
|
68 |
+
'plugin_url' => $this->transposh_plugin_url,
|
69 |
+
'edit' => ($this->edit_mode? '1' : ''),
|
70 |
+
//'rtl' => (in_array ($this->target_language, $GLOBALS['rtl_languages'])? 'true' : ''),
|
71 |
+
'lang' => $this->target_language,
|
72 |
+
// those two options show if the script can support said engines
|
73 |
+
'prefix' => SPAN_PREFIX,
|
74 |
+
|
75 |
+
'progress'=>$this->edit_mode || $this->options->get_widget_progressbar() ? '1' : '') */
|
76 |
// 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
|
77 |
+
));
|
78 |
+
wp_enqueue_style("jquery", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css", array(), '1.0');
|
79 |
+
wp_enqueue_script("jqueryui", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js", array("jquery"), '1.7.2', true);
|
80 |
+
/* if ($this->transposh->options->get_enable_msn_translate() && $this->transposh->options->get_msn_key()) {
|
81 |
+
wp_enqueue_script("mstranslate","http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=".$this->transposh->options->get_msn_key(),array(),'1',true);
|
82 |
+
} */
|
83 |
+
}
|
84 |
}
|
85 |
|
86 |
/**
|
88 |
* @param int $postID
|
89 |
*/
|
90 |
function get_post_phrases($postID) {
|
91 |
+
// Some security, to avoid others from seeing private posts
|
92 |
+
if (!current_user_can('edit_post', $postID)) return;
|
93 |
+
$post = get_post($postID);
|
94 |
+
// Display filters
|
95 |
+
$title = apply_filters('the_title', $post->post_title);
|
96 |
+
$content = apply_filters('the_content', $post->post_content);
|
97 |
+
// TODO - grab phrases from rss excerpt
|
98 |
+
//$output = get_the_excerpt();
|
99 |
+
// echo apply_filters('the_excerpt_rss', $output);
|
100 |
+
//TODO - get comments text
|
101 |
+
|
102 |
+
$parser = new parser();
|
103 |
+
$phrases = $parser->get_phrases_list($content);
|
104 |
+
$phrases2 = $parser->get_phrases_list($title);
|
105 |
+
|
106 |
+
// Merge the two arrays for traversing
|
107 |
+
$phrases = array_merge($phrases, $phrases2);
|
108 |
+
|
109 |
+
// Add pharses from permalink
|
110 |
+
if ($this->transposh->options->get_enable_url_translate()) {
|
111 |
+
$permalink = get_permalink($postID);
|
112 |
+
$permalink = substr($permalink, strlen($this->transposh->home_url) + 1);
|
113 |
+
$parts = explode('/', $permalink);
|
114 |
+
foreach ($parts as $part) {
|
115 |
+
if (!$part || is_numeric($part)) continue;
|
116 |
+
$part = str_replace('-', ' ', $part);
|
117 |
+
$phrases[] = $part;
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
foreach ($phrases as $key) {
|
122 |
+
foreach (explode(',', $this->transposh->options->get_editable_langs()) as $lang) {
|
123 |
+
// if this isn't the default language or we specifically allow default language translation, we will seek this out...
|
124 |
+
// as we don't normally want to auto-translate the default language
|
125 |
+
if (!$this->transposh->options->is_default_language($lang) || $this->transposh->options->get_enable_default_translate()) {
|
126 |
+
list($translation, $source) = $this->transposh->database->fetch_translation($key, $lang);
|
127 |
+
if (!$translation) {
|
128 |
+
// p stands for phrases, l stands for languages, t is token
|
129 |
+
if (!is_array($json['p'][$key]['l'])) {
|
130 |
+
$json['p'][$key]['l'] = array();
|
131 |
+
}
|
132 |
+
array_push($json['p'][$key]['l'], $lang);
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
136 |
+
// only if a languages list was created we'll need to translate this
|
137 |
+
if (is_array($json['p'][$key]['l'])) {
|
138 |
+
$json['p'][$key]['t'] = base64_url_encode($key);
|
139 |
+
$json['length']++;
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
// add the title
|
144 |
+
// if ($json['length'])
|
145 |
+
$json['posttitle'] = $title;
|
146 |
+
|
147 |
+
// the header helps with debugging
|
148 |
+
header("Content-type: text/javascript");
|
149 |
+
echo json_encode($json);
|
|
|
150 |
}
|
151 |
|
152 |
/**
|
153 |
* This is the box that appears on the side
|
154 |
*/
|
155 |
function transposh_postpublish_box() {
|
156 |
+
// the nonce will help double translation if time has passed
|
157 |
+
if ($_GET['justedited'] && wp_verify_nonce($_GET['justedited']))
|
158 |
+
$this->just_published = true;
|
159 |
+
|
160 |
+
if ($this->just_published) {
|
161 |
+
echo '<div id="tr_loading">Publication happened - loading phrases list...</div>';
|
162 |
+
} else {
|
163 |
+
echo 'Waiting for publication';
|
164 |
+
}
|
165 |
}
|
166 |
|
167 |
/**
|
169 |
* @param int $postID
|
170 |
*/
|
171 |
function on_edit($postID) {
|
172 |
+
add_filter('wp_redirect', array(&$this, 'inform_published'));
|
173 |
}
|
174 |
|
175 |
/**
|
178 |
* @return string redirected URL
|
179 |
*/
|
180 |
function inform_published($url) {
|
181 |
+
return add_query_arg('justedited', wp_create_nonce(), $url);
|
182 |
}
|
183 |
+
|
184 |
}
|
185 |
?>
|
wp/transposh_widget.php
CHANGED
@@ -1,118 +1,157 @@
|
|
1 |
<?php
|
|
|
2 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
3 |
*
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
13 |
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*/
|
18 |
|
19 |
/*
|
20 |
* Provides the sidebar widget for selecting a language and switching between edit/view
|
21 |
* mode.
|
22 |
-
*/
|
|
|
|
|
|
|
23 |
|
24 |
//class that reperesent the complete plugin
|
25 |
class transposh_plugin_widget {
|
|
|
26 |
/** @var transposh_plugin Container class */
|
27 |
private $transposh;
|
|
|
|
|
28 |
|
29 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
30 |
function transposh_plugin_widget(&$transposh) {
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
}
|
36 |
|
37 |
/**
|
38 |
* Intercept init calls to see if it was posted by the widget.
|
39 |
*/
|
40 |
function init_transposh() {
|
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 |
-
wp_redirect($ref);
|
76 |
-
exit;
|
77 |
-
}
|
78 |
}
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
function transposh_widget_init() {
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
-
|
90 |
-
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
}
|
98 |
|
99 |
/**
|
100 |
* Add custom css, i.e. transposh_widget.css, flags now override widget
|
101 |
*/
|
102 |
-
function
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
}
|
115 |
-
|
116 |
}
|
117 |
|
118 |
/**
|
@@ -120,172 +159,194 @@ class transposh_plugin_widget {
|
|
120 |
* @param array $args Contains such as $before_widget, $after_widget, $before_title, $after_title, etc
|
121 |
*/
|
122 |
function transposh_widget($args) {
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
if($this->transposh->is_editing_permitted()) {
|
220 |
-
echo "<input type=\"checkbox\" name=\"" . EDIT_PARAM . "\" value=\"1\" " .
|
221 |
-
($this->transposh->edit_mode ? "checked=\"checked\"" : "") .
|
222 |
-
" onclick=\"this.form.submit();\"/> Edit Translation";
|
223 |
-
}
|
224 |
-
|
225 |
-
echo "<input type=\"hidden\" name=\"transposh_widget_posted\" value=\"1\"/>";
|
226 |
-
}
|
227 |
-
else {
|
228 |
-
//no languages configured - error message
|
229 |
-
echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>';
|
230 |
-
}
|
231 |
-
|
232 |
-
echo "</form>";
|
233 |
-
if ($this->transposh->options->get_widget_in_list()) echo "</li></ul>";
|
234 |
-
//TODO: maybe... echo "<button onClick=\"do_auto_translate();\">translate all</button>";
|
235 |
-
if ($this->transposh->options->get_widget_in_list()) echo "<ul><li>";
|
236 |
-
// Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget
|
237 |
-
// first - according to the gpl, you may do so - but since the code has changed - please make in available under the gpl
|
238 |
-
// second - we did invest a lot of time and effort into this, and the link is a way to help us grow and show your appreciation, if it
|
239 |
-
// upsets you, feel more than free to move this link somewhere else on your page, such as the footer etc.
|
240 |
-
// third - feel free to write your own widget, the translation core will work
|
241 |
-
// forth - you can ask for permission, with a good reason, if you contributed to the code - it's a good enough reason :)
|
242 |
-
// last - if you just delete the following line, it means that you have little respect to the whole copyright thing, which as far as we
|
243 |
-
// understand means that by doing so - you are giving everybody else the right to do the same and use your work without any attribution
|
244 |
-
echo "<div id=\"".SPAN_PREFIX."credit\">by <a href=\"http://tran"."sposh.org\"><img class=\"".NO_TRANSLATE_CLASS."\" height=\"16\" width=\"16\" src=\"$plugpath/img/tplog"."o.png\" style=\"padding:1px;border:0px\" title=\"Transposh\" alt=\"Transposh\"/></a></div>";
|
245 |
-
if ($this->transposh->options->get_widget_in_list()) echo "</li></ul>";
|
246 |
-
echo $after_widget;
|
247 |
}
|
248 |
|
249 |
function transposh_widget_post($save = true) {
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
}
|
262 |
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
function transposh_widget_control() {
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
'<input type="hidden" name="transposh-submit" id="transposh-submit" value="1"/>';
|
288 |
}
|
|
|
289 |
}
|
290 |
|
291 |
/**
|
@@ -295,5 +356,4 @@ class transposh_plugin_widget {
|
|
295 |
function transposh_widget($args = array()) {
|
296 |
$GLOBALS['my_transposh_plugin']->widget->transposh_widget($args);
|
297 |
}
|
298 |
-
|
299 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/* Copyright © 2009-2010 Transposh Team (website : http://transposh.org)
|
4 |
*
|
5 |
+
* This program is free software; you can redistribute it and/or modify
|
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 |
+
* 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 |
* Provides the sidebar widget for selecting a language and switching between edit/view
|
22 |
* mode.
|
23 |
+
*/
|
24 |
+
|
25 |
+
//Define widget file prefix
|
26 |
+
define('TRANSPOSH_WIDGET_PREFIX', 'tpw_');
|
27 |
|
28 |
//class that reperesent the complete plugin
|
29 |
class transposh_plugin_widget {
|
30 |
+
|
31 |
/** @var transposh_plugin Container class */
|
32 |
private $transposh;
|
33 |
+
/** @var string Contains the name of the used widget file */
|
34 |
+
public $base_widget_file_name;
|
35 |
|
36 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
37 |
function transposh_plugin_widget(&$transposh) {
|
38 |
+
//Register callback for WordPress events
|
39 |
+
$this->transposh = &$transposh;
|
40 |
+
add_action('init', array(&$this, 'init_transposh'), 1);
|
41 |
+
add_action('widgets_init', array(&$this, 'transposh_widget_init'));
|
42 |
}
|
43 |
|
44 |
/**
|
45 |
* Intercept init calls to see if it was posted by the widget.
|
46 |
*/
|
47 |
function init_transposh() {
|
48 |
+
if (isset($_POST['transposh_widget_posted'])) {
|
49 |
+
|
50 |
+
|
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 = '';
|
58 |
+
|
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 |
+
|
79 |
+
wp_redirect($ref);
|
80 |
+
exit;
|
81 |
+
}
|
|
|
|
|
|
|
82 |
}
|
83 |
|
84 |
+
/**
|
85 |
+
* Register the widget.
|
86 |
+
*/
|
87 |
function transposh_widget_init() {
|
88 |
+
|
89 |
+
if (!function_exists('register_sidebar_widget')) {
|
90 |
+
return;
|
91 |
+
}
|
92 |
+
|
93 |
+
// Register widget
|
94 |
+
register_sidebar_widget(array('Transposh', 'widgets'), array(&$this, 'transposh_widget'));
|
95 |
+
|
96 |
+
// Register widget control
|
97 |
+
register_widget_control("Transposh", array(&$this, 'transposh_widget_control'));
|
98 |
|
99 |
+
// Register callback for widget's css and js
|
100 |
+
add_action('wp_print_styles', array(&$this, 'add_transposh_widget_css'));
|
101 |
+
add_action('wp_print_scripts', array(&$this, 'add_transposh_widget_js'));
|
102 |
+
}
|
103 |
|
104 |
+
/**
|
105 |
+
* Loads the widget code
|
106 |
+
*/
|
107 |
+
function load_widget() {
|
108 |
+
// avoid dual loadings
|
109 |
+
if ($this->base_widget_file_name) return;
|
110 |
+
|
111 |
+
$file = $this->transposh->options->get_widget_file();
|
112 |
+
$widget_src = $this->transposh->transposh_plugin_dir . TRANSPOSH_DIR_WIDGETS . '/' . $file;
|
113 |
+
if (file_exists($widget_src)) {
|
114 |
+
require_once $widget_src;
|
115 |
+
} else {
|
116 |
+
$file = 'tpw_default.php';
|
117 |
+
require_once $this->transposh->transposh_plugin_dir . TRANSPOSH_DIR_WIDGETS . '/' . $file; //TODO fix widget constant all around...
|
118 |
+
}
|
119 |
+
$this->base_widget_file_name = substr($file, 0, -4);
|
120 |
+
}
|
121 |
|
122 |
+
/**
|
123 |
+
* Add custom css, i.e. transposh_widget.css, flags now override widget
|
124 |
+
*/
|
125 |
+
function add_transposh_widget_css() { //TODO ! goway
|
126 |
+
$this->load_widget();
|
127 |
+
|
128 |
+
if (function_exists(tp_widget_css)) {
|
129 |
+
tp_widget_css();
|
130 |
+
} else {
|
131 |
+
$widget_css = TRANSPOSH_DIR_WIDGETS.'/'.$this->base_widget_file_name . ".css";
|
132 |
+
if (file_exists($this->transposh->transposh_plugin_dir . $widget_css )) {
|
133 |
+
wp_enqueue_style('transposh_widget', $this->transposh->transposh_plugin_url.'/'.$widget_css, '', TRANSPOSH_PLUGIN_VER);
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
|
138 |
}
|
139 |
|
140 |
/**
|
141 |
* Add custom css, i.e. transposh_widget.css, flags now override widget
|
142 |
*/
|
143 |
+
function add_transposh_widget_js() { //TODO ! goway
|
144 |
+
$this->load_widget();
|
145 |
+
|
146 |
+
if (function_exists(tp_widget_js)) {
|
147 |
+
tp_widget_js();
|
148 |
+
} else {
|
149 |
+
$widget_js = TRANSPOSH_DIR_WIDGETS.'/'.$this->base_widget_file_name . ".js";
|
150 |
+
if (file_exists($this->transposh->transposh_plugin_dir . $widget_js )) {
|
151 |
+
wp_enqueue_script('transposh_widget', $this->transposh->transposh_plugin_url.'/'.$widget_js, '', TRANSPOSH_PLUGIN_VER);
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
|
|
|
|
155 |
}
|
156 |
|
157 |
/**
|
159 |
* @param array $args Contains such as $before_widget, $after_widget, $before_title, $after_title, etc
|
160 |
*/
|
161 |
function transposh_widget($args) {
|
162 |
+
$this->load_widget();
|
163 |
+
|
164 |
+
// hmmm, this should actually prepare all vars needed, include the correct widget and send the vars to that function,
|
165 |
+
$calc_url = false; // By default, avoid calculating the urls
|
166 |
+
if (function_exists(tp_widget_needs_post_url))
|
167 |
+
$calc_url = tp_widget_needs_post_url();
|
168 |
+
|
169 |
+
$widget_args = array();
|
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 |
+
|
180 |
+
// loop on the languages
|
181 |
+
foreach ($this->transposh->options->get_sorted_langs() as $code => $langrecord) {
|
182 |
+
list ($langname, $language, $flag) = explode(',', $langrecord);
|
183 |
+
|
184 |
+
// Only send languages which are viewable or (editable and the user is a translator)
|
185 |
+
if ($this->transposh->options->is_viewable_language($code) ||
|
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,
|
199 |
+
'flag' => $flag,
|
200 |
+
'isocode' => $code,
|
201 |
+
'url' => $page_url,
|
202 |
+
'active' => ($this->transposh->target_language == $code));
|
203 |
+
}
|
204 |
+
}
|
205 |
+
// at this point the widget args are ready
|
206 |
+
|
207 |
+
|
208 |
+
|
209 |
+
// extract args given by wordpress
|
210 |
+
extract($args);
|
211 |
+
|
212 |
+
|
213 |
+
// widget default title
|
214 |
+
echo $before_widget . $before_title . __('Translation') . $after_title;
|
215 |
+
|
216 |
+
// the widget is inside a form used for posting a language change or edit request
|
217 |
+
echo '<form id="tp_form" action="' . $clean_page_url . '" method="post">';
|
218 |
+
|
219 |
+
// actually run the external widget code
|
220 |
+
tp_widget_do($widget_args);
|
221 |
+
|
222 |
+
//at least one language showing - add the edit box if applicable
|
223 |
+
if (!empty($widget_args)) {
|
224 |
+
// this is the set default language line
|
225 |
+
if ($this->transposh->options->get_widget_allow_set_default_language()) {
|
226 |
+
If ((isset($_COOKIE['TR_LNG']) && $_COOKIE['TR_LNG'] != $this->transposh->target_language) || (!isset($_COOKIE['TR_LNG']) && !$this->transposh->options->is_default_language($this->transposh->target_language))) {
|
227 |
+
echo '<a id="' . SPAN_PREFIX . 'setdeflang" onClick="return false;" href="' . $this->transposh->post_url . '?tr_cookie_bck">Set as default language</a><br/>';
|
228 |
+
}
|
229 |
+
}
|
230 |
+
// add the edit checkbox only for translators for languages marked as editable
|
231 |
+
if ($this->transposh->is_editing_permitted()) {
|
232 |
+
echo '<input type="checkbox" name="' . EDIT_PARAM . '" value="1" ' .
|
233 |
+
($this->transposh->edit_mode ? 'checked="checked"' : '') .
|
234 |
+
' onclick="this.form.submit();"/> Edit Translation';
|
235 |
+
}
|
236 |
+
|
237 |
+
echo '<input type="hidden" name="transposh_widget_posted" value="1"/>';
|
238 |
+
} else {
|
239 |
+
//no languages configured - error message
|
240 |
+
echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>';
|
241 |
+
}
|
242 |
+
|
243 |
+
echo "</form>";
|
244 |
+
|
245 |
+
// Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget
|
246 |
+
// first - according to the gpl, you may do so - but since the code has changed - please make in available under the gpl
|
247 |
+
// second - we did invest a lot of time and effort into this, and the link is a way to help us grow and show your appreciation, if it
|
248 |
+
// upsets you, feel more than free to move this link somewhere else on your page, such as the footer etc.
|
249 |
+
// third - feel free to write your own widget, the translation core will work
|
250 |
+
// forth - you can ask for permission, with a good reason, if you contributed to the code - it's a good enough reason :)
|
251 |
+
// last - if you just delete the following line, it means that you have little respect to the whole copyright thing, which as far as we
|
252 |
+
// understand means that by doing so - you are giving everybody else the right to do the same and use your work without any attribution
|
253 |
+
$plugpath = parse_url($this->transposh->transposh_plugin_url, PHP_URL_PATH);
|
254 |
+
|
255 |
+
echo '<div id="' . SPAN_PREFIX . 'credit">by <a href="http://tran' . 'sposh.org"><img class="' . NO_TRANSLATE_CLASS . '" height="16" width="16" src="' .
|
256 |
+
$plugpath . '/img/tplog' . 'o.png" style="padding:1px;border:0px" title="Transposh" alt="Transposh"/></a></div>';
|
257 |
+
echo $after_widget;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
}
|
259 |
|
260 |
function transposh_widget_post($save = true) {
|
261 |
+
|
262 |
+
|
263 |
+
$this->transposh->options->set_widget_file($_POST[WIDGET_FILE]);
|
264 |
+
$this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]);
|
265 |
+
$this->transposh->options->set_widget_allow_set_default_language($_POST[WIDGET_ALLOW_SET_DEFLANG]);
|
266 |
+
if ($save) $this->transposh->options->update_options();
|
267 |
+
// Avoid coming here twice...
|
268 |
+
unset($_POST['transposh-submit']);
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Inspired (and used code) from the get_plugins function of wordpress
|
273 |
+
*/
|
274 |
+
function get_widgets($widget_folder = '') {
|
275 |
+
get_plugins();
|
276 |
+
|
277 |
+
$tp_widgets = array();
|
278 |
+
$widget_root = $this->transposh->transposh_plugin_dir . "widgets";
|
279 |
+
if (!empty($widget_folder)) $widget_root .= $widget_folder;
|
280 |
+
|
281 |
+
// Files in wp-content/widgets directory
|
282 |
+
$widgets_dir = @opendir($widget_root);
|
283 |
+
$widget_files = array();
|
284 |
+
if ($widgets_dir) {
|
285 |
+
while (($file = readdir($widgets_dir) ) !== false) {
|
286 |
+
if (substr($file, 0, 1) == '.') continue;
|
287 |
+
if (is_dir($widget_root . '/' . $file)) {
|
288 |
+
$widgets_subdir = @ opendir($widget_root . '/' . $file);
|
289 |
+
if ($widgets_subdir) {
|
290 |
+
while (($subfile = readdir($widgets_subdir) ) !== false) {
|
291 |
+
if (substr($subfile, 0, 1) == '.') continue;
|
292 |
+
if (substr($subfile, 0, 4) == TRANSPOSH_WIDGET_PREFIX && substr($subfile, -4) == '.php')
|
293 |
+
$widget_files[] = "$file/$subfile";
|
294 |
+
}
|
295 |
+
}
|
296 |
+
}
|
297 |
+
if (substr($file, 0, 4) == TRANSPOSH_WIDGET_PREFIX && substr($file, -4) == '.php')
|
298 |
+
$widget_files[] = $file;
|
299 |
+
}
|
300 |
+
} else {
|
301 |
+
return $tp_widgets;
|
302 |
+
}
|
303 |
+
|
304 |
+
@closedir($widgets_dir);
|
305 |
+
@closedir($widgets_subdir);
|
306 |
+
|
307 |
+
if (empty($widget_files)) return $tp_widgets;
|
308 |
+
|
309 |
+
foreach ($widget_files as $widget_file) {
|
310 |
+
if (!is_readable("$widget_root/$widget_file")) continue;
|
311 |
+
|
312 |
+
$widget_data = get_plugin_data("$widget_root/$widget_file", false, false); //Do not apply markup/translate as it'll be cached.
|
313 |
+
|
314 |
+
if (empty($widget_data['Name'])) continue;
|
315 |
+
|
316 |
+
$tp_widgets[plugin_basename($widget_file)] = $widget_data;
|
317 |
+
}
|
318 |
+
|
319 |
+
uasort($tp_widgets, create_function('$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );'));
|
320 |
+
|
321 |
+
return $tp_widgets;
|
322 |
}
|
323 |
|
324 |
+
/**
|
325 |
+
* This is the widget control, allowing the selection of presentation type.
|
326 |
+
*/
|
327 |
function transposh_widget_control() {
|
328 |
+
if (isset($_POST['transposh-submit'])) $this->transposh_widget_post();
|
329 |
+
|
330 |
+
$widgets = $this->get_widgets();
|
331 |
+
|
332 |
+
echo '<p><label for="' . WIDGET_FILE . '">Style:<br />' .
|
333 |
+
'<select id="transposh-style" name="' . WIDGET_FILE . '">';
|
334 |
+
foreach ($widgets as $file => $widget) {
|
335 |
+
|
336 |
+
$selected = ($this->transposh->options->get_widget_file() == $file) ? ' selected="selected"' : '';
|
337 |
+
echo "<option value=\"$file\"$selected>{$widget['Name']}</option>";
|
338 |
+
}
|
339 |
+
echo '</select>' .
|
340 |
+
'</label></p>' .
|
341 |
+
'<p><label for="transposh-progress">Effects:</label><br/>' .
|
342 |
+
'<input type="checkbox" id="' . WIDGET_PROGRESSBAR . '" name="' . WIDGET_PROGRESSBAR . '"' . ($this->transposh->options->get_widget_progressbar() ? ' checked="checked"' : '') . '/>' .
|
343 |
+
'<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Show progress bar when a client triggers automatic translation">Show progress bar</span><br/>' .
|
344 |
+
'<input type="checkbox" id="' . WIDGET_ALLOW_SET_DEFLANG . '" name="' . WIDGET_ALLOW_SET_DEFLANG . '"' . ($this->transposh->options->get_widget_allow_set_default_language() ? ' checked="checked"' : '') . '/>' .
|
345 |
+
'<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Widget will allow setting this language as user default.">Allow user to set current language as default</span><br/>' .
|
346 |
+
'</p>' .
|
347 |
+
'<input type="hidden" name="transposh-submit" id="transposh-submit" value="1"/>';
|
|
|
348 |
}
|
349 |
+
|
350 |
}
|
351 |
|
352 |
/**
|
356 |
function transposh_widget($args = array()) {
|
357 |
$GLOBALS['my_transposh_plugin']->widget->transposh_widget($args);
|
358 |
}
|
|
|
359 |
?>
|