Version Description
Download this release
Release Info
Developer | oferwald |
Plugin | Transposh WordPress Translation |
Version | 0.1.2 |
Comparing to | |
See all releases |
Code changes from version 0.1.1 to 0.1.2
- constants.php → core/constants.php +39 -39
- core/globals.php +49 -0
- parser.php → core/parser.php +80 -26
- core/utils.php +99 -0
- transposh.css → css/transposh.css +2 -2
- css/transposh_widget.css +10 -0
- {flags → img/flags}/ad.png +0 -0
- {flags → img/flags}/ae.png +0 -0
- {flags → img/flags}/af.png +0 -0
- {flags → img/flags}/ag.png +0 -0
- {flags → img/flags}/ai.png +0 -0
- {flags → img/flags}/al.png +0 -0
- {flags → img/flags}/am.png +0 -0
- {flags → img/flags}/an.png +0 -0
- {flags → img/flags}/ao.png +0 -0
- {flags → img/flags}/ar.png +0 -0
- {flags → img/flags}/as.png +0 -0
- {flags → img/flags}/at.png +0 -0
- {flags → img/flags}/au.png +0 -0
- {flags → img/flags}/aw.png +0 -0
- {flags → img/flags}/ax.png +0 -0
- {flags → img/flags}/az.png +0 -0
- {flags → img/flags}/ba.png +0 -0
- {flags → img/flags}/bb.png +0 -0
- {flags → img/flags}/bd.png +0 -0
- {flags → img/flags}/be.png +0 -0
- {flags → img/flags}/bf.png +0 -0
- {flags → img/flags}/bg.png +0 -0
- {flags → img/flags}/bh.png +0 -0
- {flags → img/flags}/bi.png +0 -0
- {flags → img/flags}/bj.png +0 -0
- {flags → img/flags}/bm.png +0 -0
- {flags → img/flags}/bn.png +0 -0
- {flags → img/flags}/bo.png +0 -0
- {flags → img/flags}/br.png +0 -0
- {flags → img/flags}/bs.png +0 -0
- {flags → img/flags}/bt.png +0 -0
- {flags → img/flags}/bv.png +0 -0
- {flags → img/flags}/bw.png +0 -0
- {flags → img/flags}/by.png +0 -0
- {flags → img/flags}/bz.png +0 -0
- {flags → img/flags}/ca.png +0 -0
- {flags → img/flags}/catalonia.png +0 -0
- {flags → img/flags}/cc.png +0 -0
- {flags → img/flags}/cd.png +0 -0
- {flags → img/flags}/cf.png +0 -0
- {flags → img/flags}/cg.png +0 -0
- {flags → img/flags}/ch.png +0 -0
- {flags → img/flags}/ci.png +0 -0
- {flags → img/flags}/ck.png +0 -0
- {flags → img/flags}/cl.png +0 -0
- {flags → img/flags}/cm.png +0 -0
- {flags → img/flags}/cn.png +0 -0
- {flags → img/flags}/co.png +0 -0
- {flags → img/flags}/cr.png +0 -0
- {flags → img/flags}/cs.png +0 -0
- {flags → img/flags}/cu.png +0 -0
- {flags → img/flags}/cv.png +0 -0
- {flags → img/flags}/cx.png +0 -0
- {flags → img/flags}/cy.png +0 -0
- {flags → img/flags}/cz.png +0 -0
- {flags → img/flags}/de.png +0 -0
- {flags → img/flags}/dj.png +0 -0
- {flags → img/flags}/dk.png +0 -0
- {flags → img/flags}/dm.png +0 -0
- {flags → img/flags}/do.png +0 -0
- {flags → img/flags}/dz.png +0 -0
- {flags → img/flags}/ec.png +0 -0
- {flags → img/flags}/ee.png +0 -0
- {flags → img/flags}/eg.png +0 -0
- {flags → img/flags}/eh.png +0 -0
- {flags → img/flags}/england.png +0 -0
- {flags → img/flags}/er.png +0 -0
- {flags → img/flags}/es.png +0 -0
- {flags → img/flags}/et.png +0 -0
- {flags → img/flags}/europeanunion.png +0 -0
- {flags → img/flags}/fam.png +0 -0
- {flags → img/flags}/fi.png +0 -0
- {flags → img/flags}/fj.png +0 -0
- {flags → img/flags}/fk.png +0 -0
- {flags → img/flags}/fm.png +0 -0
- {flags → img/flags}/fo.png +0 -0
- {flags → img/flags}/fr.png +0 -0
- {flags → img/flags}/ga.png +0 -0
- img/flags/galicia.png +0 -0
- {flags → img/flags}/gb.png +0 -0
- {flags → img/flags}/gd.png +0 -0
- {flags → img/flags}/ge.png +0 -0
- {flags → img/flags}/gf.png +0 -0
- {flags → img/flags}/gh.png +0 -0
- {flags → img/flags}/gi.png +0 -0
- {flags → img/flags}/gl.png +0 -0
- {flags → img/flags}/gm.png +0 -0
- {flags → img/flags}/gn.png +0 -0
- {flags → img/flags}/gp.png +0 -0
- {flags → img/flags}/gq.png +0 -0
- {flags → img/flags}/gr.png +0 -0
- {flags → img/flags}/gs.png +0 -0
- {flags → img/flags}/gt.png +0 -0
- {flags → img/flags}/gu.png +0 -0
- {flags → img/flags}/gw.png +0 -0
- {flags → img/flags}/gy.png +0 -0
- {flags → img/flags}/hk.png +0 -0
- {flags → img/flags}/hm.png +0 -0
- {flags → img/flags}/hn.png +0 -0
- {flags → img/flags}/hr.png +0 -0
- {flags → img/flags}/ht.png +0 -0
- {flags → img/flags}/hu.png +0 -0
- {flags → img/flags}/id.png +0 -0
- {flags → img/flags}/ie.png +0 -0
- {flags → img/flags}/il.png +0 -0
- {flags → img/flags}/in.png +0 -0
- {flags → img/flags}/io.png +0 -0
- {flags → img/flags}/iq.png +0 -0
- {flags → img/flags}/ir.png +0 -0
- {flags → img/flags}/is.png +0 -0
- {flags → img/flags}/it.png +0 -0
- {flags → img/flags}/jm.png +0 -0
- {flags → img/flags}/jo.png +0 -0
- {flags → img/flags}/jp.png +0 -0
- {flags → img/flags}/ke.png +0 -0
- {flags → img/flags}/kg.png +0 -0
- {flags → img/flags}/kh.png +0 -0
- {flags → img/flags}/ki.png +0 -0
- {flags → img/flags}/km.png +0 -0
- {flags → img/flags}/kn.png +0 -0
- {flags → img/flags}/kp.png +0 -0
- {flags → img/flags}/kr.png +0 -0
- {flags → img/flags}/kw.png +0 -0
- {flags → img/flags}/ky.png +0 -0
- {flags → img/flags}/kz.png +0 -0
- {flags → img/flags}/la.png +0 -0
- {flags → img/flags}/lb.png +0 -0
- {flags → img/flags}/lc.png +0 -0
- {flags → img/flags}/li.png +0 -0
- {flags → img/flags}/lk.png +0 -0
- {flags → img/flags}/lr.png +0 -0
- {flags → img/flags}/ls.png +0 -0
- {flags → img/flags}/lt.png +0 -0
- {flags → img/flags}/lu.png +0 -0
- {flags → img/flags}/lv.png +0 -0
- {flags → img/flags}/ly.png +0 -0
- {flags → img/flags}/ma.png +0 -0
- {flags → img/flags}/mc.png +0 -0
- {flags → img/flags}/md.png +0 -0
- {flags → img/flags}/me.png +0 -0
- {flags → img/flags}/mg.png +0 -0
- {flags → img/flags}/mh.png +0 -0
- {flags → img/flags}/mk.png +0 -0
- {flags → img/flags}/ml.png +0 -0
- {flags → img/flags}/mm.png +0 -0
- {flags → img/flags}/mn.png +0 -0
- {flags → img/flags}/mo.png +0 -0
- {flags → img/flags}/mp.png +0 -0
- {flags → img/flags}/mq.png +0 -0
- {flags → img/flags}/mr.png +0 -0
- {flags → img/flags}/ms.png +0 -0
- {flags → img/flags}/mt.png +0 -0
- {flags → img/flags}/mu.png +0 -0
- {flags → img/flags}/mv.png +0 -0
- {flags → img/flags}/mw.png +0 -0
- {flags → img/flags}/mx.png +0 -0
- {flags → img/flags}/my.png +0 -0
- {flags → img/flags}/mz.png +0 -0
- {flags → img/flags}/na.png +0 -0
- {flags → img/flags}/nc.png +0 -0
- {flags → img/flags}/ne.png +0 -0
- {flags → img/flags}/nf.png +0 -0
- {flags → img/flags}/ng.png +0 -0
- {flags → img/flags}/ni.png +0 -0
- {flags → img/flags}/nl.png +0 -0
- {flags → img/flags}/no.png +0 -0
- {flags → img/flags}/np.png +0 -0
- {flags → img/flags}/nr.png +0 -0
- {flags → img/flags}/nu.png +0 -0
- {flags → img/flags}/nz.png +0 -0
- {flags → img/flags}/om.png +0 -0
- {flags → img/flags}/pa.png +0 -0
- {flags → img/flags}/pe.png +0 -0
- {flags → img/flags}/pf.png +0 -0
- {flags → img/flags}/pg.png +0 -0
- {flags → img/flags}/ph.png +0 -0
- {flags → img/flags}/pk.png +0 -0
- {flags → img/flags}/pl.png +0 -0
- {flags → img/flags}/pm.png +0 -0
- {flags → img/flags}/pn.png +0 -0
- {flags → img/flags}/pr.png +0 -0
- {flags → img/flags}/ps.png +0 -0
- {flags → img/flags}/pt.png +0 -0
- {flags → img/flags}/pw.png +0 -0
- {flags → img/flags}/py.png +0 -0
- {flags → img/flags}/qa.png +0 -0
- {flags → img/flags}/re.png +0 -0
- {flags → img/flags}/ro.png +0 -0
- {flags → img/flags}/rs.png +0 -0
- {flags → img/flags}/ru.png +0 -0
- {flags → img/flags}/rw.png +0 -0
- {flags → img/flags}/sa.png +0 -0
- {flags → img/flags}/sb.png +0 -0
- {flags → img/flags}/sc.png +0 -0
- {flags → img/flags}/scotland.png +0 -0
- {flags → img/flags}/sd.png +0 -0
- {flags → img/flags}/se.png +0 -0
- {flags → img/flags}/sg.png +0 -0
- {flags → img/flags}/sh.png +0 -0
- {flags → img/flags}/si.png +0 -0
- {flags → img/flags}/sj.png +0 -0
- {flags → img/flags}/sk.png +0 -0
- {flags → img/flags}/sl.png +0 -0
- {flags → img/flags}/sm.png +0 -0
- {flags → img/flags}/sn.png +0 -0
- {flags → img/flags}/so.png +0 -0
- {flags → img/flags}/sr.png +0 -0
- {flags → img/flags}/st.png +0 -0
- {flags → img/flags}/sv.png +0 -0
- {flags → img/flags}/sy.png +0 -0
- {flags → img/flags}/sz.png +0 -0
- {flags → img/flags}/tc.png +0 -0
- {flags → img/flags}/td.png +0 -0
- {flags → img/flags}/tf.png +0 -0
- {flags → img/flags}/tg.png +0 -0
- {flags → img/flags}/th.png +0 -0
- {flags → img/flags}/tj.png +0 -0
- {flags → img/flags}/tk.png +0 -0
- {flags → img/flags}/tl.png +0 -0
- {flags → img/flags}/tm.png +0 -0
- {flags → img/flags}/tn.png +0 -0
- {flags → img/flags}/to.png +0 -0
- {flags → img/flags}/tr.png +0 -0
- {flags → img/flags}/tt.png +0 -0
- {flags → img/flags}/tv.png +0 -0
- {flags → img/flags}/tw.png +0 -0
- {flags → img/flags}/tz.png +0 -0
- {flags → img/flags}/ua.png +0 -0
- {flags → img/flags}/ug.png +0 -0
- {flags → img/flags}/um.png +0 -0
- {flags → img/flags}/us.png +0 -0
- {flags → img/flags}/uy.png +0 -0
- {flags → img/flags}/uz.png +0 -0
- {flags → img/flags}/va.png +0 -0
- {flags → img/flags}/vc.png +0 -0
- {flags → img/flags}/ve.png +0 -0
- {flags → img/flags}/vg.png +0 -0
- {flags → img/flags}/vi.png +0 -0
- {flags → img/flags}/vn.png +0 -0
- {flags → img/flags}/vu.png +0 -0
- {flags → img/flags}/wales.png +0 -0
- {flags → img/flags}/wf.png +0 -0
- {flags → img/flags}/ws.png +0 -0
- {flags → img/flags}/ye.png +0 -0
- {flags → img/flags}/yt.png +0 -0
- {flags → img/flags}/za.png +0 -0
- {flags → img/flags}/zm.png +0 -0
- {flags → img/flags}/zw.png +0 -0
- tplogo.png → img/tplogo.png +0 -0
- translate.png → img/translate.png +0 -0
- translate_auto.png → img/translate_auto.png +0 -0
- translate_fix.png → img/translate_fix.png +0 -0
- js/transposh.js +48 -41
- readme.txt +14 -3
- transposh.php +116 -367
- transposh_admin.php +39 -55
- transposh_db.php +255 -0
- transposh_widget.php +41 -23
constants.php → core/constants.php
RENAMED
@@ -31,47 +31,47 @@ define("NO_TRANSLATE_CLASS", "no_translate");
|
|
31 |
//Supported languages, new languages can be added here
|
32 |
//the array directs from language code to - Native name, flag
|
33 |
$languages = array("en" => "English,us",
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
"ca" => "
|
38 |
"zh" => "中文(简体),cn",
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
"nl" => "Nederlands,nl",
|
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 |
//Language which are read from right to left (rtl)
|
77 |
$rtl_languages = array("ar", "he");
|
31 |
//Supported languages, new languages can be added here
|
32 |
//the array directs from language code to - Native name, flag
|
33 |
$languages = array("en" => "English,us",
|
34 |
+
"sq" => "Shqip,al",
|
35 |
+
"ar" => "العربية,sa",
|
36 |
+
"bg" => "Български,bg",
|
37 |
+
"ca" => "Català,catalonia",
|
38 |
"zh" => "中文(简体),cn",
|
39 |
+
"zh-tw" => "中文(漢字),tw",
|
40 |
+
"hr" => "Hrvatski,hr",
|
41 |
+
"cs" => "čeština,cz",
|
42 |
+
"da" => "dansk,dk",
|
43 |
"nl" => "Nederlands,nl",
|
44 |
+
"et" => "Eesti keel,ee",
|
45 |
+
"fi" => "Suomi,fi",
|
46 |
+
"fr" => "Français,fr",
|
47 |
+
"gl" => "Galego,galicia",
|
48 |
+
"de" => "Deutsch,de",
|
49 |
+
"el" => "Ελληνικά,gr",
|
50 |
+
"he" => "עברית,il",
|
51 |
+
"hi" => "हिन्दी; हिंदी,in",
|
52 |
+
"hu" => "magyar,hu",
|
53 |
+
"id" => "Bahasa Indonesia,id",
|
54 |
+
"it" => "Italiano,it",
|
55 |
+
"ja" => "日本語 (にほんご/にっぽんご),jp",
|
56 |
+
"ko" => "우리말,kr",
|
57 |
+
"lv" => "latviešu valoda,lv",
|
58 |
+
"lt" => "lietuvių kalba,lt",
|
59 |
+
"mt" => "Malti,mt",
|
60 |
+
"no" => "Norsk,no",
|
61 |
+
"pl" => "Polski,pl",
|
62 |
+
"pt" => "Português,pt",
|
63 |
+
"ro" => "Română,ro",
|
64 |
+
"ru" => "Русский,ru",
|
65 |
+
"sr" => "српски језик,rs",
|
66 |
+
"sk" => "slovenčina,sk",
|
67 |
+
"sl" => "slovenščina,sl",
|
68 |
+
"es" => "Español,es",
|
69 |
+
"sv" => "svenska,se",
|
70 |
+
"tl" => "Tagalog,ph",
|
71 |
+
"th" => "ภาษาไทย,th",
|
72 |
+
"tr" => "Türkçe,tr",
|
73 |
+
"uk" => "Українська,ua",
|
74 |
+
"vi" => "Tiếng Việt,vn");
|
75 |
|
76 |
//Language which are read from right to left (rtl)
|
77 |
$rtl_languages = array("ar", "he");
|
core/globals.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* Copyright © 2009 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 |
+
//Home url of the blog - already quoted and ready for regex
|
31 |
+
$home_url_quoted;
|
32 |
+
|
33 |
+
//The url pointing to the base of the plugin. Used for generatint urls to resources
|
34 |
+
$plugin_url;
|
35 |
+
|
36 |
+
//The language to which the current page will be translated to.
|
37 |
+
$lang;
|
38 |
+
|
39 |
+
//Is the current user is in edit mode.
|
40 |
+
$is_edit_mode = FALSE;
|
41 |
+
|
42 |
+
//Indicates whether automatic translation (i.e. google) is enabled for this page
|
43 |
+
$enable_auto_translate = FALSE;
|
44 |
+
|
45 |
+
//Indicates whether to use parameters when rewriting url as oppposed to using permalinks format
|
46 |
+
// http://wordpress?lang=he vs. http://wordpress/he/ when flag is set to TRUE
|
47 |
+
$enable_permalinks_rewrite = FALSE;
|
48 |
+
|
49 |
+
?>
|
parser.php → core/parser.php
RENAMED
@@ -25,9 +25,8 @@
|
|
25 |
|
26 |
|
27 |
require_once("constants.php");
|
28 |
-
|
29 |
-
|
30 |
-
$lang;
|
31 |
|
32 |
//The html page which starts contains the content being translated
|
33 |
$page;
|
@@ -44,9 +43,6 @@ $tr_page;
|
|
44 |
//Points to the last character that have been copied from the original to the translated page.
|
45 |
$tr_mark = 0;
|
46 |
|
47 |
-
//Is the current use is in edit mode.
|
48 |
-
$is_edit_mode = FALSE;
|
49 |
-
|
50 |
//Segment identifier within tags (span/img) mainly for use by js code on the client
|
51 |
$segment_id = 0;
|
52 |
|
@@ -56,9 +52,6 @@ $is_in_body = FALSE;
|
|
56 |
//Is current position within the channel tag, i.e. RSS feed
|
57 |
$is_in_channel = FALSE;
|
58 |
|
59 |
-
//Indicates whether automatic translation (i.e. google) is enabled for this page
|
60 |
-
$enable_auto_translate;
|
61 |
-
|
62 |
/*
|
63 |
* Parse the html page into tags, identify translateable string which
|
64 |
* will be translated.
|
@@ -495,7 +488,11 @@ function is_translatable_section()
|
|
495 |
$rc = FALSE;
|
496 |
$current_tag = end($tags_list);
|
497 |
|
498 |
-
if($
|
|
|
|
|
|
|
|
|
499 |
{
|
500 |
$rc = TRUE;
|
501 |
}
|
@@ -568,9 +565,9 @@ function is_html_entity($position, &$is_breaker)
|
|
568 |
$entity = substr($page, $position, $end_pos - $position + 1);
|
569 |
|
570 |
//Don't break on ` so for our use we don't consider it an entity
|
571 |
-
//e.g. Jack`s apple.
|
572 |
-
//Exception: don't break when we there is a white space after the apostrophe. e.g. `uncategorized`
|
573 |
-
if(($entity == "’" || $entity == "'" || $entity == "'")
|
574 |
&& $page[$end_pos + 1] != " ")
|
575 |
{
|
576 |
$is_breaker = FALSE;
|
@@ -579,7 +576,7 @@ function is_html_entity($position, &$is_breaker)
|
|
579 |
{
|
580 |
$is_breaker = TRUE;
|
581 |
}
|
582 |
-
|
583 |
|
584 |
//It is an html entity.
|
585 |
return $end_pos + 1;
|
@@ -740,7 +737,7 @@ function is_word($word, $index1)
|
|
740 |
function translate_text($start)
|
741 |
{
|
742 |
|
743 |
-
global $page, $pos;
|
744 |
|
745 |
//trim white space from the start position going forward
|
746 |
skip_white_space($start);
|
@@ -767,7 +764,7 @@ function translate_text($start)
|
|
767 |
return;
|
768 |
}
|
769 |
|
770 |
-
list($translated_text, $source) = fetch_translation($original_text);
|
771 |
|
772 |
insert_translation($original_text, $translated_text, $source, $start, $end);
|
773 |
}
|
@@ -883,19 +880,76 @@ function update_translated_page($start, $end, $translated_text)
|
|
883 |
|
884 |
}
|
885 |
|
886 |
-
|
887 |
-
|
888 |
-
*
|
|
|
889 |
*/
|
890 |
-
function
|
891 |
-
|
892 |
-
|
893 |
|
894 |
-
|
895 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
896 |
*/
|
897 |
-
function
|
898 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
899 |
}
|
900 |
|
901 |
?>
|
25 |
|
26 |
|
27 |
require_once("constants.php");
|
28 |
+
require_once("globals.php");
|
29 |
+
require_once("utils.php");
|
|
|
30 |
|
31 |
//The html page which starts contains the content being translated
|
32 |
$page;
|
43 |
//Points to the last character that have been copied from the original to the translated page.
|
44 |
$tr_mark = 0;
|
45 |
|
|
|
|
|
|
|
46 |
//Segment identifier within tags (span/img) mainly for use by js code on the client
|
47 |
$segment_id = 0;
|
48 |
|
52 |
//Is current position within the channel tag, i.e. RSS feed
|
53 |
$is_in_channel = FALSE;
|
54 |
|
|
|
|
|
|
|
55 |
/*
|
56 |
* Parse the html page into tags, identify translateable string which
|
57 |
* will be translated.
|
488 |
$rc = FALSE;
|
489 |
$current_tag = end($tags_list);
|
490 |
|
491 |
+
if($current_tag == 'title')
|
492 |
+
{
|
493 |
+
$rc = TRUE;
|
494 |
+
}
|
495 |
+
else if($is_in_body && $current_tag != 'style' && $current_tag != 'script')
|
496 |
{
|
497 |
$rc = TRUE;
|
498 |
}
|
565 |
$entity = substr($page, $position, $end_pos - $position + 1);
|
566 |
|
567 |
//Don't break on ` so for our use we don't consider it an entity
|
568 |
+
//e.g. Jack`s apple.
|
569 |
+
//Exception: don't break when we there is a white space after the apostrophe. e.g. `uncategorized`
|
570 |
+
if(($entity == "’" || $entity == "'" || $entity == "'")
|
571 |
&& $page[$end_pos + 1] != " ")
|
572 |
{
|
573 |
$is_breaker = FALSE;
|
576 |
{
|
577 |
$is_breaker = TRUE;
|
578 |
}
|
579 |
+
|
580 |
|
581 |
//It is an html entity.
|
582 |
return $end_pos + 1;
|
737 |
function translate_text($start)
|
738 |
{
|
739 |
|
740 |
+
global $page, $pos, $lang;
|
741 |
|
742 |
//trim white space from the start position going forward
|
743 |
skip_white_space($start);
|
764 |
return;
|
765 |
}
|
766 |
|
767 |
+
list($translated_text, $source) = fetch_translation($original_text, $lang);
|
768 |
|
769 |
insert_translation($original_text, $translated_text, $source, $start, $end);
|
770 |
}
|
880 |
|
881 |
}
|
882 |
|
883 |
+
|
884 |
+
/*
|
885 |
+
* Fix links on the page. href needs to be modified to include
|
886 |
+
* lang specifier and editing mode.
|
887 |
*/
|
888 |
+
function process_anchor_tag($start, $end)
|
889 |
+
{
|
890 |
+
global $home_url, $home_url_quoted, $lang, $is_edit_mode, $enable_permalinks_rewrite;
|
891 |
|
892 |
+
$href = get_attribute($start, $end, 'href');
|
893 |
+
|
894 |
+
if($href == NULL)
|
895 |
+
{
|
896 |
+
return;
|
897 |
+
}
|
898 |
+
|
899 |
+
//Ignore urls not from this site
|
900 |
+
if(stripos($href, $home_url) === FALSE)
|
901 |
+
{
|
902 |
+
return;
|
903 |
+
}
|
904 |
+
|
905 |
+
$use_params = !$enable_permalinks_rewrite;
|
906 |
+
|
907 |
+
//Allow specific override for url rewriting .
|
908 |
+
if($enable_permalinks_rewrite && function_exists('is_url_excluded_from_permalink_rewrite') &&
|
909 |
+
is_url_excluded_from_permalink_rewrite($href))
|
910 |
+
{
|
911 |
+
$use_params = TRUE;
|
912 |
+
}
|
913 |
+
|
914 |
+
$href = rewrite_url_lang_param($href, $lang, $is_edit_mode, $use_params);
|
915 |
+
|
916 |
+
//rewrite url in translated page
|
917 |
+
update_translated_page($start, $end, $href);
|
918 |
+
|
919 |
+
}
|
920 |
+
/*
|
921 |
+
* Return the img tag that will added to enable editing a translatable
|
922 |
+
* item on the page.
|
923 |
+
* param segement_id The id (number) identifying this segment. Needs to be
|
924 |
+
* placed within the img tag for use on client side operation (jquery)
|
925 |
*/
|
926 |
+
function get_img_tag($original, $translation, $source, $segment_id, $is_translated = FALSE)
|
927 |
+
{
|
928 |
+
global $plugin_url, $lang, $home_url;
|
929 |
+
$url = $home_url . '/index.php';
|
930 |
+
|
931 |
+
//For use in javascript, make the following changes:
|
932 |
+
//1. Add slashes to escape the inner text
|
933 |
+
//2. Convert the html special characters
|
934 |
+
//The browser will take decode step 2 and pass it to the js engine which decode step 1 - a bit tricky
|
935 |
+
$translation = htmlspecialchars(addslashes($translation));
|
936 |
+
$original = htmlspecialchars(addslashes($original));
|
937 |
+
|
938 |
+
if ($is_translated)
|
939 |
+
{
|
940 |
+
$add_img = "_fix";
|
941 |
+
}
|
942 |
+
|
943 |
+
if ($source == 1) {
|
944 |
+
$add_img = "_auto";
|
945 |
+
}
|
946 |
+
|
947 |
+
$img = "<img src=\"$plugin_url/img/translate$add_img.png\" alt=\"translate\" class=\"".IMG_PREFIX."\" id=\"" . IMG_PREFIX . "$segment_id\" ".
|
948 |
+
"onclick=\"translate_dialog('$original','$translation','$segment_id'); return false;\" ".
|
949 |
+
"onmouseover=\"hint('$original'); return true;\" ".
|
950 |
+
"onmouseout=\"nd()\" />";
|
951 |
+
|
952 |
+
return $img;
|
953 |
}
|
954 |
|
955 |
?>
|
core/utils.php
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* Copyright © 2009 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 utility functions which are shared across the plugin.
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
|
27 |
+
/*
|
28 |
+
* Update the given url to include language params.
|
29 |
+
* param url - the original url to rewrite
|
30 |
+
* param lang - language code
|
31 |
+
* param is_edit - is running in edit mode.
|
32 |
+
* param use_params_only - use only parameters as modifiers, i.e. not permalinks
|
33 |
+
*/
|
34 |
+
function rewrite_url_lang_param($url, $lang, $is_edit, $use_params_only=FALSE)
|
35 |
+
{
|
36 |
+
global $home_url, $home_url_quoted, $enable_permalinks_rewrite;
|
37 |
+
|
38 |
+
$url = html_entity_decode($url, ENT_NOQUOTES);
|
39 |
+
|
40 |
+
if(!$enable_permalinks_rewrite)
|
41 |
+
{
|
42 |
+
//override the use only params - admin configured system to not touch permalinks
|
43 |
+
$use_params_only = TRUE;
|
44 |
+
}
|
45 |
+
|
46 |
+
if($is_edit)
|
47 |
+
{
|
48 |
+
$params = EDIT_PARAM . '=1&';
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
if($use_params_only)
|
53 |
+
{
|
54 |
+
$params .= LANG_PARAM . "=$lang&";
|
55 |
+
}
|
56 |
+
else
|
57 |
+
{
|
58 |
+
$url = preg_replace("/$home_url_quoted\/(..(-..)?\/)?\/?/",
|
59 |
+
"$home_url/$lang/", $url);
|
60 |
+
}
|
61 |
+
|
62 |
+
if($params)
|
63 |
+
{
|
64 |
+
//insert params to url
|
65 |
+
$url = preg_replace("/(.+\/[^\?\#]*[\?]?)/", '$1?' . $params, $url);
|
66 |
+
|
67 |
+
//Cleanup extra &
|
68 |
+
$url = preg_replace("/&&+/", "&", $url);
|
69 |
+
|
70 |
+
//Cleanup extra ?
|
71 |
+
$url = preg_replace("/\?\?+/", "?", $url);
|
72 |
+
}
|
73 |
+
|
74 |
+
// more cleanups
|
75 |
+
$url = preg_replace("/&$/", "", $url);
|
76 |
+
$url = preg_replace("/\?$/", "", $url);
|
77 |
+
|
78 |
+
$url = htmlentities($url, ENT_NOQUOTES);
|
79 |
+
|
80 |
+
return $url;
|
81 |
+
}
|
82 |
+
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Encode a string as base 64 while avoiding characters which should be avoided
|
86 |
+
* in uri, e.g. + is interpeted as a space.
|
87 |
+
*/
|
88 |
+
function base64_url_encode($input) {
|
89 |
+
return strtr(base64_encode($input), '+/=', '-_,');
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Decode a string previously decoded with base64_url_encode
|
94 |
+
*/
|
95 |
+
function base64_url_decode($input) {
|
96 |
+
return base64_decode(strtr($input, '-_,', '+/='));
|
97 |
+
}
|
98 |
+
|
99 |
+
?>
|
transposh.css → css/transposh.css
RENAMED
@@ -80,7 +80,7 @@ a.olcloD:hover {
|
|
80 |
|
81 |
.olraisedBlue {
|
82 |
text-align:center;
|
83 |
-
background:#33aaff url(raised_blue.gif) repeat-x bottom left;}
|
84 |
|
85 |
table.olraisedBlue {
|
86 |
border-bottom:1px solid #333399;}
|
@@ -92,7 +92,7 @@ table.olraisedBlue {
|
|
92 |
color:#ffffff;}
|
93 |
|
94 |
input.olinput {
|
95 |
-
background:white url(inputText.gif) repeat-x bottom left;
|
96 |
min-height:16px;
|
97 |
font-family:Verdana,Arial,Helvetica,sans-serif;
|
98 |
font-size:13px;
|
80 |
|
81 |
.olraisedBlue {
|
82 |
text-align:center;
|
83 |
+
background:#33aaff url(../js/overlibmws/raised_blue.gif) repeat-x bottom left;}
|
84 |
|
85 |
table.olraisedBlue {
|
86 |
border-bottom:1px solid #333399;}
|
92 |
color:#ffffff;}
|
93 |
|
94 |
input.olinput {
|
95 |
+
background:white url(../js/overlibmws/inputText.gif) repeat-x bottom left;
|
96 |
min-height:16px;
|
97 |
font-family:Verdana,Arial,Helvetica,sans-serif;
|
98 |
font-size:13px;
|
css/transposh_widget.css
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Widget's css
|
3 |
+
*/
|
4 |
+
.transposh_flags {
|
5 |
+
direction: ltr;
|
6 |
+
}
|
7 |
+
|
8 |
+
.transposh_flags a {
|
9 |
+
display: inline;
|
10 |
+
}
|
{flags → img/flags}/ad.png
RENAMED
File without changes
|
{flags → img/flags}/ae.png
RENAMED
File without changes
|
{flags → img/flags}/af.png
RENAMED
File without changes
|
{flags → img/flags}/ag.png
RENAMED
File without changes
|
{flags → img/flags}/ai.png
RENAMED
File without changes
|
{flags → img/flags}/al.png
RENAMED
File without changes
|
{flags → img/flags}/am.png
RENAMED
File without changes
|
{flags → img/flags}/an.png
RENAMED
File without changes
|
{flags → img/flags}/ao.png
RENAMED
File without changes
|
{flags → img/flags}/ar.png
RENAMED
File without changes
|
{flags → img/flags}/as.png
RENAMED
File without changes
|
{flags → img/flags}/at.png
RENAMED
File without changes
|
{flags → img/flags}/au.png
RENAMED
File without changes
|
{flags → img/flags}/aw.png
RENAMED
File without changes
|
{flags → img/flags}/ax.png
RENAMED
File without changes
|
{flags → img/flags}/az.png
RENAMED
File without changes
|
{flags → img/flags}/ba.png
RENAMED
File without changes
|
{flags → img/flags}/bb.png
RENAMED
File without changes
|
{flags → img/flags}/bd.png
RENAMED
File without changes
|
{flags → img/flags}/be.png
RENAMED
File without changes
|
{flags → img/flags}/bf.png
RENAMED
File without changes
|
{flags → img/flags}/bg.png
RENAMED
File without changes
|
{flags → img/flags}/bh.png
RENAMED
File without changes
|
{flags → img/flags}/bi.png
RENAMED
File without changes
|
{flags → img/flags}/bj.png
RENAMED
File without changes
|
{flags → img/flags}/bm.png
RENAMED
File without changes
|
{flags → img/flags}/bn.png
RENAMED
File without changes
|
{flags → img/flags}/bo.png
RENAMED
File without changes
|
{flags → img/flags}/br.png
RENAMED
File without changes
|
{flags → img/flags}/bs.png
RENAMED
File without changes
|
{flags → img/flags}/bt.png
RENAMED
File without changes
|
{flags → img/flags}/bv.png
RENAMED
File without changes
|
{flags → img/flags}/bw.png
RENAMED
File without changes
|
{flags → img/flags}/by.png
RENAMED
File without changes
|
{flags → img/flags}/bz.png
RENAMED
File without changes
|
{flags → img/flags}/ca.png
RENAMED
File without changes
|
{flags → img/flags}/catalonia.png
RENAMED
File without changes
|
{flags → img/flags}/cc.png
RENAMED
File without changes
|
{flags → img/flags}/cd.png
RENAMED
File without changes
|
{flags → img/flags}/cf.png
RENAMED
File without changes
|
{flags → img/flags}/cg.png
RENAMED
File without changes
|
{flags → img/flags}/ch.png
RENAMED
File without changes
|
{flags → img/flags}/ci.png
RENAMED
File without changes
|
{flags → img/flags}/ck.png
RENAMED
File without changes
|
{flags → img/flags}/cl.png
RENAMED
File without changes
|
{flags → img/flags}/cm.png
RENAMED
File without changes
|
{flags → img/flags}/cn.png
RENAMED
File without changes
|
{flags → img/flags}/co.png
RENAMED
File without changes
|
{flags → img/flags}/cr.png
RENAMED
File without changes
|
{flags → img/flags}/cs.png
RENAMED
File without changes
|
{flags → img/flags}/cu.png
RENAMED
File without changes
|
{flags → img/flags}/cv.png
RENAMED
File without changes
|
{flags → img/flags}/cx.png
RENAMED
File without changes
|
{flags → img/flags}/cy.png
RENAMED
File without changes
|
{flags → img/flags}/cz.png
RENAMED
File without changes
|
{flags → img/flags}/de.png
RENAMED
File without changes
|
{flags → img/flags}/dj.png
RENAMED
File without changes
|
{flags → img/flags}/dk.png
RENAMED
File without changes
|
{flags → img/flags}/dm.png
RENAMED
File without changes
|
{flags → img/flags}/do.png
RENAMED
File without changes
|
{flags → img/flags}/dz.png
RENAMED
File without changes
|
{flags → img/flags}/ec.png
RENAMED
File without changes
|
{flags → img/flags}/ee.png
RENAMED
File without changes
|
{flags → img/flags}/eg.png
RENAMED
File without changes
|
{flags → img/flags}/eh.png
RENAMED
File without changes
|
{flags → img/flags}/england.png
RENAMED
File without changes
|
{flags → img/flags}/er.png
RENAMED
File without changes
|
{flags → img/flags}/es.png
RENAMED
File without changes
|
{flags → img/flags}/et.png
RENAMED
File without changes
|
{flags → img/flags}/europeanunion.png
RENAMED
File without changes
|
{flags → img/flags}/fam.png
RENAMED
File without changes
|
{flags → img/flags}/fi.png
RENAMED
File without changes
|
{flags → img/flags}/fj.png
RENAMED
File without changes
|
{flags → img/flags}/fk.png
RENAMED
File without changes
|
{flags → img/flags}/fm.png
RENAMED
File without changes
|
{flags → img/flags}/fo.png
RENAMED
File without changes
|
{flags → img/flags}/fr.png
RENAMED
File without changes
|
{flags → img/flags}/ga.png
RENAMED
File without changes
|
img/flags/galicia.png
ADDED
Binary file
|
{flags → img/flags}/gb.png
RENAMED
File without changes
|
{flags → img/flags}/gd.png
RENAMED
File without changes
|
{flags → img/flags}/ge.png
RENAMED
File without changes
|
{flags → img/flags}/gf.png
RENAMED
File without changes
|
{flags → img/flags}/gh.png
RENAMED
File without changes
|
{flags → img/flags}/gi.png
RENAMED
File without changes
|
{flags → img/flags}/gl.png
RENAMED
File without changes
|
{flags → img/flags}/gm.png
RENAMED
File without changes
|
{flags → img/flags}/gn.png
RENAMED
File without changes
|
{flags → img/flags}/gp.png
RENAMED
File without changes
|
{flags → img/flags}/gq.png
RENAMED
File without changes
|
{flags → img/flags}/gr.png
RENAMED
File without changes
|
{flags → img/flags}/gs.png
RENAMED
File without changes
|
{flags → img/flags}/gt.png
RENAMED
File without changes
|
{flags → img/flags}/gu.png
RENAMED
File without changes
|
{flags → img/flags}/gw.png
RENAMED
File without changes
|
{flags → img/flags}/gy.png
RENAMED
File without changes
|
{flags → img/flags}/hk.png
RENAMED
File without changes
|
{flags → img/flags}/hm.png
RENAMED
File without changes
|
{flags → img/flags}/hn.png
RENAMED
File without changes
|
{flags → img/flags}/hr.png
RENAMED
File without changes
|
{flags → img/flags}/ht.png
RENAMED
File without changes
|
{flags → img/flags}/hu.png
RENAMED
File without changes
|
{flags → img/flags}/id.png
RENAMED
File without changes
|
{flags → img/flags}/ie.png
RENAMED
File without changes
|
{flags → img/flags}/il.png
RENAMED
File without changes
|
{flags → img/flags}/in.png
RENAMED
File without changes
|
{flags → img/flags}/io.png
RENAMED
File without changes
|
{flags → img/flags}/iq.png
RENAMED
File without changes
|
{flags → img/flags}/ir.png
RENAMED
File without changes
|
{flags → img/flags}/is.png
RENAMED
File without changes
|
{flags → img/flags}/it.png
RENAMED
File without changes
|
{flags → img/flags}/jm.png
RENAMED
File without changes
|
{flags → img/flags}/jo.png
RENAMED
File without changes
|
{flags → img/flags}/jp.png
RENAMED
File without changes
|
{flags → img/flags}/ke.png
RENAMED
File without changes
|
{flags → img/flags}/kg.png
RENAMED
File without changes
|
{flags → img/flags}/kh.png
RENAMED
File without changes
|
{flags → img/flags}/ki.png
RENAMED
File without changes
|
{flags → img/flags}/km.png
RENAMED
File without changes
|
{flags → img/flags}/kn.png
RENAMED
File without changes
|
{flags → img/flags}/kp.png
RENAMED
File without changes
|
{flags → img/flags}/kr.png
RENAMED
File without changes
|
{flags → img/flags}/kw.png
RENAMED
File without changes
|
{flags → img/flags}/ky.png
RENAMED
File without changes
|
{flags → img/flags}/kz.png
RENAMED
File without changes
|
{flags → img/flags}/la.png
RENAMED
File without changes
|
{flags → img/flags}/lb.png
RENAMED
File without changes
|
{flags → img/flags}/lc.png
RENAMED
File without changes
|
{flags → img/flags}/li.png
RENAMED
File without changes
|
{flags → img/flags}/lk.png
RENAMED
File without changes
|
{flags → img/flags}/lr.png
RENAMED
File without changes
|
{flags → img/flags}/ls.png
RENAMED
File without changes
|
{flags → img/flags}/lt.png
RENAMED
File without changes
|
{flags → img/flags}/lu.png
RENAMED
File without changes
|
{flags → img/flags}/lv.png
RENAMED
File without changes
|
{flags → img/flags}/ly.png
RENAMED
File without changes
|
{flags → img/flags}/ma.png
RENAMED
File without changes
|
{flags → img/flags}/mc.png
RENAMED
File without changes
|
{flags → img/flags}/md.png
RENAMED
File without changes
|
{flags → img/flags}/me.png
RENAMED
File without changes
|
{flags → img/flags}/mg.png
RENAMED
File without changes
|
{flags → img/flags}/mh.png
RENAMED
File without changes
|
{flags → img/flags}/mk.png
RENAMED
File without changes
|
{flags → img/flags}/ml.png
RENAMED
File without changes
|
{flags → img/flags}/mm.png
RENAMED
File without changes
|
{flags → img/flags}/mn.png
RENAMED
File without changes
|
{flags → img/flags}/mo.png
RENAMED
File without changes
|
{flags → img/flags}/mp.png
RENAMED
File without changes
|
{flags → img/flags}/mq.png
RENAMED
File without changes
|
{flags → img/flags}/mr.png
RENAMED
File without changes
|
{flags → img/flags}/ms.png
RENAMED
File without changes
|
{flags → img/flags}/mt.png
RENAMED
File without changes
|
{flags → img/flags}/mu.png
RENAMED
File without changes
|
{flags → img/flags}/mv.png
RENAMED
File without changes
|
{flags → img/flags}/mw.png
RENAMED
File without changes
|
{flags → img/flags}/mx.png
RENAMED
File without changes
|
{flags → img/flags}/my.png
RENAMED
File without changes
|
{flags → img/flags}/mz.png
RENAMED
File without changes
|
{flags → img/flags}/na.png
RENAMED
File without changes
|
{flags → img/flags}/nc.png
RENAMED
File without changes
|
{flags → img/flags}/ne.png
RENAMED
File without changes
|
{flags → img/flags}/nf.png
RENAMED
File without changes
|
{flags → img/flags}/ng.png
RENAMED
File without changes
|
{flags → img/flags}/ni.png
RENAMED
File without changes
|
{flags → img/flags}/nl.png
RENAMED
File without changes
|
{flags → img/flags}/no.png
RENAMED
File without changes
|
{flags → img/flags}/np.png
RENAMED
File without changes
|
{flags → img/flags}/nr.png
RENAMED
File without changes
|
{flags → img/flags}/nu.png
RENAMED
File without changes
|
{flags → img/flags}/nz.png
RENAMED
File without changes
|
{flags → img/flags}/om.png
RENAMED
File without changes
|
{flags → img/flags}/pa.png
RENAMED
File without changes
|
{flags → img/flags}/pe.png
RENAMED
File without changes
|
{flags → img/flags}/pf.png
RENAMED
File without changes
|
{flags → img/flags}/pg.png
RENAMED
File without changes
|
{flags → img/flags}/ph.png
RENAMED
File without changes
|
{flags → img/flags}/pk.png
RENAMED
File without changes
|
{flags → img/flags}/pl.png
RENAMED
File without changes
|
{flags → img/flags}/pm.png
RENAMED
File without changes
|
{flags → img/flags}/pn.png
RENAMED
File without changes
|
{flags → img/flags}/pr.png
RENAMED
File without changes
|
{flags → img/flags}/ps.png
RENAMED
File without changes
|
{flags → img/flags}/pt.png
RENAMED
File without changes
|
{flags → img/flags}/pw.png
RENAMED
File without changes
|
{flags → img/flags}/py.png
RENAMED
File without changes
|
{flags → img/flags}/qa.png
RENAMED
File without changes
|
{flags → img/flags}/re.png
RENAMED
File without changes
|
{flags → img/flags}/ro.png
RENAMED
File without changes
|
{flags → img/flags}/rs.png
RENAMED
File without changes
|
{flags → img/flags}/ru.png
RENAMED
File without changes
|
{flags → img/flags}/rw.png
RENAMED
File without changes
|
{flags → img/flags}/sa.png
RENAMED
File without changes
|
{flags → img/flags}/sb.png
RENAMED
File without changes
|
{flags → img/flags}/sc.png
RENAMED
File without changes
|
{flags → img/flags}/scotland.png
RENAMED
File without changes
|
{flags → img/flags}/sd.png
RENAMED
File without changes
|
{flags → img/flags}/se.png
RENAMED
File without changes
|
{flags → img/flags}/sg.png
RENAMED
File without changes
|
{flags → img/flags}/sh.png
RENAMED
File without changes
|
{flags → img/flags}/si.png
RENAMED
File without changes
|
{flags → img/flags}/sj.png
RENAMED
File without changes
|
{flags → img/flags}/sk.png
RENAMED
File without changes
|
{flags → img/flags}/sl.png
RENAMED
File without changes
|
{flags → img/flags}/sm.png
RENAMED
File without changes
|
{flags → img/flags}/sn.png
RENAMED
File without changes
|
{flags → img/flags}/so.png
RENAMED
File without changes
|
{flags → img/flags}/sr.png
RENAMED
File without changes
|
{flags → img/flags}/st.png
RENAMED
File without changes
|
{flags → img/flags}/sv.png
RENAMED
File without changes
|
{flags → img/flags}/sy.png
RENAMED
File without changes
|
{flags → img/flags}/sz.png
RENAMED
File without changes
|
{flags → img/flags}/tc.png
RENAMED
File without changes
|
{flags → img/flags}/td.png
RENAMED
File without changes
|
{flags → img/flags}/tf.png
RENAMED
File without changes
|
{flags → img/flags}/tg.png
RENAMED
File without changes
|
{flags → img/flags}/th.png
RENAMED
File without changes
|
{flags → img/flags}/tj.png
RENAMED
File without changes
|
{flags → img/flags}/tk.png
RENAMED
File without changes
|
{flags → img/flags}/tl.png
RENAMED
File without changes
|
{flags → img/flags}/tm.png
RENAMED
File without changes
|
{flags → img/flags}/tn.png
RENAMED
File without changes
|
{flags → img/flags}/to.png
RENAMED
File without changes
|
{flags → img/flags}/tr.png
RENAMED
File without changes
|
{flags → img/flags}/tt.png
RENAMED
File without changes
|
{flags → img/flags}/tv.png
RENAMED
File without changes
|
{flags → img/flags}/tw.png
RENAMED
File without changes
|
{flags → img/flags}/tz.png
RENAMED
File without changes
|
{flags → img/flags}/ua.png
RENAMED
File without changes
|
{flags → img/flags}/ug.png
RENAMED
File without changes
|
{flags → img/flags}/um.png
RENAMED
File without changes
|
{flags → img/flags}/us.png
RENAMED
File without changes
|
{flags → img/flags}/uy.png
RENAMED
File without changes
|
{flags → img/flags}/uz.png
RENAMED
File without changes
|
{flags → img/flags}/va.png
RENAMED
File without changes
|
{flags → img/flags}/vc.png
RENAMED
File without changes
|
{flags → img/flags}/ve.png
RENAMED
File without changes
|
{flags → img/flags}/vg.png
RENAMED
File without changes
|
{flags → img/flags}/vi.png
RENAMED
File without changes
|
{flags → img/flags}/vn.png
RENAMED
File without changes
|
{flags → img/flags}/vu.png
RENAMED
File without changes
|
{flags → img/flags}/wales.png
RENAMED
File without changes
|
{flags → img/flags}/wf.png
RENAMED
File without changes
|
{flags → img/flags}/ws.png
RENAMED
File without changes
|
{flags → img/flags}/ye.png
RENAMED
File without changes
|
{flags → img/flags}/yt.png
RENAMED
File without changes
|
{flags → img/flags}/za.png
RENAMED
File without changes
|
{flags → img/flags}/zm.png
RENAMED
File without changes
|
{flags → img/flags}/zw.png
RENAMED
File without changes
|
tplogo.png → img/tplogo.png
RENAMED
File without changes
|
translate.png → img/translate.png
RENAMED
File without changes
|
translate_auto.png → img/translate_auto.png
RENAMED
File without changes
|
translate_fix.png → img/translate_fix.png
RENAMED
File without changes
|
js/transposh.js
CHANGED
@@ -49,26 +49,23 @@ function hint(original)
|
|
49 |
// fetch translation from google translate...
|
50 |
function getgt()
|
51 |
{
|
52 |
-
google.language.translate(jQuery("#tr_original_unescaped").text(), "",
|
53 |
if (!result.error) {
|
54 |
-
jQuery("#tr_translation").val(result.translation);
|
55 |
}
|
56 |
});
|
57 |
}
|
58 |
|
59 |
//Ajax translation
|
60 |
function ajax_translate(original,translation,source,segment_id) {
|
61 |
-
var token = jQuery("#tr_" + segment_id).attr('token');
|
62 |
-
var query = 'token=' + token +
|
63 |
-
'&translation=' + translation +
|
64 |
-
'&lang=' + transposh_target_lang +
|
65 |
-
'&source=' + source +
|
66 |
-
'&translation_posted=1';
|
67 |
-
|
68 |
jQuery.ajax({
|
69 |
type: "POST",
|
70 |
-
url:
|
71 |
-
data:
|
|
|
|
|
|
|
|
|
72 |
success: function(req) {
|
73 |
var pre_translated = jQuery("#tr_" + segment_id).html();
|
74 |
var new_text = translation;
|
@@ -82,34 +79,35 @@ function ajax_translate(original,translation,source,segment_id) {
|
|
82 |
var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1);
|
83 |
//current img
|
84 |
var img = jQuery("#tr_img_" + img_segment_id).attr('src');
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
//switch to the edit img
|
94 |
-
|
95 |
-
img = img.replace(/translate_auto.png/, "translate.png");
|
96 |
-
} else {
|
97 |
-
if (source == 1) {
|
98 |
-
//switch to the auto img
|
99 |
-
img = img.replace(/translate.png/, "translate_auto.png");
|
100 |
} else {
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
|
109 |
});
|
110 |
|
111 |
//close dialog
|
112 |
-
|
|
|
|
|
113 |
},
|
114 |
|
115 |
error: function(req) {
|
@@ -118,7 +116,6 @@ function ajax_translate(original,translation,source,segment_id) {
|
|
118 |
}
|
119 |
}
|
120 |
});
|
121 |
-
|
122 |
}
|
123 |
|
124 |
//Open translation dialog
|
@@ -127,13 +124,13 @@ function translate_dialog(original, trans, segment_id)
|
|
127 |
caption='Edit Translation';
|
128 |
//alert (this.id);
|
129 |
var dialog = ''+
|
130 |
-
('<form id="tr_form" name="transposh_edit_form" method="post" action="' +
|
131 |
'<p dir="ltr">Original text<br \/><textarea id="tr_original_unescaped" cols="60" rows="3" readonly="readyonly">' +
|
132 |
original + '</textarea> <\/p>' +
|
133 |
-
'<p>Translate to<br \/><input type="text" id="tr_translation" name="translation" size="80" value="'+ trans +
|
134 |
'"' + 'onfocus="OLmEdit=1;" onblur="OLmEdit=0;"<\/p>' +
|
135 |
'<input type="hidden" name="translation_posted" value= "1">' +
|
136 |
-
'<p><input onclick="getgt()" type="button" value="Get Suggestion!"/> <input type="submit" value="Translate"/><\/p>' +
|
137 |
('<\/div><\/form>');
|
138 |
|
139 |
display_dialog(caption, dialog);
|
@@ -155,10 +152,10 @@ var dialog = ''+
|
|
155 |
function do_auto_translate() {
|
156 |
jQuery(".tr_u").each(function (i) {
|
157 |
var translated_id = jQuery(this).attr('id');
|
158 |
-
google.language.translate(jQuery(this).text(), "",
|
159 |
if (!result.error) {
|
160 |
var segment_id = translated_id.substr(translated_id.lastIndexOf('_')+1);
|
161 |
-
ajax_translate(jQuery("#"+translated_id).text(),result.translation,1,segment_id);
|
162 |
jQuery("#"+translated_id).addClass("tr_t").removeClass("tr_u");
|
163 |
}
|
164 |
});
|
@@ -167,11 +164,21 @@ function do_auto_translate() {
|
|
167 |
|
168 |
//to run at start
|
169 |
jQuery.noConflict();
|
170 |
-
|
|
|
171 |
jQuery("script[src*='transposh.js']").each(function (i) {
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
});
|
|
|
175 |
google.load("language", "1");
|
176 |
jQuery(document).ready(
|
177 |
function() {
|
49 |
// fetch translation from google translate...
|
50 |
function getgt()
|
51 |
{
|
52 |
+
google.language.translate(jQuery("#tr_original_unescaped").text(), "", transposh_params['lang'], function(result) {
|
53 |
if (!result.error) {
|
54 |
+
jQuery("#tr_translation").val(jQuery("<div>"+result.translation+"</div>").text());
|
55 |
}
|
56 |
});
|
57 |
}
|
58 |
|
59 |
//Ajax translation
|
60 |
function ajax_translate(original,translation,source,segment_id) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
jQuery.ajax({
|
62 |
type: "POST",
|
63 |
+
url: transposh_params['post_url'],
|
64 |
+
data: {token: jQuery("#tr_" + segment_id).attr('token'),
|
65 |
+
translation: translation,
|
66 |
+
lang: transposh_params['lang'],
|
67 |
+
source: source,
|
68 |
+
translation_posted: "1"},
|
69 |
success: function(req) {
|
70 |
var pre_translated = jQuery("#tr_" + segment_id).html();
|
71 |
var new_text = translation;
|
79 |
var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1);
|
80 |
//current img
|
81 |
var img = jQuery("#tr_img_" + img_segment_id).attr('src');
|
82 |
+
if (img != undefined) {
|
83 |
+
//rewrite onclick function - in case of re-edit
|
84 |
+
jQuery("#tr_img_" + img_segment_id).click(function () {
|
85 |
+
translate_dialog(original, translation, img_segment_id);
|
86 |
+
});
|
87 |
+
img = img.substr(0,img.lastIndexOf("/")) + "/";
|
88 |
+
// handle image
|
89 |
+
if(jQuery.trim(translation).length == 0) {
|
90 |
//switch to the edit img
|
91 |
+
img += "translate.png";
|
|
|
|
|
|
|
|
|
|
|
92 |
} else {
|
93 |
+
if (source == 1) {
|
94 |
+
//switch to the auto img
|
95 |
+
img += "translate_auto.png";
|
96 |
+
} else {
|
97 |
+
// switch to the fix img
|
98 |
+
img += "translate_fix.png";
|
99 |
+
}
|
100 |
}
|
101 |
+
// rewrite image
|
102 |
+
jQuery("#tr_img_" + img_segment_id).attr('src', img);
|
103 |
+
};
|
104 |
|
105 |
});
|
106 |
|
107 |
//close dialog
|
108 |
+
if (typeof cClick == 'function' && source == 0) {
|
109 |
+
cClick();
|
110 |
+
}
|
111 |
},
|
112 |
|
113 |
error: function(req) {
|
116 |
}
|
117 |
}
|
118 |
});
|
|
|
119 |
}
|
120 |
|
121 |
//Open translation dialog
|
124 |
caption='Edit Translation';
|
125 |
//alert (this.id);
|
126 |
var dialog = ''+
|
127 |
+
('<form id="tr_form" name="transposh_edit_form" method="post" action="' + transposh_params['post_url'] + '"><div>') +
|
128 |
'<p dir="ltr">Original text<br \/><textarea id="tr_original_unescaped" cols="60" rows="3" readonly="readyonly">' +
|
129 |
original + '</textarea> <\/p>' +
|
130 |
+
'<p>Translate to<br \/><input class="olinput" type="text" id="tr_translation" name="translation" size="80" value="'+ trans +
|
131 |
'"' + 'onfocus="OLmEdit=1;" onblur="OLmEdit=0;"<\/p>' +
|
132 |
'<input type="hidden" name="translation_posted" value= "1">' +
|
133 |
+
'<p><input class="olinput" onclick="getgt()" type="button" value="Get Suggestion!"/> <input class="olinput" type="submit" value="Translate"/><\/p>' +
|
134 |
('<\/div><\/form>');
|
135 |
|
136 |
display_dialog(caption, dialog);
|
152 |
function do_auto_translate() {
|
153 |
jQuery(".tr_u").each(function (i) {
|
154 |
var translated_id = jQuery(this).attr('id');
|
155 |
+
google.language.translate(jQuery(this).text(), "", transposh_params['lang'], function(result) {
|
156 |
if (!result.error) {
|
157 |
var segment_id = translated_id.substr(translated_id.lastIndexOf('_')+1);
|
158 |
+
ajax_translate(jQuery("#"+translated_id).text(),jQuery("<div>"+result.translation+"</div>").text(),1,segment_id);
|
159 |
jQuery("#"+translated_id).addClass("tr_t").removeClass("tr_u");
|
160 |
}
|
161 |
});
|
164 |
|
165 |
//to run at start
|
166 |
jQuery.noConflict();
|
167 |
+
//read parameters
|
168 |
+
var transposh_params = new Array();
|
169 |
jQuery("script[src*='transposh.js']").each(function (i) {
|
170 |
+
var query_string = unescape(this.src.substring(this.src.indexOf('?')+1));
|
171 |
+
var parms = query_string.split('&');
|
172 |
+
for (var i=0; i<parms.length; i++) {
|
173 |
+
var pos = parms[i].indexOf('=');
|
174 |
+
if (pos > 0) {
|
175 |
+
var key = parms[i].substring(0,pos);
|
176 |
+
var val = parms[i].substring(pos+1);
|
177 |
+
transposh_params[key] = val;
|
178 |
+
}
|
179 |
+
}
|
180 |
});
|
181 |
+
|
182 |
google.load("language", "1");
|
183 |
jQuery(document).ready(
|
184 |
function() {
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://transposh.org/
|
|
4 |
Tags: translation, widget, filter, bilingual, multilingual, transposh, language, RTL, Hebrew, Spanish, French, Russian, English, Arabic, crowdsourcing, context, wiki
|
5 |
Requires at least: 2.7
|
6 |
Tested up to: 2.7.1
|
7 |
-
Stable tag: 0.1.
|
8 |
|
9 |
Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
|
10 |
|
@@ -70,6 +70,13 @@ There are currently three colors used
|
|
70 |
Wiki has proven itself quite a valid model on the Internet. More people have good intentions than bad intentions and that can be
|
71 |
harnessed to get your message out to more people. Future versions will give more focus on preventing spammers from defacing sites
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
== Screenshots ==
|
74 |
|
75 |
1. This is a screen shot of a site using Transposh widget on the sidebar
|
@@ -80,11 +87,15 @@ harnessed to get your message out to more people. Future versions will give more
|
|
80 |
|
81 |
== Release notes ==
|
82 |
|
|
|
|
|
|
|
|
|
83 |
* 2009/03/24 - 0.1.1
|
84 |
-
* Fixed
|
85 |
* Fixed minor issues with encoding some strings
|
86 |
* Verify UTF charset and collation upon database creation
|
87 |
-
* Some CSS
|
88 |
* 2009/03/22 - 0.1.0
|
89 |
* Enabled automatic translation for site readers
|
90 |
* Added many languages to the default list
|
4 |
Tags: translation, widget, filter, bilingual, multilingual, transposh, language, RTL, Hebrew, Spanish, French, Russian, English, Arabic, crowdsourcing, context, wiki
|
5 |
Requires at least: 2.7
|
6 |
Tested up to: 2.7.1
|
7 |
+
Stable tag: 0.1.2
|
8 |
|
9 |
Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
|
10 |
|
70 |
Wiki has proven itself quite a valid model on the Internet. More people have good intentions than bad intentions and that can be
|
71 |
harnessed to get your message out to more people. Future versions will give more focus on preventing spammers from defacing sites
|
72 |
|
73 |
+
= I have installed the plugin - nothing happens =
|
74 |
+
|
75 |
+
By default, automatic translation is on and it should be kicking in. If its off, and you don't have enough privileges
|
76 |
+
to translate, nothing will happen.
|
77 |
+
|
78 |
+
If everything is setup correctly and still nothing happens, please contact us.
|
79 |
+
|
80 |
== Screenshots ==
|
81 |
|
82 |
1. This is a screen shot of a site using Transposh widget on the sidebar
|
87 |
|
88 |
== Release notes ==
|
89 |
|
90 |
+
* 2009/03/31 - 0.1.2
|
91 |
+
* Made sure our code passes w3c validation
|
92 |
+
* Added missing flags for two languages
|
93 |
+
* Auto translation should always work if set (even to non translators)
|
94 |
* 2009/03/24 - 0.1.1
|
95 |
+
* Fixed compatibility issues with other scripts (thanks [Eike](http://spotterblog.de/))
|
96 |
* Fixed minor issues with encoding some strings
|
97 |
* Verify UTF charset and collation upon database creation
|
98 |
+
* Some CSS improvements
|
99 |
* 2009/03/22 - 0.1.0
|
100 |
* Enabled automatic translation for site readers
|
101 |
* Added many languages to the default list
|
transposh.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
Plugin URI: http://transposh.org/#
|
5 |
Description: Translation filter for WordPress, After enabling please set languages at the <a href="options-general.php?page=Transposh">the options page</a> Want to help? visit our development site at <a href="http://trac.transposh.org/">trac.transposh.org</a>.
|
6 |
Author: Team Transposh
|
7 |
-
Version: 0.1.
|
8 |
Author URI: http://transposh.org/
|
9 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
10 |
*/
|
@@ -26,42 +26,11 @@
|
|
26 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
27 |
*/
|
28 |
|
29 |
-
|
30 |
-
require_once("
|
31 |
-
require_once("parser.php");
|
32 |
require_once("transposh_widget.php");
|
33 |
require_once("transposh_admin.php");
|
34 |
|
35 |
-
//
|
36 |
-
//Constants
|
37 |
-
//
|
38 |
-
|
39 |
-
//Table name in database for storing translations
|
40 |
-
define("TRANSLATIONS_TABLE", "translations");
|
41 |
-
define("TRANSLATIONS_LOG", "translations_log");
|
42 |
-
|
43 |
-
//Database version
|
44 |
-
define("DB_VERSION", "1.02");
|
45 |
-
|
46 |
-
//Constant used as key in options database
|
47 |
-
define("TRANSPOSH_DB_VERSION", "transposh_db_version");
|
48 |
-
|
49 |
-
//
|
50 |
-
// Global variables
|
51 |
-
//
|
52 |
-
|
53 |
-
//The full table name, i.e. prefix + name
|
54 |
-
$table_name;
|
55 |
-
|
56 |
-
//Home url of the blog
|
57 |
-
$home_url;
|
58 |
-
|
59 |
-
//Home url of the blog - already quoted and ready for regex
|
60 |
-
$home_url_quoted;
|
61 |
-
|
62 |
-
//The url pointing to the base of the plugin
|
63 |
-
$plugin_url;
|
64 |
-
|
65 |
//Error message displayed for the admin in case of failure
|
66 |
$admin_msg;
|
67 |
|
@@ -71,7 +40,7 @@ $admin_msg;
|
|
71 |
*/
|
72 |
function process_page(&$buffer) {
|
73 |
|
74 |
-
global $wp_query, $tr_page, $page, $pos, $lang, $plugin_url, $is_edit_mode
|
75 |
|
76 |
$start_time = microtime(TRUE);
|
77 |
|
@@ -93,17 +62,10 @@ function process_page(&$buffer) {
|
|
93 |
|
94 |
$page = $buffer;
|
95 |
|
96 |
-
if (($wp_query->query_vars[EDIT_PARAM] == "1" ||
|
97 |
-
|
98 |
{
|
99 |
-
|
100 |
-
//user has the required permissions
|
101 |
-
$editable_langs = get_option(EDITABLE_LANGS);
|
102 |
-
|
103 |
-
if(is_translator() && strstr($editable_langs, $lang))
|
104 |
-
{
|
105 |
-
$is_edit_mode = TRUE;
|
106 |
-
}
|
107 |
}
|
108 |
|
109 |
|
@@ -120,192 +82,13 @@ function process_page(&$buffer) {
|
|
120 |
}
|
121 |
|
122 |
/*
|
123 |
-
*
|
124 |
-
*
|
125 |
-
|
126 |
-
function process_anchor_tag($start, $end)
|
127 |
-
{
|
128 |
-
global $home_url, $home_url_quoted, $lang, $is_edit_mode, $wp_rewrite;
|
129 |
-
|
130 |
-
$href = get_attribute($start, $end, 'href');
|
131 |
-
|
132 |
-
if($href == NULL)
|
133 |
-
{
|
134 |
-
return;
|
135 |
-
}
|
136 |
-
|
137 |
-
//Ignore urls not from this site
|
138 |
-
if(stripos($href, $home_url) === FALSE)
|
139 |
-
{
|
140 |
-
return;
|
141 |
-
}
|
142 |
-
|
143 |
-
$use_params = FALSE;
|
144 |
-
|
145 |
-
//Only use params if permalinks are not enabled.
|
146 |
-
//don't fix links pointing to real files as it will cause that the
|
147 |
-
//web server will not be able to locate them
|
148 |
-
if(!$wp_rewrite->using_permalinks() ||
|
149 |
-
stripos($href, '/wp-admin') !== FALSE ||
|
150 |
-
stripos($href, '/wp-content') !== FALSE ||
|
151 |
-
stripos($href, '/wp-login') !== FALSE ||
|
152 |
-
stripos($href, '/.php') !== FALSE)
|
153 |
-
{
|
154 |
-
$use_params = TRUE;
|
155 |
-
}
|
156 |
-
|
157 |
-
$href = rewrite_url_lang_param($href, $lang, $is_edit_mode, $use_params);
|
158 |
-
|
159 |
-
//rewrite url in translated page
|
160 |
-
update_translated_page($start, $end, $href);
|
161 |
-
|
162 |
-
}
|
163 |
-
|
164 |
-
/*
|
165 |
-
* Update the given url to include language params.
|
166 |
-
* param url - the original url to rewrite
|
167 |
-
* param lang - language code
|
168 |
-
* param is_edit - is running in edit mode.
|
169 |
-
* param use_params_only - use only parameters as modifiers, i.e. not permalinks
|
170 |
-
*/
|
171 |
-
function rewrite_url_lang_param($url, $lang, $is_edit, $use_params_only)
|
172 |
-
{
|
173 |
-
global $home_url, $home_url_quoted;
|
174 |
-
|
175 |
-
if(!get_option(ENABLE_PERMALINKS_REWRITE))
|
176 |
-
{
|
177 |
-
//override the use only params - admin configured system to not touch permalinks
|
178 |
-
$use_params_only = TRUE;
|
179 |
-
}
|
180 |
-
|
181 |
-
if($is_edit)
|
182 |
-
{
|
183 |
-
$params = EDIT_PARAM . '=1&';
|
184 |
-
|
185 |
-
}
|
186 |
-
|
187 |
-
if($use_params_only)
|
188 |
-
{
|
189 |
-
$params .= LANG_PARAM . "=$lang&";
|
190 |
-
}
|
191 |
-
else
|
192 |
-
{
|
193 |
-
$url = preg_replace("/$home_url_quoted\/(..(-..)?\/)?\/?/",
|
194 |
-
"$home_url/$lang/", $url);
|
195 |
-
}
|
196 |
-
|
197 |
-
if($params)
|
198 |
-
{
|
199 |
-
//insert params to url
|
200 |
-
$url = preg_replace("/(.+\/[^\?\#]*[\?]?)/", '$1?' . $params, $url);
|
201 |
-
|
202 |
-
//Cleanup extra &
|
203 |
-
$url = preg_replace("/&&+/", "&", $url);
|
204 |
-
|
205 |
-
//Cleanup extra ?
|
206 |
-
$url = preg_replace("/\?\?+/", "?", $url);
|
207 |
-
}
|
208 |
-
|
209 |
-
return $url;
|
210 |
-
}
|
211 |
-
|
212 |
-
/*
|
213 |
-
* Fetch translation from db or cache.
|
214 |
-
* Returns An array that contains the translated string and it source.
|
215 |
-
* Will return NULL if no translation is available.
|
216 |
-
*/
|
217 |
-
function fetch_translation($original)
|
218 |
-
{
|
219 |
-
global $wpdb, $lang, $table_name;
|
220 |
-
$translated = NULL;
|
221 |
-
|
222 |
-
|
223 |
-
//The original is saved in db in its escaped form
|
224 |
-
$original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
|
225 |
-
|
226 |
-
if(ENABLE_APC && function_exists('apc_fetch'))
|
227 |
-
{
|
228 |
-
$cached = apc_fetch($original .'___'. $lang, $rc);
|
229 |
-
if($rc === TRUE)
|
230 |
-
{
|
231 |
-
|
232 |
-
return $cached;
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
-
$query = "SELECT * FROM $table_name WHERE original = '$original' and lang = '$lang' ";
|
237 |
-
$row = $wpdb->get_row($query);
|
238 |
-
|
239 |
-
if($row !== FALSE)
|
240 |
-
{
|
241 |
-
$translated_text = stripslashes($row->translated);
|
242 |
-
$translated = array($translated_text, $row->source);
|
243 |
-
|
244 |
-
|
245 |
-
}
|
246 |
-
|
247 |
-
if(ENABLE_APC && function_exists('apc_store'))
|
248 |
-
{
|
249 |
-
//If we don't have translation still we want to have it in cache
|
250 |
-
$cache_entry = $translated;
|
251 |
-
if($cache_entry == NULL)
|
252 |
-
{
|
253 |
-
$cache_entry = "";
|
254 |
-
}
|
255 |
-
|
256 |
-
//update cache
|
257 |
-
$rc = apc_store($original .'___'. $lang, $cache_entry, 3600);
|
258 |
-
if($rc === TRUE)
|
259 |
-
{
|
260 |
-
|
261 |
-
}
|
262 |
-
}
|
263 |
-
|
264 |
-
|
265 |
-
return $translated;
|
266 |
-
}
|
267 |
-
|
268 |
-
/*
|
269 |
-
* Return the img tag that will added to enable editing a translatable
|
270 |
-
* item on the page.
|
271 |
-
* param segement_id The id (number) identifying this segment. Needs to be
|
272 |
-
* placed within the img tag for use on client side operation (jquery)
|
273 |
-
*/
|
274 |
-
function get_img_tag($original, $translation, $source, $segment_id, $is_translated = FALSE)
|
275 |
-
{
|
276 |
-
global $plugin_url, $lang, $home_url;
|
277 |
-
$url = $home_url . '/index.php';
|
278 |
-
|
279 |
-
//For use in javascript, make the following changes:
|
280 |
-
//1. Add slashes to escape the inner text
|
281 |
-
//2. Convert the html special characters
|
282 |
-
//The browser will take decode step 2 and pass it to the js engine which decode step 1 - a bit tricky
|
283 |
-
$translation = htmlspecialchars(addslashes($translation));
|
284 |
-
$original = htmlspecialchars(addslashes($original));
|
285 |
-
|
286 |
-
if ($is_translated)
|
287 |
-
{
|
288 |
-
$add_img = "_fix";
|
289 |
-
}
|
290 |
-
|
291 |
-
if ($source == 1) {
|
292 |
-
$add_img = "_auto";
|
293 |
-
}
|
294 |
-
|
295 |
-
$img = "<img src=\"$plugin_url/translate$add_img.png\" alt=\"translate\" class=\"".IMG_PREFIX."\" id=\"" . IMG_PREFIX . "$segment_id\" ".
|
296 |
-
"onclick=\"translate_dialog('$original','$translation','$segment_id'); return false;\" ".
|
297 |
-
"onmouseover=\"hint('$original'); return true;\" ".
|
298 |
-
"onmouseout=\"nd()\" />";
|
299 |
-
|
300 |
-
return $img;
|
301 |
-
}
|
302 |
-
|
303 |
-
/*
|
304 |
-
* Init global variables later used throughout this process
|
305 |
*/
|
306 |
function init_global_vars()
|
307 |
{
|
308 |
-
global $home_url, $home_url_quoted, $plugin_url, $
|
309 |
|
310 |
$home_url = get_option('home');
|
311 |
$local_dir = preg_replace("/.*\//", "", dirname(__FILE__));
|
@@ -314,95 +97,9 @@ function init_global_vars()
|
|
314 |
$home_url_quoted = preg_quote($home_url);
|
315 |
$home_url_quoted = preg_replace("/\//", "\\/", $home_url_quoted);
|
316 |
|
317 |
-
$
|
318 |
-
$enable_auto_translate = get_option(ENABLE_AUTO_TRANSLATE,1) && is_translator();
|
319 |
-
}
|
320 |
-
|
321 |
-
/*
|
322 |
-
* A new translation has been posted, update the translation database.
|
323 |
-
*/
|
324 |
-
function update_translation()
|
325 |
-
{
|
326 |
-
global $wpdb, $table_name;
|
327 |
-
|
328 |
-
$ref=getenv('HTTP_REFERER');
|
329 |
-
$original = base64_url_decode($_POST['token']);
|
330 |
-
$translation = $_POST['translation'];
|
331 |
-
$lang = $_POST['lang'];
|
332 |
-
$source = $_POST['source'];
|
333 |
-
|
334 |
-
if(!isset($original) || !isset($translation) || !isset($lang))
|
335 |
-
{
|
336 |
-
|
337 |
-
return;
|
338 |
-
}
|
339 |
-
|
340 |
-
//Check that use is allowed to translate
|
341 |
-
if(!is_translator())
|
342 |
{
|
343 |
-
|
344 |
-
}
|
345 |
-
|
346 |
-
//Decode & remove already escaped character to avoid double escaping
|
347 |
-
$translation = $wpdb->escape(htmlspecialchars(stripslashes(urldecode($translation))));
|
348 |
-
|
349 |
-
//The original content is encoded as base64 before it is sent (i.e. token), after we
|
350 |
-
//decode it should just the same after it was parsed.
|
351 |
-
$original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
|
352 |
-
|
353 |
-
$update = "REPLACE INTO $table_name (original, translated, lang, source)
|
354 |
-
VALUES ('" . $original . "','" . $translation . "','" . $lang . "','" . $source . "')";
|
355 |
-
|
356 |
-
$result = $wpdb->query($update);
|
357 |
-
|
358 |
-
if($result !== FALSE)
|
359 |
-
{
|
360 |
-
update_transaction_log($original, $translation, $lang, $source);
|
361 |
-
|
362 |
-
//Delete entry from cache
|
363 |
-
if(ENABLE_APC && function_exists('apc_store'))
|
364 |
-
{
|
365 |
-
apc_delete($original .'___'. $lang);
|
366 |
-
}
|
367 |
-
|
368 |
-
|
369 |
-
}
|
370 |
-
else
|
371 |
-
{
|
372 |
-
|
373 |
-
header("HTTP/1.0 404 Failed to update language database");
|
374 |
-
}
|
375 |
-
|
376 |
-
exit;
|
377 |
-
}
|
378 |
-
|
379 |
-
/*
|
380 |
-
* Update the transaction log
|
381 |
-
*/
|
382 |
-
function update_transaction_log(&$original, &$translation, &$lang, $source)
|
383 |
-
{
|
384 |
-
global $wpdb, $user_ID;
|
385 |
-
get_currentuserinfo();
|
386 |
-
|
387 |
-
// log either the user ID or his IP
|
388 |
-
if ('' == $user_ID)
|
389 |
-
{
|
390 |
-
$loguser = $_SERVER['REMOTE_ADDR'];
|
391 |
-
}
|
392 |
-
else
|
393 |
-
{
|
394 |
-
$loguser = $user_ID;
|
395 |
-
}
|
396 |
-
|
397 |
-
$log = "INSERT INTO ".$wpdb->prefix.TRANSLATIONS_LOG." (original, translated, lang, translated_by, source) ".
|
398 |
-
"VALUES ('" . $original . "','" . $translation . "','" . $lang . "','".$loguser."','".$source."')";
|
399 |
-
|
400 |
-
$result = $wpdb->query($log);
|
401 |
-
|
402 |
-
if($result === FALSE)
|
403 |
-
{
|
404 |
-
|
405 |
-
|
406 |
}
|
407 |
}
|
408 |
|
@@ -512,48 +209,6 @@ function parameter_queryvars($qvars)
|
|
512 |
return $qvars;
|
513 |
}
|
514 |
|
515 |
-
/*
|
516 |
-
* Setup the translation database.
|
517 |
-
*/
|
518 |
-
function setup_db()
|
519 |
-
{
|
520 |
-
|
521 |
-
global $wpdb;
|
522 |
-
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
523 |
-
|
524 |
-
$installed_ver = get_option(TRANSPOSH_DB_VERSION);
|
525 |
-
|
526 |
-
if( $installed_ver != DB_VERSION ) {
|
527 |
-
$table_name = $wpdb->prefix . TRANSLATIONS_TABLE;
|
528 |
-
|
529 |
-
|
530 |
-
$sql = "CREATE TABLE $table_name (original VARCHAR(256) NOT NULL,".
|
531 |
-
"lang CHAR(5) NOT NULL,".
|
532 |
-
"translated VARCHAR(256),".
|
533 |
-
"source TINYINT NOT NULL,".
|
534 |
-
"PRIMARY KEY (original, lang)) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
|
535 |
-
|
536 |
-
dbDelta($sql);
|
537 |
-
|
538 |
-
|
539 |
-
$table_name = $wpdb->prefix . TRANSLATIONS_LOG;
|
540 |
-
|
541 |
-
|
542 |
-
$sql = "CREATE TABLE $table_name (original VARCHAR(256) NOT NULL,".
|
543 |
-
"lang CHAR(5) NOT NULL,".
|
544 |
-
"translated VARCHAR(256),".
|
545 |
-
"translated_by VARCHAR(15),".
|
546 |
-
"source TINYINT NOT NULL,".
|
547 |
-
"timestamp TIMESTAMP,".
|
548 |
-
"PRIMARY KEY (original, lang, timestamp)) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
|
549 |
-
|
550 |
-
dbDelta($sql);
|
551 |
-
update_option(TRANSPOSH_DB_VERSION, DB_VERSION);
|
552 |
-
}
|
553 |
-
|
554 |
-
|
555 |
-
}
|
556 |
-
|
557 |
/*
|
558 |
* Determine if the current user is allowed to translate.
|
559 |
* Return TRUE if allowed to translate otherwise FALSE
|
@@ -680,13 +335,15 @@ function get_plugin_name()
|
|
680 |
* Add custom css, i.e. transposh.css
|
681 |
*/
|
682 |
function add_transposh_css() {
|
683 |
-
global $plugin_url
|
684 |
-
|
|
|
685 |
{
|
|
|
686 |
return;
|
687 |
}
|
688 |
//include the transposh.css
|
689 |
-
wp_enqueue_style("transposh","$plugin_url/transposh.css",array(),'1.0.1');
|
690 |
|
691 |
}
|
692 |
|
@@ -697,17 +354,18 @@ function add_transposh_css() {
|
|
697 |
function add_transposh_js() {
|
698 |
global $plugin_url, $wp_query, $lang, $home_url, $enable_auto_translate;
|
699 |
|
700 |
-
|
|
|
701 |
{
|
|
|
702 |
return;
|
703 |
}
|
704 |
-
|
705 |
$is_edit_param_enabled = $wp_query->query_vars[EDIT_PARAM];
|
706 |
-
|
707 |
-
if (!$is_edit_param_enabled &&
|
708 |
{
|
709 |
-
//
|
710 |
-
//js code when it is not needed
|
711 |
return;
|
712 |
}
|
713 |
|
@@ -732,6 +390,97 @@ function add_transposh_js() {
|
|
732 |
}
|
733 |
}
|
734 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
735 |
//Register callbacks
|
736 |
add_filter('query_vars', 'parameter_queryvars' );
|
737 |
add_action('wp_print_styles', 'add_transposh_css');
|
4 |
Plugin URI: http://transposh.org/#
|
5 |
Description: Translation filter for WordPress, After enabling please set languages at the <a href="options-general.php?page=Transposh">the options page</a> Want to help? visit our development site at <a href="http://trac.transposh.org/">trac.transposh.org</a>.
|
6 |
Author: Team Transposh
|
7 |
+
Version: 0.1.2
|
8 |
Author URI: http://transposh.org/
|
9 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
10 |
*/
|
26 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
27 |
*/
|
28 |
|
29 |
+
require_once("core/parser.php");
|
30 |
+
require_once("transposh_db.php");
|
|
|
31 |
require_once("transposh_widget.php");
|
32 |
require_once("transposh_admin.php");
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
//Error message displayed for the admin in case of failure
|
35 |
$admin_msg;
|
36 |
|
40 |
*/
|
41 |
function process_page(&$buffer) {
|
42 |
|
43 |
+
global $wp_query, $tr_page, $page, $pos, $lang, $plugin_url, $is_edit_mode;
|
44 |
|
45 |
$start_time = microtime(TRUE);
|
46 |
|
62 |
|
63 |
$page = $buffer;
|
64 |
|
65 |
+
if (($wp_query->query_vars[EDIT_PARAM] == "1" || $wp_query->query_vars[EDIT_PARAM] == "true") &&
|
66 |
+
is_editing_permitted())
|
67 |
{
|
68 |
+
$is_edit_mode = TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
}
|
70 |
|
71 |
|
82 |
}
|
83 |
|
84 |
/*
|
85 |
+
* Init global variables later used throughout this process.
|
86 |
+
* Note that at the time that this function is called the wp_query is not initialized,
|
87 |
+
* which means that query parameters are not accessiable.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
*/
|
89 |
function init_global_vars()
|
90 |
{
|
91 |
+
global $home_url, $home_url_quoted, $plugin_url, $enable_permalinks_rewrite, $wp_rewrite;
|
92 |
|
93 |
$home_url = get_option('home');
|
94 |
$local_dir = preg_replace("/.*\//", "", dirname(__FILE__));
|
97 |
$home_url_quoted = preg_quote($home_url);
|
98 |
$home_url_quoted = preg_replace("/\//", "\\/", $home_url_quoted);
|
99 |
|
100 |
+
if($wp_rewrite->using_permalinks() && get_option(ENABLE_PERMALINKS_REWRITE))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
{
|
102 |
+
$enable_permalinks_rewrite = TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
}
|
104 |
}
|
105 |
|
209 |
return $qvars;
|
210 |
}
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
/*
|
213 |
* Determine if the current user is allowed to translate.
|
214 |
* Return TRUE if allowed to translate otherwise FALSE
|
335 |
* Add custom css, i.e. transposh.css
|
336 |
*/
|
337 |
function add_transposh_css() {
|
338 |
+
global $plugin_url;
|
339 |
+
|
340 |
+
if(!is_editing_permitted() && !is_auto_translate_permitted())
|
341 |
{
|
342 |
+
//translation not allowed - no need for the transposh.css
|
343 |
return;
|
344 |
}
|
345 |
//include the transposh.css
|
346 |
+
wp_enqueue_style("transposh","$plugin_url/css/transposh.css",array(),'1.0.1');
|
347 |
|
348 |
}
|
349 |
|
354 |
function add_transposh_js() {
|
355 |
global $plugin_url, $wp_query, $lang, $home_url, $enable_auto_translate;
|
356 |
|
357 |
+
$enable_auto_translate = is_auto_translate_permitted();
|
358 |
+
if(!is_editing_permitted() && !$enable_auto_translate)
|
359 |
{
|
360 |
+
//translation not allowed - no need for any js.
|
361 |
return;
|
362 |
}
|
363 |
+
|
364 |
$is_edit_param_enabled = $wp_query->query_vars[EDIT_PARAM];
|
365 |
+
|
366 |
+
if (!$is_edit_param_enabled && !$enable_auto_translate)
|
367 |
{
|
368 |
+
//Not in any translation mode - no need for any js.
|
|
|
369 |
return;
|
370 |
}
|
371 |
|
390 |
}
|
391 |
}
|
392 |
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Determine if the currently selected language (taken from the query parameters) is in the admin's list
|
396 |
+
* of editable languages and the current user is allowed to translate.
|
397 |
+
*
|
398 |
+
* @return TRUE if translation allowed otherwise FALSE
|
399 |
+
*/
|
400 |
+
function is_editing_permitted()
|
401 |
+
{
|
402 |
+
global $wp_query;
|
403 |
+
|
404 |
+
if(!is_translator())
|
405 |
+
{
|
406 |
+
return FALSE;
|
407 |
+
}
|
408 |
+
|
409 |
+
if (!isset($wp_query->query_vars[LANG_PARAM]))
|
410 |
+
{
|
411 |
+
return FALSE;
|
412 |
+
}
|
413 |
+
|
414 |
+
$lang = $wp_query->query_vars[LANG_PARAM];
|
415 |
+
return is_editable_lang($lang);
|
416 |
+
}
|
417 |
+
|
418 |
+
/**
|
419 |
+
* Determine if the given language in on the list of editable languages
|
420 |
+
* @return TRUE if editable othewise FALSE
|
421 |
+
*/
|
422 |
+
function is_editable_lang($lang)
|
423 |
+
{
|
424 |
+
$editable_langs = get_option(EDITABLE_LANGS);
|
425 |
+
|
426 |
+
if(strpos($editable_langs, $lang) === FALSE)
|
427 |
+
{
|
428 |
+
//not an editable language
|
429 |
+
return FALSE;
|
430 |
+
}
|
431 |
+
|
432 |
+
return TRUE;
|
433 |
+
}
|
434 |
+
|
435 |
+
|
436 |
+
/**
|
437 |
+
* Determine if the currently selected language (taken from the query parameters) is in the admin's list
|
438 |
+
* of editable languages and that automatic translation has been enabled.
|
439 |
+
* Note that any user can auto translate. i.e. ignore permissions.
|
440 |
+
*
|
441 |
+
* @return TRUE if automatic translation allowed otherwise FALSE
|
442 |
+
*/
|
443 |
+
function is_auto_translate_permitted()
|
444 |
+
{
|
445 |
+
global $wp_query;
|
446 |
+
|
447 |
+
if(!get_option(ENABLE_AUTO_TRANSLATE, 1))
|
448 |
+
{
|
449 |
+
return FALSE;
|
450 |
+
}
|
451 |
+
|
452 |
+
if (!isset($wp_query->query_vars[LANG_PARAM]))
|
453 |
+
{
|
454 |
+
return FALSE;
|
455 |
+
}
|
456 |
+
|
457 |
+
$lang = $wp_query->query_vars[LANG_PARAM];
|
458 |
+
return is_editable_lang($lang);
|
459 |
+
}
|
460 |
+
/**
|
461 |
+
* Callback from parser allowing to overide the global setting of url rewriting using permalinks.
|
462 |
+
* Some urls should be modified only by adding parameters and should be identified by this
|
463 |
+
* function.
|
464 |
+
* @param $href
|
465 |
+
* @return TRUE if parameters should be used instead of rewriting as a permalink
|
466 |
+
*/
|
467 |
+
function is_url_excluded_from_permalink_rewrite($href)
|
468 |
+
{
|
469 |
+
$use_params = FALSE;
|
470 |
+
|
471 |
+
//don't fix links pointing to real files as it will cause that the
|
472 |
+
//web server will not be able to locate them
|
473 |
+
if(stripos($href, '/wp-admin') !== FALSE ||
|
474 |
+
stripos($href, '/wp-content') !== FALSE ||
|
475 |
+
stripos($href, '/wp-login') !== FALSE ||
|
476 |
+
stripos($href, '/.php') !== FALSE)
|
477 |
+
{
|
478 |
+
$use_params = TRUE;
|
479 |
+
}
|
480 |
+
|
481 |
+
return $use_params;
|
482 |
+
}
|
483 |
+
|
484 |
//Register callbacks
|
485 |
add_filter('query_vars', 'parameter_queryvars' );
|
486 |
add_action('wp_print_styles', 'add_transposh_css');
|
transposh_admin.php
CHANGED
@@ -19,26 +19,21 @@
|
|
19 |
/*
|
20 |
* Provide the admin page for configuring the translation options. eg. what languages ?
|
21 |
* who is allowed to translate ?
|
22 |
-
*
|
23 |
*/
|
24 |
|
25 |
|
26 |
-
require_once("constants.php");
|
27 |
-
|
28 |
|
29 |
/*
|
30 |
* Add transposh to the admin menu.
|
31 |
-
*
|
32 |
*/
|
33 |
function transposh_admin_menu()
|
34 |
{
|
35 |
add_options_page('Transposh','Transposh', 6,'Transposh', 'transposh_admin_page');
|
36 |
}
|
37 |
|
38 |
-
|
39 |
/*
|
40 |
* Create the admin page.
|
41 |
-
*
|
42 |
*/
|
43 |
function transposh_admin_page()
|
44 |
{
|
@@ -72,36 +67,30 @@ function transposh_admin_page()
|
|
72 |
|
73 |
/*
|
74 |
* Insert supported languages section in admin page
|
75 |
-
*
|
76 |
*/
|
77 |
function insert_supported_langs()
|
78 |
{
|
79 |
global $languages, $plugin_url;
|
80 |
|
81 |
-
echo '
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
</script>
|
94 |
-
|
95 |
-
<table>
|
96 |
-
<tr>';
|
97 |
-
|
98 |
|
99 |
$columns = 2;
|
100 |
|
101 |
for($hdr=0; $hdr < $columns; $hdr++)
|
102 |
{
|
103 |
-
echo '<th>Language</th><th>Viewable</th><th>Translatable</th>
|
104 |
-
|
105 |
}
|
106 |
|
107 |
echo '</tr>';
|
@@ -111,21 +100,21 @@ function insert_supported_langs()
|
|
111 |
list ($language,$flag) = explode (",",$lang);
|
112 |
if($i % $columns == 0)
|
113 |
{
|
114 |
-
echo '
|
115 |
}
|
116 |
echo "\n";
|
117 |
|
118 |
$i++;
|
119 |
|
120 |
-
echo "<td><img src=\"$plugin_url/flags/$flag.png\"/> $language</td>";
|
121 |
echo '<td align="center"> <input type="checkbox" id="' . $code .'_view" name="' .
|
122 |
-
$code . '_view"
|
123 |
echo "\n";
|
124 |
echo '<td align="center"> <input type="checkbox" id="' . $code . '_edit" name="' .
|
125 |
$code . '_edit" ' . is_editable($code). '/></td>';
|
126 |
echo "\n";
|
127 |
-
echo "<td align=\"center\"><input type=\"radio\" name=\"default_lang\" value=\"$code\"" .
|
128 |
-
is_default_lang($code). "
|
129 |
|
130 |
if($i % $columns == 0)
|
131 |
{
|
@@ -133,7 +122,7 @@ function insert_supported_langs()
|
|
133 |
}
|
134 |
else
|
135 |
{
|
136 |
-
echo "<td
|
137 |
}
|
138 |
echo "\n";
|
139 |
}
|
@@ -150,9 +139,9 @@ function is_editable($code)
|
|
150 |
{
|
151 |
$langs = get_option(EDITABLE_LANGS);
|
152 |
|
153 |
-
if(
|
154 |
{
|
155 |
-
return "checked";
|
156 |
}
|
157 |
|
158 |
return "";
|
@@ -165,9 +154,9 @@ function is_editable($code)
|
|
165 |
function is_viewable($code)
|
166 |
{
|
167 |
$langs = get_option(VIEWABLE_LANGS);
|
168 |
-
if(
|
169 |
{
|
170 |
-
return "checked";
|
171 |
}
|
172 |
|
173 |
return "";
|
@@ -190,7 +179,7 @@ function is_default_lang($code)
|
|
190 |
|
191 |
if($default == $code)
|
192 |
{
|
193 |
-
return "checked";
|
194 |
}
|
195 |
|
196 |
return "";
|
@@ -198,7 +187,6 @@ function is_default_lang($code)
|
|
198 |
|
199 |
/*
|
200 |
* Insert permissiions section in the admin page
|
201 |
-
*
|
202 |
*/
|
203 |
function insert_permissions()
|
204 |
{
|
@@ -208,12 +196,12 @@ function insert_permissions()
|
|
208 |
foreach($wp_roles->get_names() as $role_name => $something)
|
209 |
{
|
210 |
echo '<input type="checkbox" value="1" name="' . $role_name . '" ' . can_translate($role_name) .
|
211 |
-
'
|
212 |
}
|
213 |
|
214 |
//Add our own custom role
|
215 |
-
echo '<input type="checkbox" value="1" name="anonymous"'
|
216 |
-
can_translate('anonymous') . '
|
217 |
}
|
218 |
|
219 |
/*
|
@@ -226,32 +214,29 @@ function insert_permalink_rewrite_option()
|
|
226 |
$checked = "";
|
227 |
if(get_option(ENABLE_PERMALINKS_REWRITE))
|
228 |
{
|
229 |
-
$checked = 'checked';
|
230 |
}
|
231 |
|
232 |
-
echo '<input type="checkbox" value="1" name="enable_permalinks"'. $checked . '
|
233 |
'Rewrite URLs to be search engine friendly, '.
|
234 |
'e.g. (http://wordpress.org/<strong> en</strong>). '.
|
235 |
-
'Requires that permalinks will be enabled.'
|
236 |
-
'</input>';
|
237 |
}
|
238 |
|
239 |
/*
|
240 |
* Insert the option to enable/disable automatic translation.
|
241 |
* Enabled by default.
|
242 |
-
*
|
243 |
*/
|
244 |
function insert_auto_translate_option()
|
245 |
{
|
246 |
$checked = "";
|
247 |
if(get_option(ENABLE_AUTO_TRANSLATE,1))
|
248 |
{
|
249 |
-
$checked = 'checked';
|
250 |
}
|
251 |
|
252 |
-
echo '<input type="checkbox" value="1" name="enable_autotranslate"'.$checked.'
|
253 |
-
'Allow automatic translation of pages (currently using Google Translate)
|
254 |
-
'</input>';
|
255 |
}
|
256 |
|
257 |
/*
|
@@ -266,7 +251,7 @@ function can_translate($role_name)
|
|
266 |
$role = $wp_roles->get_role($role_name);
|
267 |
if(isset($role) && $role->has_cap(TRANSLATOR))
|
268 |
{
|
269 |
-
return 'checked';
|
270 |
}
|
271 |
}
|
272 |
else
|
@@ -274,7 +259,7 @@ function can_translate($role_name)
|
|
274 |
$allow_anonymous = get_option(ANONYMOUS_TRANSLATION);
|
275 |
if($allow_anonymous == "1")
|
276 |
{
|
277 |
-
return 'checked';
|
278 |
}
|
279 |
}
|
280 |
|
@@ -283,7 +268,6 @@ function can_translate($role_name)
|
|
283 |
|
284 |
/*
|
285 |
* Handle newly posted admin options.
|
286 |
-
*
|
287 |
*/
|
288 |
function update_admin_options()
|
289 |
{
|
@@ -350,8 +334,8 @@ function update_admin_options()
|
|
350 |
update_option(ENABLE_AUTO_TRANSLATE, $_POST['enable_autotranslate']);
|
351 |
}
|
352 |
|
353 |
-
echo '<div id="message"class="updated fade">';
|
354 |
-
echo
|
355 |
echo '</div>';
|
356 |
}
|
357 |
|
19 |
/*
|
20 |
* Provide the admin page for configuring the translation options. eg. what languages ?
|
21 |
* who is allowed to translate ?
|
|
|
22 |
*/
|
23 |
|
24 |
|
25 |
+
require_once("core/constants.php");
|
|
|
26 |
|
27 |
/*
|
28 |
* Add transposh to the admin menu.
|
|
|
29 |
*/
|
30 |
function transposh_admin_menu()
|
31 |
{
|
32 |
add_options_page('Transposh','Transposh', 6,'Transposh', 'transposh_admin_page');
|
33 |
}
|
34 |
|
|
|
35 |
/*
|
36 |
* Create the admin page.
|
|
|
37 |
*/
|
38 |
function transposh_admin_page()
|
39 |
{
|
67 |
|
68 |
/*
|
69 |
* Insert supported languages section in admin page
|
|
|
70 |
*/
|
71 |
function insert_supported_langs()
|
72 |
{
|
73 |
global $languages, $plugin_url;
|
74 |
|
75 |
+
echo '<script type="text/javascript">'.
|
76 |
+
'function chbx_change(lang)'.
|
77 |
+
'{'.
|
78 |
+
'var view = lang + "_view";'.
|
79 |
+
'if(document.getElementById(view).checked)'.
|
80 |
+
'{'.
|
81 |
+
'var edit = lang + "_edit";'.
|
82 |
+
'document.getElementById(edit).checked = true;'.
|
83 |
+
'}'.
|
84 |
+
'}'.
|
85 |
+
'</script>';
|
86 |
+
echo '<table><tr>';
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
$columns = 2;
|
89 |
|
90 |
for($hdr=0; $hdr < $columns; $hdr++)
|
91 |
{
|
92 |
+
echo '<th>Language</th><th>Viewable</th><th>Translatable</th>'.
|
93 |
+
'<th>Default</th><th style="padding-right: 80px"></th>';
|
94 |
}
|
95 |
|
96 |
echo '</tr>';
|
100 |
list ($language,$flag) = explode (",",$lang);
|
101 |
if($i % $columns == 0)
|
102 |
{
|
103 |
+
echo '<tr>';
|
104 |
}
|
105 |
echo "\n";
|
106 |
|
107 |
$i++;
|
108 |
|
109 |
+
echo "<td><img src=\"$plugin_url/img/flags/$flag.png\" alt=\"\"/> $language</td>";
|
110 |
echo '<td align="center"> <input type="checkbox" id="' . $code .'_view" name="' .
|
111 |
+
$code . '_view" onchange="chbx_change(\'' . $code . '\')" ' . is_viewable($code) . '/></td>';
|
112 |
echo "\n";
|
113 |
echo '<td align="center"> <input type="checkbox" id="' . $code . '_edit" name="' .
|
114 |
$code . '_edit" ' . is_editable($code). '/></td>';
|
115 |
echo "\n";
|
116 |
+
echo "<td align=\"center\"><input type=\"radio\" name=\"default_lang\" value=\"$code\" " .
|
117 |
+
is_default_lang($code). "/></td>";
|
118 |
|
119 |
if($i % $columns == 0)
|
120 |
{
|
122 |
}
|
123 |
else
|
124 |
{
|
125 |
+
echo "<td style=\"padding-right: 60px\"></td>";
|
126 |
}
|
127 |
echo "\n";
|
128 |
}
|
139 |
{
|
140 |
$langs = get_option(EDITABLE_LANGS);
|
141 |
|
142 |
+
if(strpos($langs, $code) !== FALSE)
|
143 |
{
|
144 |
+
return 'checked="checked"';
|
145 |
}
|
146 |
|
147 |
return "";
|
154 |
function is_viewable($code)
|
155 |
{
|
156 |
$langs = get_option(VIEWABLE_LANGS);
|
157 |
+
if(strpos($langs, $code) !== FALSE)
|
158 |
{
|
159 |
+
return 'checked="checked"';
|
160 |
}
|
161 |
|
162 |
return "";
|
179 |
|
180 |
if($default == $code)
|
181 |
{
|
182 |
+
return 'checked="checked"';
|
183 |
}
|
184 |
|
185 |
return "";
|
187 |
|
188 |
/*
|
189 |
* Insert permissiions section in the admin page
|
|
|
190 |
*/
|
191 |
function insert_permissions()
|
192 |
{
|
196 |
foreach($wp_roles->get_names() as $role_name => $something)
|
197 |
{
|
198 |
echo '<input type="checkbox" value="1" name="' . $role_name . '" ' . can_translate($role_name) .
|
199 |
+
'/>' . $role_name . ' ';
|
200 |
}
|
201 |
|
202 |
//Add our own custom role
|
203 |
+
echo '<input type="checkbox" value="1" name="anonymous" '.
|
204 |
+
can_translate('anonymous') . '/> Anonymous';
|
205 |
}
|
206 |
|
207 |
/*
|
214 |
$checked = "";
|
215 |
if(get_option(ENABLE_PERMALINKS_REWRITE))
|
216 |
{
|
217 |
+
$checked = 'checked="checked"';
|
218 |
}
|
219 |
|
220 |
+
echo '<input type="checkbox" value="1" name="enable_permalinks" '. $checked . '/>'.
|
221 |
'Rewrite URLs to be search engine friendly, '.
|
222 |
'e.g. (http://wordpress.org/<strong> en</strong>). '.
|
223 |
+
'Requires that permalinks will be enabled.';
|
|
|
224 |
}
|
225 |
|
226 |
/*
|
227 |
* Insert the option to enable/disable automatic translation.
|
228 |
* Enabled by default.
|
|
|
229 |
*/
|
230 |
function insert_auto_translate_option()
|
231 |
{
|
232 |
$checked = "";
|
233 |
if(get_option(ENABLE_AUTO_TRANSLATE,1))
|
234 |
{
|
235 |
+
$checked = 'checked="checked"';
|
236 |
}
|
237 |
|
238 |
+
echo '<input type="checkbox" value="1" name="enable_autotranslate" '.$checked.'/>'.
|
239 |
+
'Allow automatic translation of pages (currently using Google Translate)';
|
|
|
240 |
}
|
241 |
|
242 |
/*
|
251 |
$role = $wp_roles->get_role($role_name);
|
252 |
if(isset($role) && $role->has_cap(TRANSLATOR))
|
253 |
{
|
254 |
+
return 'checked="checked"';
|
255 |
}
|
256 |
}
|
257 |
else
|
259 |
$allow_anonymous = get_option(ANONYMOUS_TRANSLATION);
|
260 |
if($allow_anonymous == "1")
|
261 |
{
|
262 |
+
return 'checked="checked"';
|
263 |
}
|
264 |
}
|
265 |
|
268 |
|
269 |
/*
|
270 |
* Handle newly posted admin options.
|
|
|
271 |
*/
|
272 |
function update_admin_options()
|
273 |
{
|
334 |
update_option(ENABLE_AUTO_TRANSLATE, $_POST['enable_autotranslate']);
|
335 |
}
|
336 |
|
337 |
+
echo '<div id="message" class="updated fade">';
|
338 |
+
echo '<p>Changes saved</p>';
|
339 |
echo '</div>';
|
340 |
}
|
341 |
|
transposh_db.php
ADDED
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* Copyright © 2009 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 |
+
* Contains db realated function which are likely to be specific for each environment.
|
22 |
+
* This implementation for use with mysql within wordpress
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
|
27 |
+
require_once("core/constants.php");
|
28 |
+
require_once("core/utils.php");
|
29 |
+
|
30 |
+
//
|
31 |
+
//Constants
|
32 |
+
//
|
33 |
+
|
34 |
+
//Table name in database for storing translations
|
35 |
+
define("TRANSLATIONS_TABLE", "translations");
|
36 |
+
define("TRANSLATIONS_LOG", "translations_log");
|
37 |
+
|
38 |
+
//Database version
|
39 |
+
define("DB_VERSION", "1.02");
|
40 |
+
|
41 |
+
//Constant used as key in options database
|
42 |
+
define("TRANSPOSH_DB_VERSION", "transposh_db_version");
|
43 |
+
|
44 |
+
/*
|
45 |
+
* Fetch translation from db or cache.
|
46 |
+
* Returns An array that contains the translated string and it source.
|
47 |
+
* Will return NULL if no translation is available.
|
48 |
+
*/
|
49 |
+
function fetch_translation($original, $lang)
|
50 |
+
{
|
51 |
+
global $wpdb;
|
52 |
+
$translated = NULL;
|
53 |
+
|
54 |
+
|
55 |
+
//The original is saved in db in its escaped form
|
56 |
+
$original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
|
57 |
+
|
58 |
+
if(ENABLE_APC && function_exists('apc_fetch'))
|
59 |
+
{
|
60 |
+
$cached = apc_fetch($original .'___'. $lang, $rc);
|
61 |
+
if($rc === TRUE)
|
62 |
+
{
|
63 |
+
|
64 |
+
return $cached;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
$table_name = $wpdb->prefix . TRANSLATIONS_TABLE;
|
69 |
+
$query = "SELECT * FROM $table_name WHERE original = '$original' and lang = '$lang' ";
|
70 |
+
$row = $wpdb->get_row($query);
|
71 |
+
|
72 |
+
if($row !== FALSE)
|
73 |
+
{
|
74 |
+
$translated_text = stripslashes($row->translated);
|
75 |
+
$translated = array($translated_text, $row->source);
|
76 |
+
|
77 |
+
|
78 |
+
}
|
79 |
+
|
80 |
+
if(ENABLE_APC && function_exists('apc_store'))
|
81 |
+
{
|
82 |
+
//If we don't have translation still we want to have it in cache
|
83 |
+
$cache_entry = $translated;
|
84 |
+
if($cache_entry == NULL)
|
85 |
+
{
|
86 |
+
$cache_entry = "";
|
87 |
+
}
|
88 |
+
|
89 |
+
//update cache
|
90 |
+
$rc = apc_store($original .'___'. $lang, $cache_entry, 3600);
|
91 |
+
if($rc === TRUE)
|
92 |
+
{
|
93 |
+
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
|
98 |
+
return $translated;
|
99 |
+
}
|
100 |
+
|
101 |
+
/*
|
102 |
+
* A new translation has been posted, update the translation database.
|
103 |
+
*/
|
104 |
+
function update_translation()
|
105 |
+
{
|
106 |
+
global $wpdb;
|
107 |
+
|
108 |
+
$ref=getenv('HTTP_REFERER');
|
109 |
+
$original = base64_url_decode($_POST['token']);
|
110 |
+
$translation = $_POST['translation'];
|
111 |
+
$lang = $_POST['lang'];
|
112 |
+
$source = $_POST['source'];
|
113 |
+
|
114 |
+
// check params
|
115 |
+
|
116 |
+
if(!isset($original) || !isset($translation) || !isset($lang))
|
117 |
+
{
|
118 |
+
|
119 |
+
return;
|
120 |
+
}
|
121 |
+
|
122 |
+
//Check permissions, first the lanugage must be on the edit list. Then either the user
|
123 |
+
//is a translator or automatic translation if it is enabled.
|
124 |
+
if(!(is_editable_lang($lang) &&
|
125 |
+
(is_translator() || ($source == 1 && get_option(ENABLE_AUTO_TRANSLATE, 1)))))
|
126 |
+
{
|
127 |
+
|
128 |
+
header("HTTP/1.0 401 Unauthorized translation");
|
129 |
+
exit;
|
130 |
+
}
|
131 |
+
|
132 |
+
$table_name = $wpdb->prefix . TRANSLATIONS_TABLE;
|
133 |
+
|
134 |
+
//Decode & remove already escaped character to avoid double escaping
|
135 |
+
$translation = $wpdb->escape(htmlspecialchars(stripslashes(urldecode($translation))));
|
136 |
+
|
137 |
+
//The original content is encoded as base64 before it is sent (i.e. token), after we
|
138 |
+
//decode it should just the same after it was parsed.
|
139 |
+
$original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
|
140 |
+
|
141 |
+
//add our own custom header - so we will know that we got here
|
142 |
+
header("Transposh: ver-0.1.2 db_version-". DB_VERSION);
|
143 |
+
|
144 |
+
list($translated_text, $old_source) = fetch_translation($original, $lang);
|
145 |
+
if ($translated_text) {
|
146 |
+
if ($source == 1) {
|
147 |
+
|
148 |
+
return;
|
149 |
+
}
|
150 |
+
if ($translation == $wpdb->escape(htmlspecialchars(stripslashes(urldecode($translated_text)))) && $old_source == $source) {
|
151 |
+
|
152 |
+
return;
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
$update = "REPLACE INTO $table_name (original, translated, lang, source)
|
157 |
+
VALUES ('" . $original . "','" . $translation . "','" . $lang . "','" . $source . "')";
|
158 |
+
|
159 |
+
$result = $wpdb->query($update);
|
160 |
+
|
161 |
+
if($result !== FALSE)
|
162 |
+
{
|
163 |
+
update_transaction_log($original, $translation, $lang, $source);
|
164 |
+
|
165 |
+
//Delete entry from cache
|
166 |
+
if(ENABLE_APC && function_exists('apc_store'))
|
167 |
+
{
|
168 |
+
apc_delete($original .'___'. $lang);
|
169 |
+
}
|
170 |
+
|
171 |
+
|
172 |
+
}
|
173 |
+
else
|
174 |
+
{
|
175 |
+
|
176 |
+
header("HTTP/1.0 404 Failed to update language database");
|
177 |
+
}
|
178 |
+
|
179 |
+
exit;
|
180 |
+
}
|
181 |
+
|
182 |
+
/*
|
183 |
+
* Update the transaction log
|
184 |
+
*/
|
185 |
+
function update_transaction_log(&$original, &$translation, &$lang, $source)
|
186 |
+
{
|
187 |
+
global $wpdb, $user_ID;
|
188 |
+
get_currentuserinfo();
|
189 |
+
|
190 |
+
// log either the user ID or his IP
|
191 |
+
if ('' == $user_ID)
|
192 |
+
{
|
193 |
+
$loguser = $_SERVER['REMOTE_ADDR'];
|
194 |
+
}
|
195 |
+
else
|
196 |
+
{
|
197 |
+
$loguser = $user_ID;
|
198 |
+
}
|
199 |
+
|
200 |
+
$log = "INSERT INTO ".$wpdb->prefix.TRANSLATIONS_LOG." (original, translated, lang, translated_by, source) ".
|
201 |
+
"VALUES ('" . $original . "','" . $translation . "','" . $lang . "','".$loguser."','".$source."')";
|
202 |
+
|
203 |
+
$result = $wpdb->query($log);
|
204 |
+
|
205 |
+
if($result === FALSE)
|
206 |
+
{
|
207 |
+
|
208 |
+
|
209 |
+
}
|
210 |
+
}
|
211 |
+
|
212 |
+
|
213 |
+
/*
|
214 |
+
* Setup the translation database.
|
215 |
+
*/
|
216 |
+
function setup_db()
|
217 |
+
{
|
218 |
+
|
219 |
+
global $wpdb;
|
220 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
221 |
+
|
222 |
+
$installed_ver = get_option(TRANSPOSH_DB_VERSION);
|
223 |
+
|
224 |
+
if( $installed_ver != DB_VERSION ) {
|
225 |
+
$table_name = $wpdb->prefix . TRANSLATIONS_TABLE;
|
226 |
+
|
227 |
+
|
228 |
+
$sql = "CREATE TABLE $table_name (original VARCHAR(256) NOT NULL,".
|
229 |
+
"lang CHAR(5) NOT NULL,".
|
230 |
+
"translated VARCHAR(256),".
|
231 |
+
"source TINYINT NOT NULL,".
|
232 |
+
"PRIMARY KEY (original, lang)) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
|
233 |
+
|
234 |
+
dbDelta($sql);
|
235 |
+
|
236 |
+
|
237 |
+
$table_name = $wpdb->prefix . TRANSLATIONS_LOG;
|
238 |
+
|
239 |
+
|
240 |
+
$sql = "CREATE TABLE $table_name (original VARCHAR(256) NOT NULL,".
|
241 |
+
"lang CHAR(5) NOT NULL,".
|
242 |
+
"translated VARCHAR(256),".
|
243 |
+
"translated_by VARCHAR(15),".
|
244 |
+
"source TINYINT NOT NULL,".
|
245 |
+
"timestamp TIMESTAMP,".
|
246 |
+
"PRIMARY KEY (original, lang, timestamp)) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
|
247 |
+
|
248 |
+
dbDelta($sql);
|
249 |
+
update_option(TRANSPOSH_DB_VERSION, DB_VERSION);
|
250 |
+
}
|
251 |
+
|
252 |
+
|
253 |
+
}
|
254 |
+
|
255 |
+
?>
|
transposh_widget.php
CHANGED
@@ -21,7 +21,7 @@
|
|
21 |
* mode.
|
22 |
*/
|
23 |
|
24 |
-
require_once("constants.php");
|
25 |
require_once("transposh.php");
|
26 |
|
27 |
/*
|
@@ -34,8 +34,6 @@ function init_transposh()
|
|
34 |
{
|
35 |
|
36 |
|
37 |
-
global $wp_rewrite;
|
38 |
-
|
39 |
$ref=getenv('HTTP_REFERER');
|
40 |
$lang = $_POST[LANG_PARAM];
|
41 |
|
@@ -44,10 +42,12 @@ function init_transposh()
|
|
44 |
|
45 |
if($lang != "none")
|
46 |
{
|
47 |
-
$use_params_only = !$wp_rewrite->using_permalinks();
|
48 |
$is_edit = $_POST[EDIT_PARAM];
|
|
|
49 |
|
50 |
-
|
|
|
|
|
51 |
}
|
52 |
|
53 |
|
@@ -73,8 +73,21 @@ function transposh_widget_init()
|
|
73 |
|
74 |
// Register widget control
|
75 |
register_widget_control("Transposh",'transposh_widget_control');
|
|
|
|
|
|
|
76 |
}
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
/*
|
80 |
* The actual widget implementation.
|
@@ -82,7 +95,7 @@ function transposh_widget_init()
|
|
82 |
function transposh_widget($args)
|
83 |
{
|
84 |
|
85 |
-
global $languages, $wp_query, $
|
86 |
extract($args);
|
87 |
|
88 |
$page_url = ($_SERVER['HTTPS'] == 'on' ?
|
@@ -100,17 +113,14 @@ function transposh_widget($args)
|
|
100 |
|
101 |
$is_showing_languages = FALSE;
|
102 |
|
103 |
-
//echo $before_widget . $before_title . __(no_translate("Transposh")) . $after_title;
|
104 |
echo $before_widget . $before_title . __("Translation") . $after_title;
|
105 |
|
106 |
switch ($options['style']) {
|
107 |
case 1: // flags
|
108 |
//keep the flags in the same direction regardless of the overall page direction
|
109 |
-
echo "<div
|
110 |
-
|
111 |
-
$using_permalinks = $wp_rewrite->using_permalinks();
|
112 |
|
113 |
-
|
114 |
{
|
115 |
list($language,$flag) = explode (",",$lang2);
|
116 |
|
@@ -118,14 +128,17 @@ function transposh_widget($args)
|
|
118 |
$page_url = cleanup_url($page_url);
|
119 |
|
120 |
//Only show languages which are viewable or (editable and the user is a translator)
|
121 |
-
if(
|
122 |
-
($is_translator &&
|
|
|
123 |
{
|
124 |
-
|
125 |
-
|
|
|
|
|
126 |
|
127 |
echo "<a href=\"" . $page_url2 . "\">".
|
128 |
-
"<img src=\"$plugin_url/flags/$flag.png\" title=\"$language\" alt=\"$language\"".
|
129 |
" style=\"padding: 1px 3px\"/></a>";
|
130 |
$is_showing_languages = TRUE;
|
131 |
}
|
@@ -148,8 +161,9 @@ function transposh_widget($args)
|
|
148 |
list($language,$flag) = explode (",",$lang2);
|
149 |
|
150 |
//Only show languages which are viewable or (editable and the user is a translator)
|
151 |
-
if(
|
152 |
-
($is_translator &&
|
|
|
153 |
{
|
154 |
$is_selected = ($lang == $code ? "selected=\"selected\"" : "" );
|
155 |
echo "<option value=\"$code\" $is_selected>" . $language . "</option>";
|
@@ -165,11 +179,11 @@ function transposh_widget($args)
|
|
165 |
if($is_showing_languages)
|
166 |
{
|
167 |
//Add the edit checkbox only for translators on languages marked as editable
|
168 |
-
if($is_translator &&
|
169 |
{
|
170 |
-
echo "<input type=\"checkbox\" name=\"" . EDIT_PARAM . "\" value=\"1\"" .
|
171 |
-
($is_edit ? "checked=\"
|
172 |
-
"
|
173 |
}
|
174 |
|
175 |
echo "<input type=\"hidden\" name=\"transposh_widget_posted\" value=\"1\"/>";
|
@@ -182,7 +196,7 @@ function transposh_widget($args)
|
|
182 |
|
183 |
echo "</form>";
|
184 |
//echo "<button onClick=\"do_auto_translate();\">translate all</button>";
|
185 |
-
echo "<div id=\"credit\">by <a href=\"http://transposh.org\"><img src=\"$plugin_url/tplogo.png\" title=\"Transposh\" alt=\"Transposh\"/></a></div>";
|
186 |
echo $after_widget;
|
187 |
}
|
188 |
|
@@ -207,6 +221,10 @@ function cleanup_url($url)
|
|
207 |
//cleanup lang identifier in permalinks
|
208 |
$url = preg_replace("/$home_url_quoted\/(..\/)/", "$home_url/", $url);
|
209 |
|
|
|
|
|
|
|
|
|
210 |
return $url;
|
211 |
}
|
212 |
|
21 |
* mode.
|
22 |
*/
|
23 |
|
24 |
+
require_once("core/constants.php");
|
25 |
require_once("transposh.php");
|
26 |
|
27 |
/*
|
34 |
{
|
35 |
|
36 |
|
|
|
|
|
37 |
$ref=getenv('HTTP_REFERER');
|
38 |
$lang = $_POST[LANG_PARAM];
|
39 |
|
42 |
|
43 |
if($lang != "none")
|
44 |
{
|
|
|
45 |
$is_edit = $_POST[EDIT_PARAM];
|
46 |
+
$ref = rewrite_url_lang_param($ref, $lang, $is_edit);
|
47 |
|
48 |
+
//ref is generated with html entities encoded, needs to be
|
49 |
+
//decoded when used in the http header (i.e. 302 redirect)
|
50 |
+
$ref = html_entity_decode($ref, ENT_NOQUOTES);
|
51 |
}
|
52 |
|
53 |
|
73 |
|
74 |
// Register widget control
|
75 |
register_widget_control("Transposh",'transposh_widget_control');
|
76 |
+
|
77 |
+
//regigster callback for widget's css
|
78 |
+
add_action('wp_print_styles', 'add_transposh_widget_css');
|
79 |
}
|
80 |
|
81 |
+
/*
|
82 |
+
* Add custom css, i.e. transposh.css
|
83 |
+
*/
|
84 |
+
function add_transposh_widget_css() {
|
85 |
+
global $plugin_url;
|
86 |
+
|
87 |
+
//include the transposh_widget.css
|
88 |
+
wp_enqueue_style("transposh_widget","$plugin_url/css/transposh_widget.css",array(),'1.0.1');
|
89 |
+
|
90 |
+
}
|
91 |
|
92 |
/*
|
93 |
* The actual widget implementation.
|
95 |
function transposh_widget($args)
|
96 |
{
|
97 |
|
98 |
+
global $languages, $wp_query, $plugin_url,$lang;
|
99 |
extract($args);
|
100 |
|
101 |
$page_url = ($_SERVER['HTTPS'] == 'on' ?
|
113 |
|
114 |
$is_showing_languages = FALSE;
|
115 |
|
|
|
116 |
echo $before_widget . $before_title . __("Translation") . $after_title;
|
117 |
|
118 |
switch ($options['style']) {
|
119 |
case 1: // flags
|
120 |
//keep the flags in the same direction regardless of the overall page direction
|
121 |
+
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
|
|
|
|
122 |
|
123 |
+
foreach($languages as $code => $lang2)
|
124 |
{
|
125 |
list($language,$flag) = explode (",",$lang2);
|
126 |
|
128 |
$page_url = cleanup_url($page_url);
|
129 |
|
130 |
//Only show languages which are viewable or (editable and the user is a translator)
|
131 |
+
if(strpos($viewable_langs, $code) !== FALSE ||
|
132 |
+
($is_translator && strpos($editable_langs, $code) !== FALSE) ||
|
133 |
+
(get_option(DEFAULT_LANG) == $code && $lang))
|
134 |
{
|
135 |
+
$page_url2 = rewrite_url_lang_param($page_url, $code, $is_edit);
|
136 |
+
if (get_option(DEFAULT_LANG) == $code) {
|
137 |
+
$page_url2 = $page_url;
|
138 |
+
}
|
139 |
|
140 |
echo "<a href=\"" . $page_url2 . "\">".
|
141 |
+
"<img src=\"$plugin_url/img/flags/$flag.png\" title=\"$language\" alt=\"$language\"".
|
142 |
" style=\"padding: 1px 3px\"/></a>";
|
143 |
$is_showing_languages = TRUE;
|
144 |
}
|
161 |
list($language,$flag) = explode (",",$lang2);
|
162 |
|
163 |
//Only show languages which are viewable or (editable and the user is a translator)
|
164 |
+
if(strpos($viewable_langs, $code) !== FALSE ||
|
165 |
+
($is_translator && strpos($editable_langs, $code) !== FALSE) ||
|
166 |
+
(get_option(DEFAULT_LANG) == $code && $lang))
|
167 |
{
|
168 |
$is_selected = ($lang == $code ? "selected=\"selected\"" : "" );
|
169 |
echo "<option value=\"$code\" $is_selected>" . $language . "</option>";
|
179 |
if($is_showing_languages)
|
180 |
{
|
181 |
//Add the edit checkbox only for translators on languages marked as editable
|
182 |
+
if($is_translator && strpos($editable_langs, $lang) !== FALSE)
|
183 |
{
|
184 |
+
echo "<input type=\"checkbox\" name=\"" . EDIT_PARAM . "\" value=\"1\" " .
|
185 |
+
($is_edit ? "checked=\"checked\"" : "") .
|
186 |
+
" onclick=\"this.form.submit();\"/> Edit Translation";
|
187 |
}
|
188 |
|
189 |
echo "<input type=\"hidden\" name=\"transposh_widget_posted\" value=\"1\"/>";
|
196 |
|
197 |
echo "</form>";
|
198 |
//echo "<button onClick=\"do_auto_translate();\">translate all</button>";
|
199 |
+
echo "<div id=\"credit\">by <a href=\"http://transposh.org\"><img src=\"$plugin_url/img/tplogo.png\" title=\"Transposh\" alt=\"Transposh\"/></a></div>";
|
200 |
echo $after_widget;
|
201 |
}
|
202 |
|
221 |
//cleanup lang identifier in permalinks
|
222 |
$url = preg_replace("/$home_url_quoted\/(..\/)/", "$home_url/", $url);
|
223 |
|
224 |
+
//some more cleans
|
225 |
+
$url = preg_replace("/&$/", "", $url);
|
226 |
+
$url = preg_replace("/\?$/", "", $url);
|
227 |
+
|
228 |
return $url;
|
229 |
}
|
230 |
|