qTranslate X - Version 2.9.3

Version Description

  • "Language Switcher" menu options, read FAQ for more information.
  • fix for too early call to current_user_can, which caused a debug notice from within some other plugins.
  • fix for https://wordpress.org/support/topic/editor-adds-characters-before-text
Download this release

Release Info

Developer johnclause
Plugin Icon wp plugin qTranslate X
Version 2.9.3
Comparing to
See all releases

Code changes from version 2.9.2 to 2.9.3

admin/xhaleera_addons.php DELETED
@@ -1,356 +0,0 @@
1
- <?php // encoding: utf-8
2
- /*
3
- Copyright 2014 qTranslate Team (email : qTranslateTeam@gmail.com )
4
-
5
- This program is free software; you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation; either version 2 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with this program; if not, write to the Free Software
17
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
- */
19
-
20
- function mqtrans_import_settings_from_qtrans() {
21
- global $wpdb;
22
-
23
- $option_names = $wpdb->get_col("SELECT `option_name` FROM {$wpdb->options} WHERE `option_name` LIKE 'qtranslate\_%'");
24
- foreach ($option_names as $name)
25
- {
26
- $opt = get_option($name);
27
-
28
- $nn = "m{$name}";
29
- if ( false !== get_option($nn) )
30
- update_option($nn, $opt);
31
- else
32
- add_option($nn, $opt);
33
- }
34
- }
35
-
36
- function mqtrans_export_setting_to_qtrans($updateOnly = false) {
37
- global $wpdb;
38
-
39
- $option_names = $wpdb->get_col("SELECT `option_name` FROM {$wpdb->options} WHERE `option_name` LIKE 'mqtranslate\_%'");
40
- foreach ($option_names as $name)
41
- {
42
- $opt = get_option($name);
43
-
44
- $nn = substr($name, 1);
45
- if ( false !== get_option($nn) )
46
- update_option($nn, $opt);
47
- else if (!$updateOnly)
48
- add_option($nn, $opt);
49
- }
50
- }
51
-
52
- function mqtrans_currentUserCanEdit($lang) {
53
- global $q_config;
54
-
55
- $cu = wp_get_current_user();
56
- if ($cu->has_cap('edit_users') || empty($q_config['ul_lang_protection']))
57
- return true;
58
- else
59
- {
60
- $user_meta = get_user_meta($cu->ID);
61
- if (empty($user_meta) || !is_array($user_meta) || !array_key_exists('mqtranslate_language_access', $user_meta))
62
- $user_langs = $q_config['enabled_languages'];
63
- else
64
- $user_langs = explode(',', get_user_meta($cu->ID, 'mqtranslate_language_access', true));
65
- return in_array($lang, $user_langs);
66
- }
67
- }
68
-
69
- function mqtrans_currentUserCanView($lang) {
70
- global $q_config;
71
-
72
- $cu = wp_get_current_user();
73
- if ($cu->has_cap('edit_users') || empty($q_config['ul_lang_protection']))
74
- return true;
75
- else
76
- {
77
- $master_lang = get_user_meta($cu->ID, 'mqtranslate_master_language', true);
78
- if (empty($master_lang))
79
- return ($lang === $q_config['default_language']);
80
- else
81
- return ($lang === $master_lang || $lang === $q_config['default_language']);
82
- }
83
- }
84
-
85
- function mqtrans_userProfile($user) {
86
- global $q_config;
87
-
88
- if (empty($q_config['ul_lang_protection']))
89
- return;
90
-
91
- $cu = wp_get_current_user();
92
- $langs = qtrans_getSortedLanguages();
93
-
94
- echo '<h3>'.__('mqTranslate User Language Settings', 'mqtranslate') . "</h3>\n";
95
- echo "<table class=\"form-table\">\n<tbody>\n";
96
-
97
- // Editable languages
98
- $user_meta = get_user_meta($user->ID);
99
- if (empty($user_meta) || !is_array($user_meta) || !array_key_exists('mqtranslate_language_access', $user_meta))
100
- $user_langs = $q_config['enabled_languages'];
101
- else
102
- $user_langs = explode(',', get_user_meta($user->ID, 'mqtranslate_language_access', true));
103
- echo "<tr>\n";
104
- if ($cu->ID == $user->ID)
105
- echo '<th>'.__('You can edit posts in', 'mqtranslate') . "</th>\n";
106
- else
107
- echo '<th>'.__('This user can edit posts in', 'mqtranslate') . "</th>\n";
108
- echo "<td>";
109
- if ($user->has_cap('edit_users'))
110
- {
111
- if (empty($langs))
112
- _e('No language available', 'mqtranslate');
113
- else if ($cu->ID == $user->ID)
114
- _e('As an Administrator, you can edit posts in all languages.', 'mqtranslate');
115
- else
116
- _e('As an Administrator, this user can edit posts in all languages.', 'mqtranslate');
117
- }
118
- else if ($cu->has_cap('edit_users'))
119
- {
120
- if (empty($langs))
121
- _e('No language available', 'mqtranslate')."\n";
122
- else
123
- {
124
- $checkboxes = array();
125
- foreach ($langs as $l) {
126
- $name = "mqtrans_user_lang_{$l}";
127
- $checked = (in_array($l, $user_langs)) ? 'checked' : '';
128
- $checkboxes[] = "<label for=\"{$name}\"><input type=\"checkbox\" name=\"mqtrans_user_lang[]\" id=\"{$name}\" value=\"{$l}\" {$checked} /> {$q_config['language_name'][$l]}</label>\n";
129
- }
130
- echo implode("<br />\n", $checkboxes);
131
- }
132
- }
133
- else
134
- {
135
- $intersect = array_intersect($langs, $user_langs);
136
- if (empty($intersect))
137
- _e('No language selected', 'mqtranslate')."\n";
138
- else
139
- {
140
- $languages = array();
141
- foreach ($intersect as $l)
142
- $languages[] = $q_config['language_name'][$l];
143
- echo implode(', ', $languages);
144
- }
145
- }
146
- echo "</td>\n";
147
- echo "</tr>\n";
148
-
149
- // Master language
150
- $user_master_lang = get_user_meta($user->ID, 'mqtranslate_master_language', true);
151
- echo "<tr>\n";
152
- echo '<th>' . __('Master language', 'mqtranslate') . "</th>\n";
153
- echo "<td>\n";
154
- if ($user->has_cap('edit_users'))
155
- _e('Not applicable to Administrators', 'mqtranslate');
156
- else if ($cu->has_cap('edit_users'))
157
- {
158
- echo "<select name=\"mqtrans_master_lang\">\n";
159
- echo '<option value="">' . __('Default Language', 'mqtranslate') . "</option>\n";
160
- foreach ($langs as $l)
161
- {
162
- if ($l == $q_config['default_language'])
163
- continue;
164
- $selected = ($user_master_lang == $l) ? ' selected' : '';
165
- echo "<option value=\"{$l}\"{$selected}>{$q_config['language_name'][$l]}</option>\n";
166
- }
167
- echo "</select>\n";
168
- echo '<span class="description">' . __('Language from which texts should be translated by this user', 'mqtranslate') . "</span>\n";
169
- }
170
- else
171
- {
172
- if (empty($langs) || empty($user_master_lang) || !in_array($user_master_lang, $langs))
173
- _e('Default Language', 'mqtranslate');
174
- else
175
- echo $q_config['language_name'][$user_master_lang];
176
- }
177
- echo "</td>\n";
178
- echo "</tr>\n";
179
-
180
- echo "</tbody>\n</table>\n";
181
- }
182
-
183
- function mqtrans_userProfileUpdate($user_id) {
184
- global $q_config;
185
- $cu = wp_get_current_user();
186
- if ($cu->has_cap('edit_users') && !empty($q_config['ul_lang_protection'])) {
187
- // Editable languages
188
- $langs = (empty($_POST['mqtrans_user_lang'])) ? array() : $_POST['mqtrans_user_lang'];
189
- if (!is_array($langs))
190
- $langs = array();
191
- update_user_meta($user_id, 'mqtranslate_language_access', implode(',', $langs));
192
-
193
- // Master language
194
- if (empty($_POST['mqtrans_master_lang']))
195
- delete_user_meta($user_id, 'mqtranslate_master_language');
196
- else
197
- update_user_meta($user_id, 'mqtranslate_master_language', $_POST['mqtrans_master_lang']);
198
- }
199
- }
200
-
201
- function qtrans_isEmptyContent($value) {
202
- $str = trim(strip_tags($value, '<img>,<embed>,<object>'));
203
- return empty($str);
204
- }
205
-
206
- function mqtrans_postUpdated($post_ID, $after, $before) {
207
- global $wpdb, $q_config;
208
-
209
- // Don't handle custom post types
210
- if (!in_array($after->post_type, array( 'post', 'page' )) && !in_array($after->post_type, $q_config['allowed_custom_post_types']))
211
- return;
212
-
213
- $titleMap = array();
214
- $contentMap = array();
215
-
216
- $cu = wp_get_current_user();
217
- if ($cu->has_cap('edit_users') || empty($q_config['ul_lang_protection']))
218
- {
219
- $title = qtrans_split($after->post_title, true, $titleMap);
220
- foreach ($title as $k => $v) {
221
- if (qtrans_isEmptyContent($v))
222
- unset($title[$k]);
223
- }
224
- $content = qtrans_split($after->post_content, true, $contentMap);
225
- foreach ($content as $k => $v) {
226
- if (qtrans_isEmptyContent($v))
227
- unset($content[$k]);
228
- }
229
- }
230
- else
231
- {
232
- $titleBeforeMap = array();
233
- $titleBefore = qtrans_split($before->post_title, true, $titleBeforeMap);
234
- $titleAfter = qtrans_split($after->post_title, true, $titleMap);
235
- foreach ($titleAfter as $k => $v) {
236
- if (!mqtrans_currentUserCanEdit($k))
237
- unset($titleAfter[$k], $titleMap[$k]);
238
- }
239
- $title = array_merge($titleBefore, $titleAfter);
240
- $titleMap = array_merge($titleBeforeMap, $titleMap);
241
-
242
- $contentBeforeMap = array();
243
- $contentBefore = qtrans_split($before->post_content, true, $contentBeforeMap);
244
- $contentAfter = qtrans_split($after->post_content, true, $contentMap);
245
- foreach ($contentAfter as $k => $v) {
246
- if (qtrans_isEmptyContent($v) || !mqtrans_currentUserCanEdit($k))
247
- unset($contentAfter[$k], $contentMap[$k]);
248
- }
249
- $content = array_merge($contentBefore, $contentAfter);
250
- $contentMap = array_merge($contentBeforeMap, $contentMap);
251
- }
252
-
253
- $data = array('post_title' => qtrans_join($title, $titleMap), 'post_content' => qtrans_join($content, $contentMap));
254
- if (get_magic_quotes_gpc())
255
- $data = stripslashes_deep($data);
256
- $where = array('ID' => $post_ID);
257
-
258
- $wpdb->update($wpdb->posts, $data, $where);
259
- }
260
-
261
- function mqtrans_filterHomeURL($url, $path, $orig_scheme, $blog_id) {
262
- global $q_config;
263
- return ((empty($path) && $q_config['url_mode'] == QT_URL_PATH) || $path == '/' || !empty($q_config['url_info']['explicit_default_language'])) ? qtrans_convertURL($url, '', false, $q_config['url_info']['explicit_default_language']) : $url;
264
- }
265
-
266
- function mqtrans_filterPostMetaData($original_value, $object_id, $meta_key, $single) {
267
- if ($meta_key == '_menu_item_url')
268
- {
269
- $meta = wp_cache_get($object_id, 'post_meta');
270
- if (!empty($meta) && array_key_exists($meta_key, $meta) && !empty($meta[$meta_key]))
271
- {
272
- if ($single === false)
273
- {
274
- if (is_array($meta[$meta_key]))
275
- $meta = $meta[$meta_key];
276
- else
277
- $meta = array($meta[$meta_key]);
278
- $meta = array_map('qtrans_convertURL', $meta);
279
- }
280
- else
281
- {
282
- if (is_array($meta[$meta_key]))
283
- $meta = $meta[$meta_key][0];
284
- else
285
- $meta = $meta[$meta_key];
286
- $meta = qtrans_convertURL($meta);
287
- }
288
- return $meta;
289
- }
290
- }
291
- return null;
292
- }
293
-
294
- function mqtrans_team_options() {
295
- global $q_config;
296
- ?>
297
- <h3><?php _e('mqTranslate Team Settings', 'mqtranslate') ?><span id="mqtranslate-show-team"> (<a name="mqtranslate_team_settings" href="#" onclick="return showTeamSettings();"><?php _e('Show / Hide', 'mqtranslate'); ?></a>)</span></h3>
298
- <table class="form-table" id="mqtranslate-team" style="display: none">
299
- <tr>
300
- <th scope="row"><?php _e('User-level Language Protection', 'mqtranslate') ?></th>
301
- <td>
302
- <label for="ul_lang_protection"><input type="checkbox" name="ul_lang_protection" id="ul_lang_protection" value="1"<?php echo ($q_config['ul_lang_protection'])?' checked="checked"':''; ?>/> <?php _e('Enable user-level language protection', 'mqtranslate'); ?></label>
303
- <br />
304
- <small><?php _e('When enabled, this option allows you to select which language is editable on a user-level account basis.', 'mqtranslate') ?></small>
305
- </td>
306
- </tr>
307
- </table>
308
- <script type="text/javascript">
309
- // <![CDATA[
310
- function showTeamSettings() {
311
- var el = document.getElementById('mqtranslate-team');
312
- if (el.style.display == 'block')
313
- el.style.display = 'none';
314
- else
315
- el.style.display='block';
316
- return false;
317
- }
318
- // ]]>
319
- </script>
320
- <?php
321
- }
322
-
323
- function mqtrans_load_team_options() {
324
- global $q_config;
325
- $opt = get_option('mqtranslate_ul_lang_protection');
326
- if ($opt === false)
327
- $q_config['ul_lang_protection'] = true;
328
- else
329
- $q_config['ul_lang_protection'] = ($opt == '1');
330
- }
331
-
332
- function mqtrans_save_team_options() {
333
- qtrans_checkSetting('ul_lang_protection', true, QT_BOOLEAN);
334
- }
335
-
336
- function mqtrans_editorExpand() {
337
- return false;
338
- }
339
-
340
- if (!defined('WP_ADMIN'))
341
- {
342
- add_filter('home_url', 'mqtrans_filterHomeURL', 10, 4);
343
- add_filter('get_post_metadata', 'mqtrans_filterPostMetaData', 10, 4);
344
- }
345
- else
346
- add_filter('wp_editor_expand', 'mqtrans_editorExpand');
347
-
348
- add_action('edit_user_profile', 'mqtrans_userProfile');
349
- add_action('show_user_profile', 'mqtrans_userProfile');
350
- add_action('profile_update', 'mqtrans_userProfileUpdate');
351
- add_action('post_updated', 'mqtrans_postUpdated', 10, 3);
352
-
353
- add_action('mqtranslate_configuration', 'mqtrans_team_options', 9);
354
- add_action('mqtranslate_loadConfig', 'mqtrans_load_team_options');
355
- add_action('mqtranslate_saveConfig', 'mqtrans_save_team_options');
356
- ?>
qtranslate.js CHANGED
@@ -31,8 +31,8 @@ qtranxj_split = function(text)
31
//c('matches='+matches);
32
if(matches==null) continue;
33
lang = matches[1];
34
- result[lang] += b.substring(10);
35
- //c('text='+result[lang]);
36
}
37
}else{
38
var split_regex_b = /(\[:[a-z]{2}\])/gi;
@@ -134,6 +134,7 @@ qtranxj_join_c = function(texts)
134
text += t;
135
text += '<!--:-->';
136
}
137
return text;
138
}
139
@@ -249,8 +250,8 @@ var qTranslateX=function()
249
if(!inpField) return;
250
var h=contentHooks[inpField.id]={};
251
h.contentField=inpField;
252
- h.contents=qtranxj_split(inpField.value);
253
- h.mlContentField=qtranxj_ce(inpField.tagName, {name: inpField.name, className: 'hidden', value: inpField.value}, form, true);
254
if(!separator){
255
if(inpField.tagName==='TEXTAREA')
256
separator='<';
31
//c('matches='+matches);
32
if(matches==null) continue;
33
lang = matches[1];
34
+ result[lang] += b.substring(b.indexOf('-->')+3);//b.substring(10);//stupid problem coming from TinyMCE like '<p><!--:en-->EN<!--:--><!--:de-->DE<!--:--></p>'
35
+ //c('text['+lang+']='+result[lang]);
36
}
37
}else{
38
var split_regex_b = /(\[:[a-z]{2}\])/gi;
134
text += t;
135
text += '<!--:-->';
136
}
137
+ //c('qtranxj_join_c:text:'+text);
138
return text;
139
}
140
250
if(!inpField) return;
251
var h=contentHooks[inpField.id]={};
252
h.contentField=inpField;
253
+ h.contents=qtranxj_split(inpField.value);//inpField.tagName
254
+ h.mlContentField=qtranxj_ce('input', {name: inpField.name, className: 'hidden', value: inpField.value}, form, true);
255
if(!separator){
256
if(inpField.tagName==='TEXTAREA')
257
separator='<';
qtranslate.min.js CHANGED
@@ -1 +1 @@
1
- function qtranxj_get_cookie(e){for(var n=document.cookie.split(";"),a=0;a<n.length;++a){var t=n[a],r=t.split("=");if(r[0].trim()==e&&!(n.length<2))return r[1].trim()}return""}function qtranxj_isArray(e){return e.constructor.toString().indexOf("Array")>=0}function qtranxj_ce(e,n,a,t){var r=document.createElement(e);if(n)for(prop in n)r[prop]=n[prop];return a&&(t&&a.firstChild?a.insertBefore(r,a.firstChild):a.appendChild(r)),r}function LanguageSwitch(e,n){function a(){var e=this;if(!e.lang)return void alert("qTranslate-X: This should not have happened: Please, report this incident to the developers: !tabSwitch.lang");if(i!==e.lang){i&&l[i].classList.remove("active"),i=e.lang,e.classList.add("active");for(var n=0;n<s.length;++n)s[n].call(this)}}var t=qTranslateConfig.enabled_languages,r=qTranslateConfig.language_name,i=n,l={},s=[];location.pathname.indexOf();for(var o=0;o<t.length;++o){var g=qTranslateConfig.flag_location,u=t[o],c=qtranxj_ce("li",{lang:u,className:"qtranxs-lang-switch",onclick:a},e);qtranxj_ce("img",{src:g+qTranslateConfig.flag[u]},c),qtranxj_ce("span",{innerHTML:r[u]},c),l[u]=c,i==u&&c.classList.add("active")}this.getActiveLanguage=function(){return i},this.onSwitch=function(e){"function"==typeof e&&s.push(e)}}qtranxj_split=function(e){for(var n=new Object,a=0;a<qTranslateConfig.enabled_languages.length;++a){var t=qTranslateConfig.enabled_languages[a];n[t]=""}var r=/<!--:-->/gi,i=e.xsplit(r);if(!qtranxj_isArray(i))return n;var l,s,t;if(i.length>1){s=/<!--:([a-z]{2})-->/gi;for(var a=0;a<i.length;++a){var o=i[a];o.length&&(l=s.exec(o),s.lastIndex=0,null!=l&&(t=l[1],n[t]+=o.substring(10)))}}else{var g=/(\[:[a-z]{2}\])/gi;if(i=e.xsplit(g),!qtranxj_isArray(i))return n;if(1==i.length)for(var o=i[0],u=0;u<qTranslateConfig.enabled_languages.length;++u){var t=qTranslateConfig.enabled_languages[u];n[t]+=o}else{s=/\[:([a-z]{2})\]/gi,t=!1;for(var a=0;a<i.length;++a){var o=i[a];if(t)n[t]+=o,t=!1;else{if(l=s.exec(o),s.lastIndex=0,null==l)continue;t=l[1]}}}}return n},qtranxj_join_c=function(e){for(var n="",a=0;a<qTranslateConfig.enabled_languages.length;++a){var t=qTranslateConfig.enabled_languages[a],r=e[t];r&&""!=r&&(n+="<!--:"+t+"-->",n+=r,n+="<!--:-->")}return n},qtranxj_join_b=function(e){for(var n="",a=0;a<qTranslateConfig.enabled_languages.length;++a){var t=qTranslateConfig.enabled_languages[a],r=e[t];r&&""!=r&&(n+="[:"+t+"]",n+=r)}return n},String.prototype.xsplit=function(e){if(3==="a~b".split(/(~)/).length)return this.split(e);e.global||(e=new RegExp(e.source,"g"+(e.ignoreCase?"i":"")));for(var n,a=0,t=[];null!=(n=e.exec(this));)t.push(this.slice(a,n.index)),n.length>1&&t.push(n[1]),a=e.lastIndex;return a<this.length&&t.push(this.slice(a)),a==this.length&&t.push(""),t};var qTranslateX=function(){function e(e){return document.getElementById(e)}function n(e,n){var a=g[e],t=languageSwitch.getActiveLanguage();a.contents[t]=n,a.mlContentField.value="<"===a.separator?qtranxj_join_c(a.contents):qtranxj_join_b(a.contents)}function a(e,a,t){if(e){var r=g[e.id]={};r.contentField=e,r.contents=qtranxj_split(e.value),r.mlContentField=qtranxj_ce(e.tagName,{name:e.name,className:"hidden",value:e.value},a,!0),t||(t="TEXTAREA"===e.tagName?"<":"["),r.separator=t,e.name+="_edit",e.value=r.contents[o],e.onblur=function(){n(this.id,this.value)}}}function t(e,n){a(e,n,"<")}function r(e,n){a(e,n,"[")}function i(){var n,a,t=!!e("tag-name");t?(n="tag-",a="addtag"):(n="",a="edittag");var r=e(n+"name"),i=e(a);if(!i||!r)return!1;var l=qTranslateConfig.language;build_translator=function(e,n){var a={};for(var t in qTranslateConfig.term_name){var r=qTranslateConfig.term_name[t],i=r[e],l=r[n];if(!i||!l){var s=r[qTranslateConfig.default_language];if(!s)continue;i||(i=s+"("+qTranslateConfig.default_language+")"),l||(l=s+"("+qTranslateConfig.default_language+")")}a[i]=l}return a};var s=e("the-list");hideQuickEdit=function(){if(s)for(var e=s.getElementsByTagName("TR"),n=0;n<e.length;n++)for(var a=e[n],t=a.getElementsByTagName("TD")[0],r=t.getElementsByClassName("inline"),i=0;i<r.length;++i){var l=r[i];l.style.display="none"}},hideQuickEdit(),updateNames=function(e,n){if(s)for(var a=s.getElementsByTagName("TR"),t=0;t<a.length;t++){for(var r,i=a[t],o=i.getElementsByTagName("TD")[0],g=o.getElementsByTagName("DIV"),u=0;u<g.length;u++){var c=g[u];if("name"===c.className){r=c.innerHTML;break}}if(l!=qTranslateConfig.default_language){var f=build_translator(l,qTranslateConfig.default_language);r=f[r]}for(var d=qTranslateConfig.term_name[r]||{},h=d[e]||"",v=d[n]||"",m=o.getElementsByClassName("row-title"),p=0;p<m.length;++p){var c=m[p];h?c.innerHTML=c.innerHTML.replace(h,v):c.innerHTML+=v}}};var g=document.getElementsByClassName("tagcloud")[0];updateTagCloud=function(e,n){if(g){var a=g.getElementsByTagName("A");if(a.length)for(var t=build_translator(e,n),r=0;r<a.length;++r){var i=a[r],l=i.innerHTML,s=t[l];s&&(i.innerHTML=s)}}},updateNamesAndTagCloud=function(e,n){updateNames(e,n),updateTagCloud(e,n)},l!==o&&updateNamesAndTagCloud(l,o);var u=qtranxj_ce("input",{name:r.name,className:"hidden",value:r.value},i,!0);r.name="";var c=qTranslateConfig.term_name[r.value]||{};o!==qTranslateConfig.default_language&&(r.value=c[o]||""),editinline_activated=function(){return!0};for(var f=document.getElementsByClassName("editinline"),d=0;d<f.length;++d){var h=f[d];"A"===h.tagName&&h.addEventListener("click",editinline_activated)}onTabSwitch=function(){o!==this.lang&&(r.value=c[this.lang]||"",updateNamesAndTagCloud(o,this.lang),o=this.lang)};for(var v=qTranslateConfig.enabled_languages,m={},d=0;d<v.length;++d){var p=v[d];m[p]=qtranxj_ce("input",{name:"qtranx_term_"+p,className:"hidden",value:name[p]||""},i,!0)}return r.onblur=function(){var e=languageSwitch.getActiveLanguage();m[e].value=this.value,c[e]=this.value,e===qTranslateConfig.default_language&&(u.value=this.value)},!0}function l(){function i(e,n){switch(qTranslateConfig.url_mode.toString()){case"1":e.search?e.search+="&lang="+n:e.search="?lang="+n;break;case"2":var a=qTranslateConfig.url_info_home,t=e.pathname.indexOf(a);e.pathname=a+n+e.pathname.substring(t+a.length-1);break;case"3":e.host=n+"."+e.host}}function l(n){if(!x){var a=e("view-post-btn");if(!a||!a.children.length)return;if(x=a.children[0],"A"!=x.tagName)return;b=x.href,E=qtranxj_ce("a",{})}E.href=b,i(E,n),x.href=E.href;var t=e("preview-action");if(t&&t.children.length&&(t.children[0].href=E.href),1!=qTranslateConfig.url_mode){if(!N){var r=e("sample-permalink");r&&r.childNodes.length&&(N=r.childNodes[0],y=N.nodeValue)}N&&(E.href=y,i(E,n),N.nodeValue=E.href)}}function s(e){var a=e.id;if(a){var t=g[a];t.mce||(t.mce=e,e.getBody().addEventListener("blur",function(){n(e.id,e.getContent())}))}}var u=e("post");if(!u)return!1;var c=e("title");c&&t(c,u);for(var f=u.getElementsByClassName("wp-editor-area"),d=0;d<f.length;++d){var h=f[d];t(h,u)}var v=e("attachment_caption");v&&t(v,u);for(var d=0;d<qTranslateConfig.custom_fields.length;++d){var m,p=qTranslateConfig.custom_fields[d];(0==p.indexOf("<")||0==p.indexOf("["))&&(m=p.substring(0,1),p=p.substring(1));var _=e(p);a(_,u,m)}for(var d=0;d<qTranslateConfig.custom_field_classes.length;++d){var m,T=qTranslateConfig.custom_field_classes[d];(0==T.indexOf("<")||0==T.indexOf("["))&&(m=T.substring(0,1),T=T.substring(1));for(var C=u.getElementsByClassName(T),q=0;q<C.length;++q)_=C[q],a(_,u,m)}var w=e("attachment_alt");w&&r(w,u);var x,b,E,N,y;return l(o),onTabSwitch=function(){for(var e in g){var n=g[e];n.contentField.value=n.contents[this.lang]}if(w&&(w.value=alttexts[this.lang]),l(this.lang),window.tinyMCE)for(var a=0;a<tinyMCE.editors.length;++a){var t=tinyMCE.editors[a],n=g[t.id];n&&t.setContent(n.contentField.value)}},window.addEventListener("load",function(){if(window.tinyMCE){for(var e=0;e<tinyMCE.editors.length;++e){var n=tinyMCE.editors[e];s(n)}for(var a in g){var t=g[a];t.mce||"TEXTAREA"===t.contentField.tagName&&(tinyMCEPreInit.mceInit[a].init_instance_callback=function(e){s(e)})}}}),!0}function s(){var n=document.getElementsByTagName("FORM");if(!n.length)return!1;var a=n[0];return r(e("blogname"),a),r(e("blogdescription"),a),onTabSwitch=function(){for(var e in g){var n=g[e];n.contentField.value=n.contents[this.lang]}},!0}var o=qtranxj_get_cookie("wp_qtrans_edit_language");o||(o=qTranslateConfig.language);var g={};setLangCookie=function(){document.cookie="wp_qtrans_edit_language="+this.lang};var u=location.pathname.match(/(\/wp-admin\/([^\/]*))#x2F;);switch(u&&u[1]){case"/wp-admin/post.php":case"/wp-admin/post-new.php":if(!l())return;break;case"/wp-admin/edit-tags.php":if(!i())return;break;case"/wp-admin/options-general.php":if(location.search.indexOf("page=")>=0)return;if(!s())return;break;default:return}var c=qtranxj_ce("ul",{className:"qtranxs-lang-switch-wrap"}),f=document.getElementsByClassName("wrap")[0],d=f.getElementsByTagName("form")[0];d.parentNode.insertBefore(c,d),languageSwitch=new LanguageSwitch(c,o),languageSwitch.onSwitch(onTabSwitch),languageSwitch.onSwitch(setLangCookie)};new qTranslateX;
1
+ function qtranxj_get_cookie(e){for(var n=document.cookie.split(";"),a=0;a<n.length;++a){var t=n[a],r=t.split("=");if(r[0].trim()==e&&!(n.length<2))return r[1].trim()}return""}function qtranxj_isArray(e){return e.constructor.toString().indexOf("Array")>=0}function qtranxj_ce(e,n,a,t){var r=document.createElement(e);if(n)for(prop in n)r[prop]=n[prop];return a&&(t&&a.firstChild?a.insertBefore(r,a.firstChild):a.appendChild(r)),r}function LanguageSwitch(e,n){function a(){var e=this;if(!e.lang)return void alert("qTranslate-X: This should not have happened: Please, report this incident to the developers: !tabSwitch.lang");if(i!==e.lang){i&&l[i].classList.remove("active"),i=e.lang,e.classList.add("active");for(var n=0;n<s.length;++n)s[n].call(this)}}var t=qTranslateConfig.enabled_languages,r=qTranslateConfig.language_name,i=n,l={},s=[];location.pathname.indexOf();for(var o=0;o<t.length;++o){var g=qTranslateConfig.flag_location,u=t[o],f=qtranxj_ce("li",{lang:u,className:"qtranxs-lang-switch",onclick:a},e);qtranxj_ce("img",{src:g+qTranslateConfig.flag[u]},f),qtranxj_ce("span",{innerHTML:r[u]},f),l[u]=f,i==u&&f.classList.add("active")}this.getActiveLanguage=function(){return i},this.onSwitch=function(e){"function"==typeof e&&s.push(e)}}qtranxj_split=function(e){for(var n=new Object,a=0;a<qTranslateConfig.enabled_languages.length;++a){var t=qTranslateConfig.enabled_languages[a];n[t]=""}var r=/<!--:-->/gi,i=e.xsplit(r);if(!qtranxj_isArray(i))return n;var l,s,t;if(i.length>1){s=/<!--:([a-z]{2})-->/gi;for(var a=0;a<i.length;++a){var o=i[a];o.length&&(l=s.exec(o),s.lastIndex=0,null!=l&&(t=l[1],n[t]+=o.substring(o.indexOf("-->")+3)))}}else{var g=/(\[:[a-z]{2}\])/gi;if(i=e.xsplit(g),!qtranxj_isArray(i))return n;if(1==i.length)for(var o=i[0],u=0;u<qTranslateConfig.enabled_languages.length;++u){var t=qTranslateConfig.enabled_languages[u];n[t]+=o}else{s=/\[:([a-z]{2})\]/gi,t=!1;for(var a=0;a<i.length;++a){var o=i[a];if(t)n[t]+=o,t=!1;else{if(l=s.exec(o),s.lastIndex=0,null==l)continue;t=l[1]}}}}return n},qtranxj_join_c=function(e){for(var n="",a=0;a<qTranslateConfig.enabled_languages.length;++a){var t=qTranslateConfig.enabled_languages[a],r=e[t];r&&""!=r&&(n+="<!--:"+t+"-->",n+=r,n+="<!--:-->")}return n},qtranxj_join_b=function(e){for(var n="",a=0;a<qTranslateConfig.enabled_languages.length;++a){var t=qTranslateConfig.enabled_languages[a],r=e[t];r&&""!=r&&(n+="[:"+t+"]",n+=r)}return n},String.prototype.xsplit=function(e){if(3==="a~b".split(/(~)/).length)return this.split(e);e.global||(e=new RegExp(e.source,"g"+(e.ignoreCase?"i":"")));for(var n,a=0,t=[];null!=(n=e.exec(this));)t.push(this.slice(a,n.index)),n.length>1&&t.push(n[1]),a=e.lastIndex;return a<this.length&&t.push(this.slice(a)),a==this.length&&t.push(""),t};var qTranslateX=function(){function e(e){return document.getElementById(e)}function n(e,n){var a=g[e],t=languageSwitch.getActiveLanguage();a.contents[t]=n,a.mlContentField.value="<"===a.separator?qtranxj_join_c(a.contents):qtranxj_join_b(a.contents)}function a(e,a,t){if(e){var r=g[e.id]={};r.contentField=e,r.contents=qtranxj_split(e.value),r.mlContentField=qtranxj_ce("input",{name:e.name,className:"hidden",value:e.value},a,!0),t||(t="TEXTAREA"===e.tagName?"<":"["),r.separator=t,e.name+="_edit",e.value=r.contents[o],e.onblur=function(){n(this.id,this.value)}}}function t(e,n){a(e,n,"<")}function r(e,n){a(e,n,"[")}function i(){var n,a,t=!!e("tag-name");t?(n="tag-",a="addtag"):(n="",a="edittag");var r=e(n+"name"),i=e(a);if(!i||!r)return!1;var l=qTranslateConfig.language;build_translator=function(e,n){var a={};for(var t in qTranslateConfig.term_name){var r=qTranslateConfig.term_name[t],i=r[e],l=r[n];if(!i||!l){var s=r[qTranslateConfig.default_language];if(!s)continue;i||(i=s+"("+qTranslateConfig.default_language+")"),l||(l=s+"("+qTranslateConfig.default_language+")")}a[i]=l}return a};var s=e("the-list");hideQuickEdit=function(){if(s)for(var e=s.getElementsByTagName("TR"),n=0;n<e.length;n++)for(var a=e[n],t=a.getElementsByTagName("TD")[0],r=t.getElementsByClassName("inline"),i=0;i<r.length;++i){var l=r[i];l.style.display="none"}},hideQuickEdit(),updateNames=function(e,n){if(s)for(var a=s.getElementsByTagName("TR"),t=0;t<a.length;t++){for(var r,i=a[t],o=i.getElementsByTagName("TD")[0],g=o.getElementsByTagName("DIV"),u=0;u<g.length;u++){var f=g[u];if("name"===f.className){r=f.innerHTML;break}}if(l!=qTranslateConfig.default_language){var c=build_translator(l,qTranslateConfig.default_language);r=c[r]}for(var d=qTranslateConfig.term_name[r]||{},h=d[e]||"",v=d[n]||"",m=o.getElementsByClassName("row-title"),p=0;p<m.length;++p){var f=m[p];h?f.innerHTML=f.innerHTML.replace(h,v):f.innerHTML+=v}}};var g=document.getElementsByClassName("tagcloud")[0];updateTagCloud=function(e,n){if(g){var a=g.getElementsByTagName("A");if(a.length)for(var t=build_translator(e,n),r=0;r<a.length;++r){var i=a[r],l=i.innerHTML,s=t[l];s&&(i.innerHTML=s)}}},updateNamesAndTagCloud=function(e,n){updateNames(e,n),updateTagCloud(e,n)},l!==o&&updateNamesAndTagCloud(l,o);var u=qtranxj_ce("input",{name:r.name,className:"hidden",value:r.value},i,!0);r.name="";var f=qTranslateConfig.term_name[r.value]||{};o!==qTranslateConfig.default_language&&(r.value=f[o]||""),editinline_activated=function(){return!0};for(var c=document.getElementsByClassName("editinline"),d=0;d<c.length;++d){var h=c[d];"A"===h.tagName&&h.addEventListener("click",editinline_activated)}onTabSwitch=function(){o!==this.lang&&(r.value=f[this.lang]||"",updateNamesAndTagCloud(o,this.lang),o=this.lang)};for(var v=qTranslateConfig.enabled_languages,m={},d=0;d<v.length;++d){var p=v[d];m[p]=qtranxj_ce("input",{name:"qtranx_term_"+p,className:"hidden",value:name[p]||""},i,!0)}return r.onblur=function(){var e=languageSwitch.getActiveLanguage();m[e].value=this.value,f[e]=this.value,e===qTranslateConfig.default_language&&(u.value=this.value)},!0}function l(){function i(e,n){switch(qTranslateConfig.url_mode.toString()){case"1":e.search?e.search+="&lang="+n:e.search="?lang="+n;break;case"2":var a=qTranslateConfig.url_info_home,t=e.pathname.indexOf(a);e.pathname=a+n+e.pathname.substring(t+a.length-1);break;case"3":e.host=n+"."+e.host}}function l(n){if(!w){var a=e("view-post-btn");if(!a||!a.children.length)return;if(w=a.children[0],"A"!=w.tagName)return;b=w.href,E=qtranxj_ce("a",{})}E.href=b,i(E,n),w.href=E.href;var t=e("preview-action");if(t&&t.children.length&&(t.children[0].href=E.href),1!=qTranslateConfig.url_mode){if(!N){var r=e("sample-permalink");r&&r.childNodes.length&&(N=r.childNodes[0],y=N.nodeValue)}N&&(E.href=y,i(E,n),N.nodeValue=E.href)}}function s(e){var a=e.id;if(a){var t=g[a];t.mce||(t.mce=e,e.getBody().addEventListener("blur",function(){n(e.id,e.getContent())}))}}var u=e("post");if(!u)return!1;var f=e("title");f&&t(f,u);for(var c=u.getElementsByClassName("wp-editor-area"),d=0;d<c.length;++d){var h=c[d];t(h,u)}var v=e("attachment_caption");v&&t(v,u);for(var d=0;d<qTranslateConfig.custom_fields.length;++d){var m,p=qTranslateConfig.custom_fields[d];(0==p.indexOf("<")||0==p.indexOf("["))&&(m=p.substring(0,1),p=p.substring(1));var _=e(p);a(_,u,m)}for(var d=0;d<qTranslateConfig.custom_field_classes.length;++d){var m,T=qTranslateConfig.custom_field_classes[d];(0==T.indexOf("<")||0==T.indexOf("["))&&(m=T.substring(0,1),T=T.substring(1));for(var C=u.getElementsByClassName(T),q=0;q<C.length;++q)_=C[q],a(_,u,m)}var x=e("attachment_alt");x&&r(x,u);var w,b,E,N,y;return l(o),onTabSwitch=function(){for(var e in g){var n=g[e];n.contentField.value=n.contents[this.lang]}if(x&&(x.value=alttexts[this.lang]),l(this.lang),window.tinyMCE)for(var a=0;a<tinyMCE.editors.length;++a){var t=tinyMCE.editors[a],n=g[t.id];n&&t.setContent(n.contentField.value)}},window.addEventListener("load",function(){if(window.tinyMCE){for(var e=0;e<tinyMCE.editors.length;++e){var n=tinyMCE.editors[e];s(n)}for(var a in g){var t=g[a];t.mce||"TEXTAREA"===t.contentField.tagName&&(tinyMCEPreInit.mceInit[a].init_instance_callback=function(e){s(e)})}}}),!0}function s(){var n=document.getElementsByTagName("FORM");if(!n.length)return!1;var a=n[0];return r(e("blogname"),a),r(e("blogdescription"),a),onTabSwitch=function(){for(var e in g){var n=g[e];n.contentField.value=n.contents[this.lang]}},!0}var o=qtranxj_get_cookie("wp_qtrans_edit_language");o||(o=qTranslateConfig.language);var g={};setLangCookie=function(){document.cookie="wp_qtrans_edit_language="+this.lang};var u=location.pathname.match(/(\/wp-admin\/([^\/]*))#x2F;);switch(u&&u[1]){case"/wp-admin/post.php":case"/wp-admin/post-new.php":if(!l())return;break;case"/wp-admin/edit-tags.php":if(!i())return;break;case"/wp-admin/options-general.php":if(location.search.indexOf("page=")>=0)return;if(!s())return;break;default:return}var f=qtranxj_ce("ul",{className:"qtranxs-lang-switch-wrap"}),c=document.getElementsByClassName("wrap")[0],d=c.getElementsByTagName("form")[0];d.parentNode.insertBefore(f,d),languageSwitch=new LanguageSwitch(f,o),languageSwitch.onSwitch(onTabSwitch),languageSwitch.onSwitch(setLangCookie)};new qTranslateX;
qtranslate.php CHANGED
@@ -1,9 +1,9 @@
1
<?php // encoding: utf-8
2
/**
3
- Plugin Name: qTranslate X
4
Plugin URI: http://wordpress.org/plugins/qtranslate-x/
5
Description: Adds user-friendly and database-friendly multilingual content support into WordPress.
6
- Version: 2.9.2
7
Author: John Clause based on original code by Qian Qin
8
Author URI: http://qtranslatexteam.wordpress.com/about
9
Tags: multilingual, multi, language, admin, tinymce, Polyglot, bilingual, widget, switcher, professional, human, translation, service, qTranslate, zTranslate, mqTranslate, qTranslate Plus, WPML
@@ -138,7 +138,7 @@ $q_config['enabled_languages'] = array(
138
139
// sets default language
140
$q_config['default_language'] = 'en';
141
- $q_config['language'] = $q_config['default_language'];//otherwise some early called (before qtranxf_init) functions complain
142
143
// enables browser language detection
144
$q_config['detect_browser_language'] = true;
1
<?php // encoding: utf-8
2
/**
3
+ Plugin Name: qTranslate-X
4
Plugin URI: http://wordpress.org/plugins/qtranslate-x/
5
Description: Adds user-friendly and database-friendly multilingual content support into WordPress.
6
+ Version: 2.9.3
7
Author: John Clause based on original code by Qian Qin
8
Author URI: http://qtranslatexteam.wordpress.com/about
9
Tags: multilingual, multi, language, admin, tinymce, Polyglot, bilingual, widget, switcher, professional, human, translation, service, qTranslate, zTranslate, mqTranslate, qTranslate Plus, WPML
138
139
// sets default language
140
$q_config['default_language'] = 'en';
141
+ $q_config['language'] = $q_config['default_language'];//otherwise some early called (before qtranxf_init_language) functions complain
142
143
// enables browser language detection
144
$q_config['detect_browser_language'] = true;
qtranslate_configuration.php CHANGED
@@ -18,44 +18,43 @@
18
*/
19
20
// Exit if accessed directly
21
- if ( !defined( 'ABSPATH' ) ) exit;
22
23
require_once(dirname(__FILE__)."/admin/import_export.php");
24
require_once(dirname(__FILE__)."/admin/activation_hook.php");
25
26
- function qtranxf_update_config()
27
{
28
- //if(!defined('WP_ADMIN')) return;
29
if(!current_user_can('manage_options')) return;
30
- if(isset($_POST['qtranslate_reset']) && isset($_POST['qtranslate_reset2'])) {
31
- // reset all settings
32
- delete_option('qtranslate_language_names');
33
- delete_option('qtranslate_enabled_languages');
34
- delete_option('qtranslate_default_language');
35
- delete_option('qtranslate_flag_location');
36
- delete_option('qtranslate_flags');
37
- delete_option('qtranslate_locales');
38
- delete_option('qtranslate_na_messages');
39
- delete_option('qtranslate_date_formats');
40
- delete_option('qtranslate_time_formats');
41
- delete_option('qtranslate_use_strftime');
42
- delete_option('qtranslate_ignore_file_types');
43
- delete_option('qtranslate_url_mode');
44
- delete_option('qtranslate_detect_browser_language');
45
- delete_option('qtranslate_hide_untranslated');
46
- delete_option('qtranslate_show_displayed_language_prefix');
47
- delete_option('qtranslate_auto_update_mo');
48
- delete_option('qtranslate_next_update_mo');
49
- delete_option('qtranslate_hide_default_language');
50
- delete_option('qtranslate_qtrans_compatibility');
51
- delete_option('qtranslate_custom_fields');
52
- if(isset($_POST['qtranslate_reset3'])) {
53
- delete_option('qtranslate_term_name');
54
- delete_option('qtranslate_widget_css');
55
- }
56
}
57
}
58
- add_action('qtranxf_init_begin','qtranxf_update_config',10);
59
60
function qtranxf_add_admin_js () {
61
global $q_config;
@@ -919,7 +918,7 @@ function qtranxf_nav_menu_metabox( $object )
919
<span class="list-controls hide-if-no-js">
920
<a href="javascript:void(0);" class="help" onclick="jQuery( '#help-login-links' ).toggle();"><?php _e( 'Help' ); ?></a>
921
<span class="hide-if-js" id="help-login-links"><br/><a name="help-login-links"></a>
922
- Menu item added is replaced with a sub-menu of available languages when menu is rendered. Depending on how your theme renders menu you may need to override and customize css entries .qtranxs-lang-menu and .qtranxs-lang-menu-item, originally defined in qtranslate.css.
923
</span>
924
</span>
925
<p class="button-controls">
18
*/
19
20
// Exit if accessed directly
21
+ if ( !defined( 'WP_ADMIN' ) ) exit;
22
23
require_once(dirname(__FILE__)."/admin/import_export.php");
24
require_once(dirname(__FILE__)."/admin/activation_hook.php");
25
26
+ function qtranxf_reset_config()
27
{
28
if(!current_user_can('manage_options')) return;
29
+ if( !isset($_POST['qtranslate_reset']) || !isset($_POST['qtranslate_reset2']) ) return;
30
+ // reset all settings
31
+ delete_option('qtranslate_language_names');
32
+ delete_option('qtranslate_enabled_languages');
33
+ delete_option('qtranslate_default_language');
34
+ delete_option('qtranslate_flag_location');
35
+ delete_option('qtranslate_flags');
36
+ delete_option('qtranslate_locales');
37
+ delete_option('qtranslate_na_messages');
38
+ delete_option('qtranslate_date_formats');
39
+ delete_option('qtranslate_time_formats');
40
+ delete_option('qtranslate_use_strftime');
41
+ delete_option('qtranslate_ignore_file_types');
42
+ delete_option('qtranslate_url_mode');
43
+ delete_option('qtranslate_detect_browser_language');
44
+ delete_option('qtranslate_hide_untranslated');
45
+ delete_option('qtranslate_show_displayed_language_prefix');
46
+ delete_option('qtranslate_auto_update_mo');
47
+ delete_option('qtranslate_next_update_mo');
48
+ delete_option('qtranslate_hide_default_language');
49
+ delete_option('qtranslate_qtrans_compatibility');
50
+ delete_option('qtranslate_custom_fields');
51
+ if(isset($_POST['qtranslate_reset3'])) {
52
+ delete_option('qtranslate_term_name');
53
+ delete_option('qtranslate_widget_css');
54
}
55
+ qtranxf_loadConfig();
56
}
57
+ add_action('qtranxf_init_begin','qtranxf_reset_config');
58
59
function qtranxf_add_admin_js () {
60
global $q_config;
918
<span class="list-controls hide-if-no-js">
919
<a href="javascript:void(0);" class="help" onclick="jQuery( '#help-login-links' ).toggle();"><?php _e( 'Help' ); ?></a>
920
<span class="hide-if-js" id="help-login-links"><br/><a name="help-login-links"></a>
921
+ Menu item added is replaced with a sub-menu of available languages when menu is rendered. Depending on how your theme renders menu you may need to override and customize css entries .qtranxs-lang-menu and .qtranxs-lang-menu-item, originally defined in qtranslate.css. The field "URL" of inserted menu item allows additional configuration described in <a href="https://wordpress.org/plugins/qtranslate-x/faq" target="blank">FAQ</a>.<br>
922
</span>
923
</span>
924
<p class="button-controls">
qtranslate_core.php CHANGED
@@ -22,49 +22,31 @@ if ( !defined( 'ABSPATH' ) ) exit;
22
23
/* qTranslate Functions */
24
25
- function qtranxf_init() {
26
global $q_config;
27
// check if it isn't already initialized
28
- if(defined('QTRANX_INIT')) return;
29
define('QTRANX_INIT',true);
30
31
- do_action('qtranxf_init_begin');
32
-
33
qtranxf_loadConfig();
34
35
- if(defined('WP_ADMIN')){
36
- // update Gettext Databases if on Backend
37
- if($q_config['auto_update_mo']) qtranxf_updateGettextDatabases();
38
- // update definitions if neccesary
39
- if(current_user_can('manage_categories')) qtranxf_updateTermLibrary();
40
- $q_config['cookie_enabled']=isset($_COOKIE[QTX_COOKIE_NAME_ADMIN]);
41
- }else{
42
- $q_config['cookie_enabled']=isset($_COOKIE[QTX_COOKIE_NAME_FRONT]);
43
- }
44
45
$host=$_SERVER['HTTP_HOST'];
46
//on different port, it will not work for now
47
//if(isset($_SERVER['SERVER_PORT']) && !empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT']!='80'){
48
// $host.=':'.$_SERVER['SERVER_PORT'];
49
//}
50
- //qtranxf_dbg_log('qtranxf_init: IP='.$_SERVER['REMOTE_ADDR']);
51
- //qtranxf_dbg_log('qtranxf_init: URL='.$host.$_SERVER['REQUEST_URI']);
52
- //qtranxf_dbg_log('qtranxf_init: POST: ',$_POST);
53
$q_config['url_info'] = qtranxf_detect_language($_SERVER['REQUEST_URI'], $host, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
54
- //qtranxf_dbg_log('qtranxf_init: url_info: ',$q_config['url_info']);
55
56
$q_config['language'] = $q_config['url_info']['language'];
57
$q_config['language'] = apply_filters('qtranslate_language', $q_config['language']);
58
59
- /*
60
- // Check for WP Secret Key Mismatch
61
- global $wp_default_secret_key;
62
- if(strpos($q_config['url_info']['url'],'wp-login.php')!==false && defined('AUTH_KEY') && isset($wp_default_secret_key) && $wp_default_secret_key != AUTH_KEY) {
63
- global $error;
64
- $error = __('Your $wp_default_secret_key is mismatchting with your AUTH_KEY. This might cause you not to be able to login anymore.', 'qtranslate');
65
- }
66
- */
67
-
68
// Filter all options for language tags
69
if(!defined('WP_ADMIN')) {
70
$alloptions = wp_load_alloptions();
@@ -73,15 +55,12 @@ function qtranxf_init() {
73
}
74
}
75
76
- // load plugin translations
77
- load_plugin_textdomain('qtranslate', false, dirname(plugin_basename( __FILE__ )).'/lang');
78
-
79
// remove traces of language (or better not?)
80
//unset($_GET['lang']);
81
- //qtranxf_dbg_log('qtranxf_init: REQUEST_URI='.$_SERVER['REQUEST_URI']);
82
//$_SERVER['REQUEST_URI'] = $q_config['url_info']['url'];
83
//$_SERVER['HTTP_HOST'] = $q_config['url_info']['host'];
84
- //qtranxf_dbg_log('qtranxf_init: REQUEST_URI='.$_SERVER['REQUEST_URI']);
85
86
// fix url to prevent xss
87
$q_config['url_info']['url'] = qtranxf_convertURL(add_query_arg('lang',$q_config['default_language'],$q_config['url_info']['url']));
@@ -90,19 +69,11 @@ function qtranxf_init() {
90
require_once(dirname(__FILE__)."/qtranslate_compatibility.php");
91
}
92
93
- //allow other plugins to initialize whatever they need
94
- do_action('qtranxf_init');
95
96
- /*
97
- //"WordPress SEO" plugin support - not yet
98
- //if(is_plugin_active( 'wordpress-seo/wp-seo.php' )){//in admin only
99
- if ( defined( 'WPSEO_FILE' ) ) {
100
- //add_filter('wpseo_replacements', 'qtranxf_wpseo_replacements', 0);
101
- add_filter('wpseo_replacements', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0);
102
- }
103
- */
104
- //qtranxf_dbg_log('qtranxf_init: url_info.url='.$q_config['url_info']['url']);
105
- //qtranxf_dbg_log('qtranxf_init: language='.$q_config['language']);
106
}
107
108
function qtranxf_resolveLangCase($lang,&$caseredirect)
@@ -344,6 +315,48 @@ function qtranxf_http_negotiate_language(){
344
return $lang;
345
}
346
347
function qtranxf_validateBool($var, $default) {
348
if($var==='0') return false; elseif($var==='1') return true; else return $default;
349
}
@@ -468,9 +481,6 @@ function qtranxf_loadConfig() {
468
$q_config['url_mode'] = $url_mode;
469
$q_config['term_name'] = $term_name;
470
471
- foreach($q_config['text_field_filters'] as $nm){
472
- add_filter($nm, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
473
- }
474
do_action('qtranslate_loadConfig');
475
}
476
22
23
/* qTranslate Functions */
24
25
+ function qtranxf_init_language() {
26
global $q_config;
27
// check if it isn't already initialized
28
+ if(defined('QTRANX_INIT')){ echo "qtranxf_init_language second time"; return; }
29
define('QTRANX_INIT',true);
30
31
qtranxf_loadConfig();
32
33
+ $cookie_name = defined('WP_ADMIN') ? QTX_COOKIE_NAME_ADMIN : QTX_COOKIE_NAME_FRONT;
34
+ $q_config['cookie_enabled']=isset($_COOKIE[$cookie_name]);
35
36
$host=$_SERVER['HTTP_HOST'];
37
//on different port, it will not work for now
38
//if(isset($_SERVER['SERVER_PORT']) && !empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT']!='80'){
39
// $host.=':'.$_SERVER['SERVER_PORT'];
40
//}
41
+ //qtranxf_dbg_log('qtranxf_init_language: IP='.$_SERVER['REMOTE_ADDR']);
42
+ //qtranxf_dbg_log('qtranxf_init_language: URL='.$host.$_SERVER['REQUEST_URI']);
43
+ //qtranxf_dbg_log('qtranxf_init_language: POST: ',$_POST);
44
$q_config['url_info'] = qtranxf_detect_language($_SERVER['REQUEST_URI'], $host, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
45
+ //qtranxf_dbg_log('qtranxf_init_language: url_info: ',$q_config['url_info']);
46
47
$q_config['language'] = $q_config['url_info']['language'];
48
$q_config['language'] = apply_filters('qtranslate_language', $q_config['language']);
49
50
// Filter all options for language tags
51
if(!defined('WP_ADMIN')) {
52
$alloptions = wp_load_alloptions();
55
}
56
}
57
58
// remove traces of language (or better not?)
59
//unset($_GET['lang']);
60
+ //qtranxf_dbg_log('qtranxf_init_language: REQUEST_URI='.$_SERVER['REQUEST_URI']);
61
//$_SERVER['REQUEST_URI'] = $q_config['url_info']['url'];
62
//$_SERVER['HTTP_HOST'] = $q_config['url_info']['host'];
63
+ //qtranxf_dbg_log('qtranxf_init_language: REQUEST_URI='.$_SERVER['REQUEST_URI']);
64
65
// fix url to prevent xss
66
$q_config['url_info']['url'] = qtranxf_convertURL(add_query_arg('lang',$q_config['default_language'],$q_config['url_info']['url']));
69
require_once(dirname(__FILE__)."/qtranslate_compatibility.php");
70
}
71
72
+ //allow other plugins to initialize whatever they need for language
73
+ do_action('qtranxf_init_language');
74
75
+ //qtranxf_dbg_log('qtranxf_init_language: url_info.url='.$q_config['url_info']['url']);
76
+ //qtranxf_dbg_log('qtranxf_init_language: language='.$q_config['language']);
77
}
78
79
function qtranxf_resolveLangCase($lang,&$caseredirect)
315
return $lang;
316
}
317
318
+ function qtranxf_init() {
319
+ global $q_config;
320
+
321
+ do_action('qtranxf_init_begin');
322
+
323
+ if(defined('WP_ADMIN')){
324
+ // update Gettext Databases if on Backend
325
+ if($q_config['auto_update_mo']) qtranxf_updateGettextDatabases();
326
+ // update definitions if neccesary
327
+ if(current_user_can('manage_categories')) qtranxf_updateTermLibrary();
328
+ }
329
+ /*
330
+ // Check for WP Secret Key Mismatch
331
+ global $wp_default_secret_key;
332
+ if(strpos($q_config['url_info']['url'],'wp-login.php')!==false && defined('AUTH_KEY') && isset($wp_default_secret_key) && $wp_default_secret_key != AUTH_KEY) {
333
+ global $error;
334
+ $error = __('Your $wp_default_secret_key is mismatchting with your AUTH_KEY. This might cause you not to be able to login anymore.', 'qtranslate');
335
+ }
336
+ */
337
+
338
+ // load plugin translations
339
+ load_plugin_textdomain('qtranslate', false, dirname(plugin_basename( __FILE__ )).'/lang');
340
+
341
+ if($q_config['qtrans_compatibility']){
342
+ require_once(dirname(__FILE__)."/qtranslate_compatibility.php");
343
+ }
344
+
345
+ foreach($q_config['text_field_filters'] as $nm){
346
+ add_filter($nm, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
347
+ }
348
+ /*
349
+ //"WordPress SEO" plugin support - not yet
350
+ //if(is_plugin_active( 'wordpress-seo/wp-seo.php' )){//in admin only
351
+ if ( defined( 'WPSEO_FILE' ) ) {
352
+ //add_filter('wpseo_replacements', 'qtranxf_wpseo_replacements', 0);
353
+ add_filter('wpseo_replacements', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0);
354
+ }
355
+ */
356
+ //allow other plugins to initialize whatever they need for qTranslate
357
+ do_action('qtranxf_init');
358
+ }
359
+
360
function qtranxf_validateBool($var, $default) {
361
if($var==='0') return false; elseif($var==='1') return true; else return $default;
362
}
481
$q_config['url_mode'] = $url_mode;
482
$q_config['term_name'] = $term_name;
483
484
do_action('qtranslate_loadConfig');
485
}
486
qtranslate_frontend.php CHANGED
@@ -73,40 +73,60 @@ function qtranxf_get_nav_menu_items( $items, $menu, $args )
73
$qtransmenu=null;
74
$altlang=null;
75
$url='';//it will keep the same page
76
- $tp='LM';
77
- $flags=true;
78
foreach($items as $item)
79
{
80
if($itemid<$item->ID) $itemid=$item->ID;
81
if($menu_order<$item->menu_order) $menu_order=$item->menu_order;
82
- if( !isset( $item->url ) || strstr( $item->url, '#qtransLangSw' ) === FALSE ) continue;
83
- $qs=explode('?',$item->url);
84
- if(count($qs)>1){
85
- $pars=explode('&',$qs[1]);
86
- foreach($pars as $par){
87
- $ps=explode('=',$par);
88
- switch($ps[0]){
89
- case 'flags': $flags=($ps[1]!='no'); break;
90
- case 'type': $tp=$ps[1]; break;
91
- }
92
}
93
}
94
- if($tp=='AL'){
95
foreach($q_config['enabled_languages'] as $lang){
96
if($lang==$language) continue;
97
$toplang=$lang;
98
$altlang=$lang;
99
break;
100
}
101
- $item->title=$q_config['language_name'][$toplang];
102
$item->url=qtranxf_convertURL($url, $altlang, false, true);
103
}else{
104
$toplang=$language;
105
- $item->title=__('Language','qtranslate');
106
$item->url=null;
107
}
108
- if($flags){
109
- $item->title.=':&nbsp;<img src="'.$flag_location.$q_config['flag'][$toplang].'">';
110
}
111
//$item->classes[] = 'qtranxs_flag_'.$language;
112
$item->classes[] = 'qtranxs-lang-menu';
@@ -115,9 +135,11 @@ function qtranxf_get_nav_menu_items( $items, $menu, $args )
115
if(!$qtransmenu) return $items;
116
foreach($q_config['enabled_languages'] as $lang)
117
{
118
- if($tp=='AL'){
119
if($lang==$language) continue;
120
if($lang==$altlang ) continue;
121
}
122
$item=new WP_Post((object)array('ID' => ++$itemid));
123
//$item->db_id=$item->ID;
73
$qtransmenu=null;
74
$altlang=null;
75
$url='';//it will keep the same page
76
+ //options
77
+ $type='LM';//[LM|AL]
78
+ $title='Language';//[none|Language|Current]
79
+ $current=true;//[shown|hidden]
80
+ $flags=true;//[none|all|items]
81
+ $topflag=true;
82
foreach($items as $item)
83
{
84
if($itemid<$item->ID) $itemid=$item->ID;
85
if($menu_order<$item->menu_order) $menu_order=$item->menu_order;
86
+ if( !isset( $item->url ) || stristr( $item->url, 'qtransLangSw' ) === FALSE ) continue;
87
+ $p=strpos($item->url,'?');
88
+ if($p!==FALSE){
89
+ $qs=substr($item->url,$p+1);
90
+ $qs=str_replace('#','',$qs);
91
+ $pars=array(); parse_str($qs,$pars);
92
+ if(isset($pars['type']) && stripos($pars['type'],'AL')!==FALSE ) $type='AL';
93
+ if(isset($pars['flags'])){
94
+ $flags=(stripos($pars['flags'],'no')===FALSE);
95
+ if($flags) $topflag=(stripos($pars['flags'],'items')===FALSE);
96
+ else $topflag=false;
97
+ }
98
+ if(isset($pars['title'])){
99
+ $title=$pars['title'];
100
+ if(stripos($pars['title'],'no')!==FALSE) $title='';
101
+ if(!$topflag && empty($title)) $title='Language';
102
+ }
103
+ if(isset($pars['current'])){
104
+ $current=(stripos($pars['current'],'hid')===FALSE);
105
}
106
}
107
+ if($type=='AL'){
108
foreach($q_config['enabled_languages'] as $lang){
109
if($lang==$language) continue;
110
$toplang=$lang;
111
$altlang=$lang;
112
break;
113
}
114
+ $item->title=empty($title)?'':$q_config['language_name'][$toplang];
115
$item->url=qtranxf_convertURL($url, $altlang, false, true);
116
}else{
117
$toplang=$language;
118
+ if(empty($title)){
119
+ $item->title='';
120
+ }elseif(stripos($title,'Current')!==FALSE){
121
+ $item->title=$q_config['language_name'][$toplang];
122
+ }else{
123
+ $item->title=__('Language','qtranslate');
124
+ }
125
$item->url=null;
126
}
127
+ if($topflag){
128
+ if(!empty($item->title)) $item->title.=':&nbsp;';
129
+ $item->title.='<img src="'.$flag_location.$q_config['flag'][$toplang].'">';
130
}
131
//$item->classes[] = 'qtranxs_flag_'.$language;
132
$item->classes[] = 'qtranxs-lang-menu';
135
if(!$qtransmenu) return $items;
136
foreach($q_config['enabled_languages'] as $lang)
137
{
138
+ if($type=='AL'){
139
if($lang==$language) continue;
140
if($lang==$altlang ) continue;
141
+ }elseif(!$current){
142
+ if($lang==$language) continue;
143
}
144
$item=new WP_Post((object)array('ID' => ++$itemid));
145
//$item->db_id=$item->ID;
qtranslate_hooks.php CHANGED
@@ -201,8 +201,9 @@ function qtranxf_gettext_with_context($translated_text) {
201
// add_action('category_add_form', 'qtranxf_modifyTermFormFor');
202
// add_action('post_tag_add_form', 'qtranxf_modifyTermFormFor');
203
// add_action('link_category_add_form', 'qtranxf_modifyTermFormFor');
204
add_action('widgets_init', 'qtranxf_widget_init');
205
- add_action('plugins_loaded', 'qtranxf_init', 2);
206
207
// Hooks (execution time critical filters)
208
add_filter('gettext', 'qtranxf_gettext',0);
201
// add_action('category_add_form', 'qtranxf_modifyTermFormFor');
202
// add_action('post_tag_add_form', 'qtranxf_modifyTermFormFor');
203
// add_action('link_category_add_form', 'qtranxf_modifyTermFormFor');
204
+ add_action('plugins_loaded', 'qtranxf_init_language', 2);//user is not authenticated yet
205
+ add_action('init', 'qtranxf_init');//user is authenticated
206
add_action('widgets_init', 'qtranxf_widget_init');
207
208
// Hooks (execution time critical filters)
209
add_filter('gettext', 'qtranxf_gettext',0);
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: johnclause, chineseleper, Vavooon
4
Tags: multilingual, language, admin, tinymce, bilingual, widget, switcher, i18n, l10n, multilanguage, translation
5
Requires at least: 3.9
6
Tested up to: 4.1
7
- Stable tag: 2.9.2
8
License: GPLv3 or later
9
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QEXEK3HX8AR6U
10
License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -59,7 +59,7 @@ Installation of this plugin is no different from any other plugin:
59
60
Yes, some themes put additional text fields per page or per post. By default, those fields have no way to respond to language switching buttons in editors. However, you may enter "id" or "class" name attribute of those fields into "Custom Fields" section of "Languages" configuration page in "Settings", and they will then respond to the language switching buttons allowing you to enter different text for each language. To lookup "id" or "class", right-click on the field in the post or the page editor, choose "Inspect Element", and look for which attributes are defined for that field. If you cannot uniquely distinct the field neither by if nor by class, report on the forum threads.
61
62
- The theme must pass those values through [translation](http://codex.wordpress.org/Function_Reference/_2) function '__()' before displaying on the front-end output. If this is not done, you will see the text of all languages displayed one after another. Most themes use '__()' translation by default, otherwise you may ask theme author to make this little modification for each field you need to be translatable. However, sometimes, they pass a value through 'apply_filters()' function before displaying the value, and then you may put that filter name into configuration filed "Custom Filters" to get the value translated properly.
63
64
The following fields are pre-configured to be translatable by default:
65
@@ -82,6 +82,32 @@ If a theme uses `__()` [translate](http://codex.wordpress.org/Function_Reference
82
83
The '`[:]`' syntax works well for one-line text fields, while '`<--:-->`' syntax is more suitable for text areas.
84
85
= What is wrong with the original qTranslate? =
86
87
qTranslate still works fine at frontend, except one known to me bug of incorrect date display in comments for some themes. However, its backend breaks tinyMCE content editor in post editing page. Many people have been reporting the problems, but the author keeps silence. qTranslate-X uses the same database backend, and updated admin interface with a slightly different design.
@@ -115,6 +141,11 @@ One can find the original qTranslate FAQ [here](https://wordpress.org/plugins/qt
115
116
== Changelog ==
117
118
= 2.9.2 =
119
* Option "Compatibility Functions" to enable former qTranslate function names: qtrans_getLanguage, qtrans_convertURL, qtrans_use, qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage, qtranxf_useTermLib and qtrans_getSortedLanguages
120
* "Language Switcher" menu options: flags=[yes|no], type=[LM|AL]. They can be used in a query string in URL field of Language Menu.
4
Tags: multilingual, language, admin, tinymce, bilingual, widget, switcher, i18n, l10n, multilanguage, translation
5
Requires at least: 3.9
6
Tested up to: 4.1
7
+ Stable tag: 2.9.3
8
License: GPLv3 or later
9
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QEXEK3HX8AR6U
10
License URI: http://www.gnu.org/licenses/gpl-3.0.html
59
60
Yes, some themes put additional text fields per page or per post. By default, those fields have no way to respond to language switching buttons in editors. However, you may enter "id" or "class" name attribute of those fields into "Custom Fields" section of "Languages" configuration page in "Settings", and they will then respond to the language switching buttons allowing you to enter different text for each language. To lookup "id" or "class", right-click on the field in the post or the page editor, choose "Inspect Element", and look for which attributes are defined for that field. If you cannot uniquely distinct the field neither by if nor by class, report on the forum threads.
61
62
+ The theme must pass those values through [translation](http://codex.wordpress.org/Function_Reference/_2) function `__()` before displaying on the front-end output. If this is not done, you will see the text of all languages displayed one after another. Most themes use `__()` translation by default, otherwise you may ask theme author to make this little modification for each field you need to be translatable. However, sometimes, they pass a value through 'apply_filters()' function before displaying the value, and then you may put that filter name into configuration filed "Custom Filters" to get the value translated properly.
63
64
The following fields are pre-configured to be translatable by default:
65
82
83
The '`[:]`' syntax works well for one-line text fields, while '`<--:-->`' syntax is more suitable for text areas.
84
85
+ = Can I change the look of Language Switcher Menu? =
86
+
87
+ The following query options can be typed in the field "URL" of "Language Menu" custom menu item, after "#qtransLangSw?", separated by "&", same way as options are provided on a query string:
88
+
89
+ - type=[LM|AL] - type of menu:
90
+ - "LM" - Language Menu (default).
91
+ - "AL" - Alternative Language: the top menu entry displays the first available language other than the current.
92
+
93
+ - title=[none|Language|Current] - title text of the top item:
94
+ - "Language" - word "Language" translated to current language (default).
95
+ - "none" - no title in the top of menu, flag only.
96
+ - "Current" - displays current language name.
97
+
98
+ - flags=[none|all|items] - the way to display language flags:
99
+ - "none" - no flag is shown in any item, including the top item.
100
+ - "all" - all items show flag, including the top item.
101
+ - "items" - only sub-items show corresponding flag, top item does not.
102
+
103
+ - current=[shown|hidden] - whether to display the current language in the menu.
104
+
105
+ We understand that this is not a very user-friendly way to adjust the options, but it works, and we will provide a better in-editor interface to specify them in the future.
106
+
107
+ = How do I customize images for flags? =
108
+
109
+ If you wish to use different flag images, point option "Flag Image Path" to your own folder, containing custom images outside of "plugins" or "themes" folders. Most people would put it somewhere under "uploads" folder.
110
+
111
= What is wrong with the original qTranslate? =
112
113
qTranslate still works fine at frontend, except one known to me bug of incorrect date display in comments for some themes. However, its backend breaks tinyMCE content editor in post editing page. Many people have been reporting the problems, but the author keeps silence. qTranslate-X uses the same database backend, and updated admin interface with a slightly different design.
141
142
== Changelog ==
143
144
+ = 2.9.3 =
145
+ * "Language Switcher" menu options, read [FAQ](https://wordpress.org/plugins/qtranslate-x/faq/) for more information.
146
+ * fix for too early call to `current_user_can`, which caused a debug notice from within some other plugins.
147
+ * fix for https://wordpress.org/support/topic/editor-adds-characters-before-text
148
+
149
= 2.9.2 =
150
* Option "Compatibility Functions" to enable former qTranslate function names: qtrans_getLanguage, qtrans_convertURL, qtrans_use, qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage, qtranxf_useTermLib and qtrans_getSortedLanguages
151
* "Language Switcher" menu options: flags=[yes|no], type=[LM|AL]. They can be used in a query string in URL field of Language Menu.