Version Description
Download this release
Release Info
Developer | oferwald |
Plugin | Transposh WordPress Translation |
Version | 0.3.7 |
Comparing to | |
See all releases |
Code changes from version 0.3.6 to 0.3.7
- core/constants.php +1 -1
- core/jsonwrapper/jsonwrapper_inner.php +15 -15
- core/parser.php +29 -11
- core/utils.php +2 -1
- readme.txt +9 -2
- transposh.php +1 -1
- transposh_options.php +12 -1
- transposh_widget.php +58 -38
core/constants.php
CHANGED
@@ -91,7 +91,7 @@ $rtl_languages = array("ar", "he", "fa", "yi");
|
|
91 |
//Define the new capability that will be assigned to roles - translator
|
92 |
define("TRANSLATOR", 'translator');
|
93 |
|
94 |
-
define("TRANSPOSH_PLUGIN_VER",'0.3.
|
95 |
|
96 |
//Define segment id prefix, will be included in span tag. also used as class identifier
|
97 |
define("SPAN_PREFIX", "tr_");
|
91 |
//Define the new capability that will be assigned to roles - translator
|
92 |
define("TRANSLATOR", 'translator');
|
93 |
|
94 |
+
define("TRANSPOSH_PLUGIN_VER",'0.3.7');
|
95 |
|
96 |
//Define segment id prefix, will be included in span tag. also used as class identifier
|
97 |
define("SPAN_PREFIX", "tr_");
|
core/jsonwrapper/jsonwrapper_inner.php
CHANGED
@@ -1,23 +1,23 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
|
|
|
|
4 |
|
5 |
-
function json_encode($arg)
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
return $services_json->encode($arg);
|
12 |
}
|
13 |
|
14 |
-
function json_decode($arg)
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
return $services_json->decode($arg);
|
21 |
}
|
22 |
|
23 |
?>
|
1 |
<?php
|
2 |
|
3 |
+
if (!class_exists(Services_JSON)) {
|
4 |
+
require_once 'JSON.php';
|
5 |
+
}
|
6 |
|
7 |
+
function json_encode($arg) {
|
8 |
+
global $services_json;
|
9 |
+
if (!isset($services_json)) {
|
10 |
+
$services_json = new Services_JSON();
|
11 |
+
}
|
12 |
+
return $services_json->encode($arg);
|
|
|
13 |
}
|
14 |
|
15 |
+
function json_decode($arg) {
|
16 |
+
global $services_json;
|
17 |
+
if (!isset($services_json)) {
|
18 |
+
$services_json = new Services_JSON();
|
19 |
+
}
|
20 |
+
return $services_json->decode($arg);
|
|
|
21 |
}
|
22 |
|
23 |
?>
|
core/parser.php
CHANGED
@@ -184,7 +184,7 @@ class parser {
|
|
184 |
if (($char == '.' || $char == '-') && ($this->is_white_space($nextchar))) return 1;
|
185 |
if (ord($char) == 226 && ord($nextchar) == 136 && ord($nextnextchar) == 153) return 3; //∙
|
186 |
if (ord($char) == 194 && ord($nextchar) == 183) return 2; //·
|
187 |
-
return (strpos(',?()[]"!:|;',$char) !== false) ? 1 : 0;
|
188 |
}
|
189 |
|
190 |
/**
|
@@ -223,6 +223,14 @@ class parser {
|
|
223 |
function parsetext($string) {
|
224 |
$pos = 0;
|
225 |
// $pos = skip_white_space($string, $pos);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
$start = $pos;
|
227 |
|
228 |
while($pos < strlen($string)) {
|
@@ -237,15 +245,19 @@ class parser {
|
|
237 |
//skip past entity
|
238 |
$pos += $len_of_entity;
|
239 |
}
|
|
|
|
|
|
|
|
|
240 |
// will break translation unit when there's a breaker ",.[]()..."
|
241 |
elseif($senb_len = $this->is_sentence_breaker($string[$pos],$string[$pos+1],$string[$pos+2])) {
|
242 |
$this->tag_phrase($string,$start,$pos);
|
243 |
$pos += $senb_len;
|
244 |
$start = $pos;
|
245 |
}
|
246 |
-
// Numbers also break, if they are followed by whitespace (don't break 42nd)
|
247 |
elseif($num_len = $this->is_number($string,$pos)) {
|
248 |
-
if ($this->is_white_space($string[$pos+$num_len])) {
|
249 |
$this->tag_phrase($string,$start,$pos);
|
250 |
$start = $pos + $num_len + 1;
|
251 |
}
|
@@ -258,7 +270,7 @@ class parser {
|
|
258 |
|
259 |
// the end is also some breaker
|
260 |
if($pos > $start) {
|
261 |
-
|
262 |
}
|
263 |
}
|
264 |
|
@@ -374,14 +386,25 @@ class parser {
|
|
374 |
return $this->html;
|
375 |
}
|
376 |
|
377 |
-
// fix
|
378 |
if ($this->feed_fix) {
|
|
|
379 |
|
380 |
-
foreach (array('link','wfw:commentrss','comments'
|
381 |
foreach ($this->html->find($tag) as $e) {
|
382 |
$e->innertext = call_user_func_array($this->url_rewrite_func,array($e->innertext));
|
|
|
|
|
383 |
}
|
384 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
}
|
386 |
|
387 |
// actually translate tags
|
@@ -413,11 +436,6 @@ class parser {
|
|
413 |
}
|
414 |
}
|
415 |
if ($newtext) {
|
416 |
-
/* if ($this->feed_fix) {
|
417 |
-
if (substr($newtext, 0, 4) == '<') {
|
418 |
-
$newtext = html_entity_decode($newtext);
|
419 |
-
}
|
420 |
-
}*/
|
421 |
$e->outertext = $newtext.$right;
|
422 |
|
423 |
}
|
184 |
if (($char == '.' || $char == '-') && ($this->is_white_space($nextchar))) return 1;
|
185 |
if (ord($char) == 226 && ord($nextchar) == 136 && ord($nextnextchar) == 153) return 3; //∙
|
186 |
if (ord($char) == 194 && ord($nextchar) == 183) return 2; //·
|
187 |
+
return (strpos(',?()[]"!:|;',$char) !== false) ? 1 : 0; // TODO: might need to add < and > here
|
188 |
}
|
189 |
|
190 |
/**
|
223 |
function parsetext($string) {
|
224 |
$pos = 0;
|
225 |
// $pos = skip_white_space($string, $pos);
|
226 |
+
// skip CDATA in feed_fix mode
|
227 |
+
if ($this->feed_fix) {
|
228 |
+
if (strpos($string,'<![CDATA[') === 0) {
|
229 |
+
$pos = 9; // CDATA length
|
230 |
+
$string = substr($string,0,-3); // chop the last ]]>;
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
$start = $pos;
|
235 |
|
236 |
while($pos < strlen($string)) {
|
245 |
//skip past entity
|
246 |
$pos += $len_of_entity;
|
247 |
}
|
248 |
+
// we have a special case for <> tags which might have came to us (maybe in xml feeds) (we'll skip them...)
|
249 |
+
elseif ($string[$pos] == '<') {
|
250 |
+
while ($string[$pos] != '>' && $pos < strlen($string)) $pos ++;
|
251 |
+
}
|
252 |
// will break translation unit when there's a breaker ",.[]()..."
|
253 |
elseif($senb_len = $this->is_sentence_breaker($string[$pos],$string[$pos+1],$string[$pos+2])) {
|
254 |
$this->tag_phrase($string,$start,$pos);
|
255 |
$pos += $senb_len;
|
256 |
$start = $pos;
|
257 |
}
|
258 |
+
// Numbers also break, if they are followed by whitespace (or a sentence breaker) (don't break 42nd) // TODO: probably by breaking entities too...
|
259 |
elseif($num_len = $this->is_number($string,$pos)) {
|
260 |
+
if ($this->is_white_space($string[$pos+$num_len]) || $this->is_sentence_breaker($string[$pos+$num_len],$string[$pos+$num_len+1],$string[$pos+$num_len+2])) {
|
261 |
$this->tag_phrase($string,$start,$pos);
|
262 |
$start = $pos + $num_len + 1;
|
263 |
}
|
270 |
|
271 |
// the end is also some breaker
|
272 |
if($pos > $start) {
|
273 |
+
$this->tag_phrase($string,$start,$pos);
|
274 |
}
|
275 |
}
|
276 |
|
386 |
return $this->html;
|
387 |
}
|
388 |
|
389 |
+
// fix feed
|
390 |
if ($this->feed_fix) {
|
391 |
+
// fix urls on feed
|
392 |
|
393 |
+
foreach (array('link','wfw:commentrss','comments') as $tag) {
|
394 |
foreach ($this->html->find($tag) as $e) {
|
395 |
$e->innertext = call_user_func_array($this->url_rewrite_func,array($e->innertext));
|
396 |
+
// no need to translate anything here
|
397 |
+
unset($e->nodes);
|
398 |
}
|
399 |
}
|
400 |
+
// guid is not really a url -- in some future, we can check if permalink is true and probably falsify it
|
401 |
+
foreach ($this->html->find('guid') as $e) {
|
402 |
+
$e->innertext = $e->innertext.'-'.$this->lang;
|
403 |
+
unset($e->nodes);
|
404 |
+
}
|
405 |
+
// fix feed language
|
406 |
+
$this->html->find('language', 0)->innertext = $this->lang;
|
407 |
+
unset($this->html->find('language', 0)->nodes);
|
408 |
}
|
409 |
|
410 |
// actually translate tags
|
436 |
}
|
437 |
}
|
438 |
if ($newtext) {
|
|
|
|
|
|
|
|
|
|
|
439 |
$e->outertext = $newtext.$right;
|
440 |
|
441 |
}
|
core/utils.php
CHANGED
@@ -168,7 +168,8 @@ function get_language_from_url($url, $home_url) {
|
|
168 |
$params = explode('&',$parsedurl['query']);
|
169 |
foreach ($params as $key => $param) {
|
170 |
if (stripos($param,LANG_PARAM) === 0) {
|
171 |
-
|
|
|
172 |
}
|
173 |
}
|
174 |
}
|
168 |
$params = explode('&',$parsedurl['query']);
|
169 |
foreach ($params as $key => $param) {
|
170 |
if (stripos($param,LANG_PARAM) === 0) {
|
171 |
+
$langa = explode("=",$params[$key]);
|
172 |
+
return ($langa[1]);
|
173 |
}
|
174 |
}
|
175 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://transposh.org/donate/
|
|
4 |
Tags: translation, widget, filter, bilingual, multilingual, transposh, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
|
5 |
Requires at least: 2.7
|
6 |
Tested up to: 2.8.6
|
7 |
-
Stable tag: 0.3.
|
8 |
|
9 |
Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
|
10 |
|
@@ -120,9 +120,16 @@ change the .css from transparent background to your page background color. And l
|
|
120 |
5. Widget style selection
|
121 |
|
122 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
= 2009/12/02 - 0.3.6 =
|
124 |
* Translated language posts are now searchable with the default wordpress search box
|
125 |
-
* Rewrite urls inside feeds so translated feeds become a much more valid option (thanks
|
126 |
* Fixed transposh_widget global bug
|
127 |
= 2009/11/26 - 0.3.5 =
|
128 |
* Enabled auto-translation to all editable languages on the admin side
|
4 |
Tags: translation, widget, filter, bilingual, multilingual, transposh, language, crowdsourcing, context, wiki, RTL, Hebrew, Spanish, French, Russian, English, Arabic, Portuguese
|
5 |
Requires at least: 2.7
|
6 |
Tested up to: 2.8.6
|
7 |
+
Stable tag: 0.3.7
|
8 |
|
9 |
Transposh filter allows in context quick translation of websites, it allows you to crowd-source the translation to your users
|
10 |
|
120 |
5. Widget style selection
|
121 |
|
122 |
== Changelog ==
|
123 |
+
= 2009/12/06 - 0.3.7 =
|
124 |
+
* Fix feed parsing
|
125 |
+
* Fix issue with parsing numbers before sentence breakers
|
126 |
+
* Change language tag in the feed (thanks [Kevin Hart](http://gainesvillecomputer.com/))
|
127 |
+
* Fix bug with search when not using permalinks
|
128 |
+
* Allow wrapping widget with an unordered list (thanks [Kevin Hart](http://gainesvillecomputer.com/))
|
129 |
+
* Fix clash with other plugins using JSON_Services
|
130 |
= 2009/12/02 - 0.3.6 =
|
131 |
* Translated language posts are now searchable with the default wordpress search box
|
132 |
+
* Rewrite urls inside feeds so translated feeds become a much more valid option (thanks [Kevin Hart](http://gainesvillecomputer.com/))
|
133 |
* Fixed transposh_widget global bug
|
134 |
= 2009/11/26 - 0.3.5 =
|
135 |
* Enabled auto-translation to all editable languages on the admin side
|
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.3.
|
8 |
Author URI: http://transposh.org/
|
9 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
10 |
*/
|
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.3.7
|
8 |
Author URI: http://transposh.org/
|
9 |
License: GPL (http://www.gnu.org/licenses/gpl.txt)
|
10 |
*/
|
transposh_options.php
CHANGED
@@ -74,6 +74,8 @@ define("WIDGET_STYLE", "widget_style");
|
|
74 |
define("WIDGET_PROGRESSBAR", "widget_progressbar");
|
75 |
//Use CSS sprites for flags if available
|
76 |
define("WIDGET_CSS_FLAGS", "widget_css_flags");
|
|
|
|
|
77 |
|
78 |
|
79 |
class transposh_plugin_options {
|
@@ -156,6 +158,10 @@ class transposh_plugin_options {
|
|
156 |
return $this->options[WIDGET_CSS_FLAGS];
|
157 |
}
|
158 |
|
|
|
|
|
|
|
|
|
159 |
function get_enable_permalinks() {
|
160 |
return $this->options[ENABLE_PERMALINKS];
|
161 |
}
|
@@ -241,11 +247,16 @@ class transposh_plugin_options {
|
|
241 |
$this->set_value($val, $this->options[WIDGET_STYLE]);
|
242 |
}
|
243 |
|
244 |
-
function set_widget_css_flags($val) {
|
245 |
$val = ($val) ? 1 : 0;
|
246 |
$this->set_value($val, $this->options[WIDGET_CSS_FLAGS]);
|
247 |
}
|
248 |
|
|
|
|
|
|
|
|
|
|
|
249 |
function set_enable_permalinks($val) {
|
250 |
$val = ($val) ? 1 : 0;
|
251 |
$this->set_value($val, $this->options[ENABLE_PERMALINKS]);
|
74 |
define("WIDGET_PROGRESSBAR", "widget_progressbar");
|
75 |
//Use CSS sprites for flags if available
|
76 |
define("WIDGET_CSS_FLAGS", "widget_css_flags");
|
77 |
+
//Wrap widget elements in an unordered list per #63 @since 0.3.7
|
78 |
+
define("WIDGET_IN_LIST", "widget_in_list");
|
79 |
|
80 |
|
81 |
class transposh_plugin_options {
|
158 |
return $this->options[WIDGET_CSS_FLAGS];
|
159 |
}
|
160 |
|
161 |
+
function get_widget_in_list() {
|
162 |
+
return $this->options[WIDGET_IN_LIST];
|
163 |
+
}
|
164 |
+
|
165 |
function get_enable_permalinks() {
|
166 |
return $this->options[ENABLE_PERMALINKS];
|
167 |
}
|
247 |
$this->set_value($val, $this->options[WIDGET_STYLE]);
|
248 |
}
|
249 |
|
250 |
+
function set_widget_css_flags($val) {
|
251 |
$val = ($val) ? 1 : 0;
|
252 |
$this->set_value($val, $this->options[WIDGET_CSS_FLAGS]);
|
253 |
}
|
254 |
|
255 |
+
function set_widget_in_list($val) {
|
256 |
+
$val = ($val) ? 1 : 0;
|
257 |
+
$this->set_value($val, $this->options[WIDGET_IN_LIST]);
|
258 |
+
}
|
259 |
+
|
260 |
function set_enable_permalinks($val) {
|
261 |
$val = ($val) ? 1 : 0;
|
262 |
$this->set_value($val, $this->options[ENABLE_PERMALINKS]);
|
transposh_widget.php
CHANGED
@@ -14,12 +14,12 @@
|
|
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 |
* Provides the sidebar widget for selecting a language and switching between edit/view
|
21 |
* mode.
|
22 |
-
|
23 |
|
24 |
require_once("core/constants.php");
|
25 |
require_once("core/utils.php");
|
@@ -28,20 +28,20 @@ require_once("transposh.php");
|
|
28 |
|
29 |
//class that reperesent the complete plugin
|
30 |
class transposh_plugin_widget {
|
31 |
-
/** @
|
32 |
private $transposh;
|
33 |
|
34 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
35 |
function transposh_plugin_widget(&$transposh) {
|
36 |
-
|
37 |
$this->transposh = &$transposh;
|
38 |
add_action('init', array(&$this,'init_transposh'),1);
|
39 |
add_action('widgets_init', array(&$this,'transposh_widget_init'));
|
40 |
}
|
41 |
|
42 |
-
/*
|
43 |
* Intercept init calls to see if it was posted by the widget.
|
44 |
-
|
45 |
function init_transposh() {
|
46 |
if (isset ($_POST['transposh_widget_posted'])) {
|
47 |
|
@@ -61,9 +61,9 @@ class transposh_plugin_widget {
|
|
61 |
$ref = rewrite_url_lang_param($ref,$this->transposh->home_url,$this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]);
|
62 |
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
}
|
68 |
|
69 |
|
@@ -73,9 +73,9 @@ class transposh_plugin_widget {
|
|
73 |
}
|
74 |
}
|
75 |
|
76 |
-
/*
|
77 |
* Register the widget.
|
78 |
-
|
79 |
function transposh_widget_init() {
|
80 |
|
81 |
if (!function_exists('register_sidebar_widget')) {
|
@@ -92,12 +92,12 @@ class transposh_plugin_widget {
|
|
92 |
add_action('wp_print_styles', array(&$this,'add_transposh_widget_css'));
|
93 |
}
|
94 |
|
95 |
-
/*
|
96 |
* Add custom css, i.e. transposh.css
|
97 |
-
|
98 |
function add_transposh_widget_css() {
|
99 |
-
|
100 |
-
|
101 |
if ($this->transposh->options->get_widget_style() == 1 || $this->transposh->options->get_widget_style() == 2) {
|
102 |
wp_enqueue_style("transposh_widget","{$this->transposh->transposh_plugin_url}/css/transposh_widget.css",array(),TRANSPOSH_PLUGIN_VER);
|
103 |
if ($this->transposh->options->get_widget_css_flags()) {
|
@@ -143,6 +143,7 @@ class transposh_plugin_widget {
|
|
143 |
case 2: // language list
|
144 |
//keep the flags in the same direction regardless of the overall page direction
|
145 |
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
|
|
146 |
|
147 |
foreach($GLOBALS['languages'] as $code => $lang2) {
|
148 |
list($language,$flag) = explode (",",$lang2);
|
@@ -156,23 +157,28 @@ class transposh_plugin_widget {
|
|
156 |
}
|
157 |
|
158 |
|
|
|
159 |
echo "<a href=\"" . $page_url . '"'.(($this->transposh->target_language == $code) ? ' class="tr_active"' :'').'>'.
|
160 |
-
|
161 |
-
|
162 |
if ($this->transposh->options->get_widget_style() != 1) {
|
163 |
echo "$language<br/>";
|
|
|
164 |
}
|
165 |
$is_showing_languages = TRUE;
|
166 |
}
|
167 |
}
|
|
|
168 |
echo "</div>";
|
169 |
|
170 |
// this is the form for the edit...
|
|
|
171 |
echo "<form action=\"$clean_page_url\" method=\"post\">";
|
172 |
echo "<input type=\"hidden\" name=\"lang\" id=\"lang\" value=\"{$this->transposh->target_language}\"/>";
|
173 |
break;
|
174 |
default: // language selection
|
175 |
|
|
|
176 |
echo "<form action=\"$clean_page_url\" method=\"post\">";
|
177 |
echo "<span class=\"" .NO_TRANSLATE_CLASS . "\" >";
|
178 |
echo "<select name=\"lang\" id=\"lang\" onchange=\"Javascript:this.form.submit();\">";
|
@@ -194,23 +200,34 @@ class transposh_plugin_widget {
|
|
194 |
|
195 |
//at least one language showing - add the edit box if applicable
|
196 |
if($is_showing_languages) {
|
197 |
-
|
198 |
if($this->transposh->is_editing_permitted()) {
|
199 |
echo "<input type=\"checkbox\" name=\"" . EDIT_PARAM . "\" value=\"1\" " .
|
200 |
-
|
201 |
-
|
202 |
}
|
203 |
|
204 |
echo "<input type=\"hidden\" name=\"transposh_widget_posted\" value=\"1\"/>";
|
205 |
}
|
206 |
else {
|
207 |
-
|
208 |
echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>';
|
209 |
}
|
210 |
|
|
|
211 |
echo "</form>";
|
212 |
-
//echo "<button onClick=\"do_auto_translate();\">translate all</button>";
|
213 |
-
echo "<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
echo $after_widget;
|
215 |
}
|
216 |
|
@@ -220,33 +237,36 @@ class transposh_plugin_widget {
|
|
220 |
$this->transposh->options->set_widget_style($_POST[WIDGET_STYLE]);
|
221 |
$this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]);
|
222 |
$this->transposh->options->set_widget_css_flags($_POST[WIDGET_CSS_FLAGS]);
|
|
|
223 |
if ($save)
|
224 |
$this->transposh->options->update_options();
|
225 |
// Avoid coming here twice...
|
226 |
unset($_POST['transposh-submit']);
|
227 |
}
|
228 |
|
229 |
-
/*
|
230 |
* This is the widget control, allowing the selection of presentation type.
|
231 |
-
|
232 |
function transposh_widget_control() {
|
233 |
if (isset($_POST['transposh-submit'])) $this->transposh_widget_post();
|
234 |
//$options = get_option(WIDGET_TRANSPOSH);
|
235 |
|
236 |
echo '<p><label for="'.WIDGET_STYLE.'">Style:<br />'.
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
|
|
|
|
250 |
}
|
251 |
}
|
252 |
|
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 |
* Provides the sidebar widget for selecting a language and switching between edit/view
|
21 |
* mode.
|
22 |
+
*/
|
23 |
|
24 |
require_once("core/constants.php");
|
25 |
require_once("core/utils.php");
|
28 |
|
29 |
//class that reperesent the complete plugin
|
30 |
class transposh_plugin_widget {
|
31 |
+
/** @var transposh_plugin Container class */
|
32 |
private $transposh;
|
33 |
|
34 |
//constructor of class, PHP4 compatible construction for backward compatibility
|
35 |
function transposh_plugin_widget(&$transposh) {
|
36 |
+
//Register callback for WordPress events
|
37 |
$this->transposh = &$transposh;
|
38 |
add_action('init', array(&$this,'init_transposh'),1);
|
39 |
add_action('widgets_init', array(&$this,'transposh_widget_init'));
|
40 |
}
|
41 |
|
42 |
+
/*
|
43 |
* Intercept init calls to see if it was posted by the widget.
|
44 |
+
*/
|
45 |
function init_transposh() {
|
46 |
if (isset ($_POST['transposh_widget_posted'])) {
|
47 |
|
61 |
$ref = rewrite_url_lang_param($ref,$this->transposh->home_url,$this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]);
|
62 |
|
63 |
|
64 |
+
//ref is generated with html entities encoded, needs to be
|
65 |
+
//decoded when used in the http header (i.e. 302 redirect)
|
66 |
+
//$ref = html_entity_decode($ref, ENT_NOQUOTES);
|
67 |
}
|
68 |
|
69 |
|
73 |
}
|
74 |
}
|
75 |
|
76 |
+
/*
|
77 |
* Register the widget.
|
78 |
+
*/
|
79 |
function transposh_widget_init() {
|
80 |
|
81 |
if (!function_exists('register_sidebar_widget')) {
|
92 |
add_action('wp_print_styles', array(&$this,'add_transposh_widget_css'));
|
93 |
}
|
94 |
|
95 |
+
/*
|
96 |
* Add custom css, i.e. transposh.css
|
97 |
+
*/
|
98 |
function add_transposh_widget_css() {
|
99 |
+
//include the transposh_widget.css
|
100 |
+
// TODO: user generated version
|
101 |
if ($this->transposh->options->get_widget_style() == 1 || $this->transposh->options->get_widget_style() == 2) {
|
102 |
wp_enqueue_style("transposh_widget","{$this->transposh->transposh_plugin_url}/css/transposh_widget.css",array(),TRANSPOSH_PLUGIN_VER);
|
103 |
if ($this->transposh->options->get_widget_css_flags()) {
|
143 |
case 2: // language list
|
144 |
//keep the flags in the same direction regardless of the overall page direction
|
145 |
echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
|
146 |
+
if ($this->transposh->options->get_widget_in_list()) echo "<ul>";
|
147 |
|
148 |
foreach($GLOBALS['languages'] as $code => $lang2) {
|
149 |
list($language,$flag) = explode (",",$lang2);
|
157 |
}
|
158 |
|
159 |
|
160 |
+
if ($this->transposh->options->get_widget_in_list()) echo "<li>";
|
161 |
echo "<a href=\"" . $page_url . '"'.(($this->transposh->target_language == $code) ? ' class="tr_active"' :'').'>'.
|
162 |
+
display_flag("$plugpath/img/flags", $flag, $language,$this->transposh->options->get_widget_css_flags()).
|
163 |
+
"</a>";
|
164 |
if ($this->transposh->options->get_widget_style() != 1) {
|
165 |
echo "$language<br/>";
|
166 |
+
if ($this->transposh->options->get_widget_in_list()) echo "</li>";
|
167 |
}
|
168 |
$is_showing_languages = TRUE;
|
169 |
}
|
170 |
}
|
171 |
+
if ($this->transposh->options->get_widget_in_list()) echo "</ul>";
|
172 |
echo "</div>";
|
173 |
|
174 |
// this is the form for the edit...
|
175 |
+
if ($this->transposh->options->get_widget_in_list()) echo "<ul><li>";
|
176 |
echo "<form action=\"$clean_page_url\" method=\"post\">";
|
177 |
echo "<input type=\"hidden\" name=\"lang\" id=\"lang\" value=\"{$this->transposh->target_language}\"/>";
|
178 |
break;
|
179 |
default: // language selection
|
180 |
|
181 |
+
if ($this->transposh->options->get_widget_in_list()) echo "<ul><li>";
|
182 |
echo "<form action=\"$clean_page_url\" method=\"post\">";
|
183 |
echo "<span class=\"" .NO_TRANSLATE_CLASS . "\" >";
|
184 |
echo "<select name=\"lang\" id=\"lang\" onchange=\"Javascript:this.form.submit();\">";
|
200 |
|
201 |
//at least one language showing - add the edit box if applicable
|
202 |
if($is_showing_languages) {
|
203 |
+
//Add the edit checkbox only for translators on languages marked as editable
|
204 |
if($this->transposh->is_editing_permitted()) {
|
205 |
echo "<input type=\"checkbox\" name=\"" . EDIT_PARAM . "\" value=\"1\" " .
|
206 |
+
($this->transposh->edit_mode ? "checked=\"checked\"" : "") .
|
207 |
+
" onclick=\"this.form.submit();\"/> Edit Translation";
|
208 |
}
|
209 |
|
210 |
echo "<input type=\"hidden\" name=\"transposh_widget_posted\" value=\"1\"/>";
|
211 |
}
|
212 |
else {
|
213 |
+
//no languages configured - error message
|
214 |
echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>';
|
215 |
}
|
216 |
|
217 |
+
if ($this->transposh->options->get_widget_in_list()) echo "</li></ul>";
|
218 |
echo "</form>";
|
219 |
+
//TODO: maybe... echo "<button onClick=\"do_auto_translate();\">translate all</button>";
|
220 |
+
if ($this->transposh->options->get_widget_in_list()) echo "<ul><li>";
|
221 |
+
// Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget
|
222 |
+
// first - according to the gpl, you may do so - but since the code has changed - please make in available under the gpl
|
223 |
+
// second - we did invest a lot of time and effort into this, and the link is a way to help us grow and show your appreciation, if it
|
224 |
+
// upsets you, feel more than free to move this link somewhere else on your page, such as the footer etc.
|
225 |
+
// third - feel free to write your own widget, the translation core will work
|
226 |
+
// forth - you can ask for permission, with a good reason, if you contributed to the code - it's a good enough reason :)
|
227 |
+
// last - if you just delete the following line, it means that you have little respect to the whole copyright thing, which as far as we
|
228 |
+
// understand means that by doing so - you are giving everybody else the right to do the same and use your work without any attribution
|
229 |
+
echo "<div id=\"".SPAN_PREFIX."credit\">by <a href=\"http://tran"."sposh.org\"><img class=\"".NO_TRANSLATE_CLASS."\" height=\"16\" width=\"16\" src=\"$plugpath/img/tplog"."o.png\" style=\"padding:1px;border:0px\" title=\"Transposh\" alt=\"Transposh\"/></a></div>";
|
230 |
+
if ($this->transposh->options->get_widget_in_list()) echo "</li></ul>";
|
231 |
echo $after_widget;
|
232 |
}
|
233 |
|
237 |
$this->transposh->options->set_widget_style($_POST[WIDGET_STYLE]);
|
238 |
$this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]);
|
239 |
$this->transposh->options->set_widget_css_flags($_POST[WIDGET_CSS_FLAGS]);
|
240 |
+
$this->transposh->options->set_widget_in_list($_POST[WIDGET_IN_LIST]);
|
241 |
if ($save)
|
242 |
$this->transposh->options->update_options();
|
243 |
// Avoid coming here twice...
|
244 |
unset($_POST['transposh-submit']);
|
245 |
}
|
246 |
|
247 |
+
/*
|
248 |
* This is the widget control, allowing the selection of presentation type.
|
249 |
+
*/
|
250 |
function transposh_widget_control() {
|
251 |
if (isset($_POST['transposh-submit'])) $this->transposh_widget_post();
|
252 |
//$options = get_option(WIDGET_TRANSPOSH);
|
253 |
|
254 |
echo '<p><label for="'.WIDGET_STYLE.'">Style:<br />'.
|
255 |
+
'<select id="transposh-style" name="'.WIDGET_STYLE.'">'.
|
256 |
+
'<option value="0"' . ($this->transposh->options->get_widget_style() == 0 ? ' selected="selected"' : '').'>Language selection</option>'.
|
257 |
+
'<option value="1"' . ($this->transposh->options->get_widget_style() == 1 ? ' selected="selected"' : '').'>Flags</option>'.
|
258 |
+
'<option value="2"' . ($this->transposh->options->get_widget_style() == 2 ? ' selected="selected"' : '').'>Language list</option>'.
|
259 |
+
'</select>'.
|
260 |
+
'</label></p>'.
|
261 |
+
'<p><label for="transposh-progress">Effects:</label><br/>'.
|
262 |
+
'<input type="checkbox" id="'.WIDGET_PROGRESSBAR.'" name="'.WIDGET_PROGRESSBAR.'"'.($this->transposh->options->get_widget_progressbar() ? ' checked="checked"' : '').'/>'.
|
263 |
+
'<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Show progress bar when a client triggers automatic translation">Show progress bar</span><br/>'.
|
264 |
+
'<input type="checkbox" id="'.WIDGET_CSS_FLAGS.'" name="'.WIDGET_CSS_FLAGS.'"'.($this->transposh->options->get_widget_css_flags() ? ' checked="checked"' : '').'/>'.
|
265 |
+
'<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Use a single sprite with all flags, makes pages load faster. Currently not suitable if you made changes to the flags.">Use CSS flags</span><br/>'.
|
266 |
+
'<input type="checkbox" id="'.WIDGET_IN_LIST.'" name="'.WIDGET_IN_LIST.'"'.($this->transposh->options->get_widget_in_list() ? ' checked="checked"' : '').'/>'.
|
267 |
+
'<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="Wraps generated widget code with UL helps with some CSSs.">Wrap widget with an unordered list (UL)</span>'.
|
268 |
+
'</p>'.
|
269 |
+
'<input type="hidden" name="transposh-submit" id="transposh-submit" value="1"/>';
|
270 |
}
|
271 |
}
|
272 |
|