qTranslate X - Version 2.9.2

Version Description

  • Option "Compatibility Functions" to enable former qTranslate function names: qtrans_getLanguage, qtrans_convertURL, qtrans_use, qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage, qtranxf_useTermLib and qtrans_getSortedLanguages
  • "Language Switcher" menu options: flags=[yes|no], type=[LM|AL]. They can be used in a query string in URL field of Language Menu.
Download this release

Release Info

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

Code changes from version 2.7.8 to 2.9.2

admin/import_export.php CHANGED
@@ -102,8 +102,8 @@ function qtranxf_admin_section_import_export($request_uri)
102
<tr valign="top" id="qtranslate-convert-database">
103
<th scope="row"><?php _e('Convert Database', 'qtranslate');?></th>
104
<td>
105
- <?php printf(__('If you are updating from qTranslate 1.x or Polyglot, <a href="%s">click here</a> to convert posts to the new language tag format.', 'qtranslate'), $clean_uri.'&convert=true'); ?>
106
- <?php printf(__('If you have installed qTranslate for the first time on a Wordpress with existing posts, you can either go through all your posts manually and save them in the correct language or <a href="%s">click here</a> to mark all existing posts as written in the default language.', 'qtranslate'), $clean_uri.'&markdefault=true'); ?>
107
<?php _e('Both processes are <b>irreversible</b>! Be sure to make a full database backup before clicking one of the links.', 'qtranslate'); ?>
108
</td>
109
</tr>
@@ -120,7 +120,7 @@ function qtranxf_admin_section_import_export($request_uri)
120
<br/>
121
<label for="qtranslate_reset3"><input type="checkbox" name="qtranslate_reset3" id="qtranslate_reset3" value="1"/> <?php _e('Also delete Translations for Categories/Tags/Link Categories.', 'qtranslate'); ?></label>
122
<br/>
123
- <?php _e('If something isn\'t working correctly, you can always try to reset all qTranslate settings. A Reset won\'t delete any posts but will remove all settings (including all languages added).', 'qtranslate'); ?>
124
</td>
125
</tr>
126
</table>
102
<tr valign="top" id="qtranslate-convert-database">
103
<th scope="row"><?php _e('Convert Database', 'qtranslate');?></th>
104
<td>
105
+ <?php printf(__('If you are updating from qTranslate 1.x or Polyglot, <a href="%s">click here</a> to convert posts to the new language tag format.', 'qtranslate'), $request_uri.'&convert=true'); ?>
106
+ <?php printf(__('If you have installed qTranslate for the first time on a Wordpress with existing posts, you can either go through all your posts manually and save them in the correct language or <a href="%s">click here</a> to mark all existing posts as written in the default language.', 'qtranslate'), $request_uri.'&markdefault=true'); ?>
107
<?php _e('Both processes are <b>irreversible</b>! Be sure to make a full database backup before clicking one of the links.', 'qtranslate'); ?>
108
</td>
109
</tr>
120
<br/>
121
<label for="qtranslate_reset3"><input type="checkbox" name="qtranslate_reset3" id="qtranslate_reset3" value="1"/> <?php _e('Also delete Translations for Categories/Tags/Link Categories.', 'qtranslate'); ?></label>
122
<br/>
123
+ <small><?php _e('If something isn\'t working correctly, you can always try to reset all qTranslate settings. A Reset won\'t delete any posts but will remove all settings (including all languages added).', 'qtranslate'); ?></small>
124
</td>
125
</tr>
126
</table>
admin/xhaleera_addons.php ADDED
@@ -0,0 +1,356 @@
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
+ ?>
lang/qtranslate-sr_RS.mo ADDED
Binary file
qtranslate.css CHANGED
@@ -72,37 +72,5 @@
72
vertical-align: middle;
73
}
74
75
-
76
- /* qTranslate-X widget */
77
-
78
- .top-widget
79
- {
80
- width: auto;
81
- }
82
- .qtranxs-widget ul li
83
- {
84
- display: inline;
85
- list-style-type: none;
86
- opacity: 0.5;
87
- -o-transition: 1s ease opacity;
88
- -moz-transition: 1s ease opacity;
89
- -webkit-transition: 1s ease opacity;
90
- transition: 1s ease opacity;
91
- }
92
- .qtranxs-widget ul
93
- {
94
- margin: 0;
95
- }
96
- .qtranxs-widget ul li.active
97
- {
98
- opacity: 0.8;
99
- }
100
- .qtranxs-widget ul li:hover
101
- {
102
- opacity: 1;
103
- }
104
- .qtranxs-widget img
105
- {
106
- box-shadow: none;
107
- vertical-align: middle;
108
- }
72
vertical-align: middle;
73
}
74
75
+ /* not sure what this for */
76
+ .top-widget { width: auto; }
qtranslate.js ADDED
@@ -0,0 +1,726 @@
1
+ /* this is the developer version of qtranslate.min.js before it is minimized */
2
+ /*
3
+ //debuging tools, do not check in
4
+ var cc=0;
5
+ function c(v){ ++cc; console.log('== '+cc+': '+v); }
6
+ function ct(v){ c(v); console.trace(); }
7
+ */
8
+
9
+ qtranxj_split = function(text)
10
+ {
11
+ var result = new Object;
12
+ for(var i=0; i<qTranslateConfig.enabled_languages.length; ++i)
13
+ {
14
+ var lang=qTranslateConfig.enabled_languages[i];
15
+ result[lang] = '';
16
+ }
17
+ var split_regex_c = /<!--:-->/gi;
18
+ var blocks = text.xsplit(split_regex_c);
19
+ //c('qtranxj_split: blocks='+blocks);
20
+ //c('qtranxj_split: blocks.length='+blocks.length);
21
+ if(!qtranxj_isArray(blocks))
22
+ return result;
23
+ var matches, lang_regex, lang;
24
+ if(blocks.length>1){//there are matches
25
+ lang_regex = /<!--:([a-z]{2})-->/gi;
26
+ for(var i = 0;i<blocks.length;++i){
27
+ var b=blocks[i];
28
+ //c('blocks['+i+']='+b);
29
+ if(!b.length) continue;
30
+ matches = lang_regex.exec(b); lang_regex.lastIndex=0;
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;
39
+ blocks = text.xsplit(split_regex_b);
40
+ if(!qtranxj_isArray(blocks))
41
+ return result;
42
+ if(blocks.length==1){//no language separator found, enter it to all languages
43
+ var b=blocks[0];
44
+ for(var j=0; j<qTranslateConfig.enabled_languages.length; ++j){
45
+ var lang=qTranslateConfig.enabled_languages[j];
46
+ result[lang] += b;
47
+ }
48
+ }else{
49
+ lang_regex = /\[:([a-z]{2})\]/gi;
50
+ lang = false;
51
+ for(var i = 0;i<blocks.length;++i){
52
+ var b=blocks[i];
53
+ //c('blocks['+i+']='+b+'; lang='+lang);
54
+ if(lang){
55
+ result[lang] += b;
56
+ lang = false;
57
+ }else{
58
+ matches = lang_regex.exec(b); lang_regex.lastIndex=0;
59
+ if(matches==null) continue;
60
+ lang = matches[1];
61
+ }
62
+ }
63
+ }
64
+ }
65
+ return result;
66
+ }
67
+
68
+ /*
69
+ qtranxj_split = function(text)
70
+ {
71
+ var result = new Object;
72
+ for(var i=0; i<qTranslateConfig.enabled_languages.length; ++i)
73
+ {
74
+ var lang=qTranslateConfig.enabled_languages[i];
75
+ result[lang] = '';
76
+ }
77
+ var split_regex_c = /(<!--.*?-->)/gi;
78
+ var blocks = text.xsplit(split_regex_c);
79
+ //c('qtranxj_split: blocks='+blocks);
80
+ if(!qtranxj_isArray(blocks))
81
+ return result;
82
+ var lang_begin_regex, lang_end_regex;
83
+ if(blocks.length>1){//there are matches, if the first block is empty
84
+ lang_begin_regex = /<!--:([a-z]{2})-->/gi;
85
+ lang_end_regex = /<!--:-->/gi;
86
+ }else{
87
+ var split_regex_b = /(\[:[a-z]{2}\])/gi;
88
+ blocks = text.xsplit(split_regex_b);
89
+ if(!qtranxj_isArray(blocks))
90
+ return result;
91
+ lang_begin_regex = /\[:([a-z]{2})\]/gi;
92
+ }
93
+ if(!blocks.length) return result;
94
+ if(blocks.length==1){//no language separator found, enter it to all languages
95
+ var b=blocks[0];
96
+ for(var j=0; j<qTranslateConfig.enabled_languages.length; j++){
97
+ var lang=qTranslateConfig.enabled_languages[j];
98
+ result[lang] += b;
99
+ }
100
+ }else{
101
+ var matches;
102
+ var lang = false;
103
+ for(var i = 0;i<blocks.length;++i){
104
+ var b=blocks[i];
105
+ //c('blocks['+i+']='+b);
106
+ if(!b.length) continue;
107
+ if ((matches = lang_begin_regex.exec(b)) != null){
108
+ lang = matches[1];
109
+ }else if(lang_end_regex && lang_end_regex.test(b)){
110
+ lang = false;
111
+ }else if(lang){
112
+ result[lang] += b;
113
+ lang = false;
114
+ }//else skip garbage which tinyMCE adds sometimes
115
+ }
116
+ }
117
+ var morenextpage_regex = /(<!--more-->|<!--nextpage-->)+#x2F;gi;
118
+ for(var i = 0;i<result.length;++i){
119
+ result[i] = result[i].replace(morenextpage_regex,'');
120
+ }
121
+ return result;
122
+ }
123
+ */
124
+ //"_c" stands for "comment"
125
+ qtranxj_join_c = function(texts)
126
+ {
127
+ var text = '';
128
+ for(var i=0; i<qTranslateConfig.enabled_languages.length; ++i)
129
+ {
130
+ var lang=qTranslateConfig.enabled_languages[i];
131
+ var t = texts[lang];
132
+ if ( !t || t=='' ) continue;
133
+ text += '<!--:'+lang+'-->';
134
+ text += t;
135
+ text += '<!--:-->';
136
+ }
137
+ return text;
138
+ }
139
+
140
+ //"b" stands for "bracket"
141
+ qtranxj_join_b = function(texts)
142
+ {
143
+ var text = '';
144
+ for(var i=0; i<qTranslateConfig.enabled_languages.length; ++i)
145
+ {
146
+ var lang=qTranslateConfig.enabled_languages[i];
147
+ var t = texts[lang];
148
+ if ( !t || t=='' ) continue;
149
+ text += '[:'+lang+']';
150
+ text += t;
151
+ }
152
+ return text;
153
+ }
154
+
155
+ function qtranxj_get_cookie(cname)
156
+ {
157
+ var nm = cname + "=";
158
+ var ca = document.cookie.split(';');
159
+ //c('ca='+ca);
160
+ for(var i=0; i<ca.length; ++i){
161
+ var s = ca[i];
162
+ var sa = s.split('=');
163
+ if(sa[0].trim()!=cname) continue;
164
+ if(ca.length<2) continue;
165
+ return sa[1].trim();
166
+ }
167
+ return '';
168
+ }
169
+
170
+ String.prototype.xsplit = function(_regEx){
171
+ // Most browsers can do this properly, so let them work, they'll do it faster
172
+ if ('a~b'.split(/(~)/).length === 3){ return this.split(_regEx); }
173
+
174
+ if (!_regEx.global)
175
+ { _regEx = new RegExp(_regEx.source, 'g' + (_regEx.ignoreCase ? 'i' : '')); }
176
+
177
+ // IE (and any other browser that can't capture the delimiter)
178
+ // will, unfortunately, have to be slowed down
179
+ var start = 0, arr=[];
180
+ var result;
181
+ while((result = _regEx.exec(this)) != null){
182
+ arr.push(this.slice(start, result.index));
183
+ if(result.length > 1) arr.push(result[1]);
184
+ start = _regEx.lastIndex;
185
+ }
186
+ if(start < this.length) arr.push(this.slice(start));
187
+ if(start == this.length) arr.push(''); //delim at the end
188
+ return arr;
189
+ };
190
+
191
+ function qtranxj_isArray(obj){ return obj.constructor.toString().indexOf('Array') >= 0; }
192
+
193
+ function qtranxj_ce(tagName, props, pNode, isFirst)
194
+ {
195
+ var el= document.createElement(tagName);
196
+ if (props)
197
+ {
198
+ for(prop in props)
199
+ {
200
+ //try
201
+ {
202
+ el[prop]=props[prop];
203
+ }
204
+ //catch(err)
205
+ {
206
+ //Handle errors here
207
+ }
208
+ }
209
+ }
210
+ if (pNode)
211
+ {
212
+ if (isFirst && pNode.firstChild)
213
+ {
214
+ pNode.insertBefore(el, pNode.firstChild);
215
+ }
216
+ else
217
+ {
218
+ pNode.appendChild(el);
219
+ }
220
+ }
221
+ return el;
222
+ }
223
+
224
+ var qTranslateX=function()
225
+ {
226
+ function ge(id){ return document.getElementById(id); }
227
+
228
+ var activeLanguage=qtranxj_get_cookie('wp_qtrans_edit_language');
229
+ if(!activeLanguage)
230
+ activeLanguage=qTranslateConfig.language;
231
+
232
+ var contentHooks={};
233
+ function updateFusedValueH(id,value)
234
+ {
235
+ var h=contentHooks[id];
236
+ var lang=languageSwitch.getActiveLanguage();
237
+ //var morenextpage_regex = /(<!--more-->|<!--nextpage-->)+#x2F;gi;
238
+ //h.contents[lang]=value.replace(morenextpage_regex,'');
239
+ h.contents[lang]=value;
240
+ if(h.separator==='<'){
241
+ h.mlContentField.value = qtranxj_join_c(h.contents);
242
+ }else{
243
+ h.mlContentField.value = qtranxj_join_b(h.contents);
244
+ }
245
+ //updateFusedValueC(h.mlContentField, value, h.contents, languageSwitch.getActiveLanguage());
246
+ }
247
+ function addContentHook(inpField,form,separator)
248
+ {
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='<';
257
+ else
258
+ separator='[';
259
+ }
260
+ h.separator=separator;
261
+ inpField.name+='_edit';
262
+ inpField.value=h.contents[activeLanguage];
263
+ //c('addContentHookC:inpField.value='+inpField.value);
264
+ inpField.onblur=function(){ updateFusedValueH(this.id,this.value); }
265
+ }
266
+ function addContentHookC(inpField,form)
267
+ {
268
+ addContentHook(inpField,form,'<');
269
+ }
270
+ function addContentHookB(inpField,form)
271
+ {
272
+ addContentHook(inpField,form,'[');
273
+ }
274
+ function tagEdit()
275
+ {
276
+ // Get fields
277
+ var isAjaxForm=!!ge('tag-name');
278
+ var prefix, formId;
279
+ if (isAjaxForm)
280
+ {
281
+ prefix='tag-';
282
+ formId='addtag';
283
+ }
284
+ else
285
+ {
286
+ prefix='';
287
+ formId='edittag';
288
+ }
289
+ var nameField=ge(prefix+'name');
290
+ var form=ge(formId);
291
+ if(!form || !nameField){
292
+ //alert('qTranslate-X cannot hook into the tag editor.\nPlease, report this incident to the developers.');
293
+ return false;
294
+ }
295
+
296
+ var adminLanguage=qTranslateConfig.language;
297
+
298
+ build_translator=function(langF,langT)
299
+ {
300
+ var translator={};
301
+ for(var key in qTranslateConfig.term_name){
302
+ var nms = qTranslateConfig.term_name[key];
303
+ var nmF=nms[langF];
304
+ var nmT=nms[langT];
305
+ if(!nmF || !nmT){
306
+ var nmD=nms[qTranslateConfig.default_language];
307
+ if(!nmD) continue;
308
+ if(!nmF) nmF=nmD+'('+qTranslateConfig.default_language+')';
309
+ if(!nmT) nmT=nmD+'('+qTranslateConfig.default_language+')';
310
+ }
311
+ translator[nmF]=nmT;
312
+ }
313
+ return translator;
314
+ }
315
+
316
+ var theList=ge('the-list');
317
+ hideQuickEdit=function()
318
+ {
319
+ if(!theList) return;
320
+ var rows=theList.getElementsByTagName('TR');
321
+ for(var r=0; r<rows.length; r++)
322
+ {
323
+ var tr=rows[r];
324
+ var td=tr.getElementsByTagName('TD')[0];
325
+ var items=td.getElementsByClassName('inline');
326
+ for(var i=0; i<items.length; ++i)
327
+ {
328
+ var e=items[i];
329
+ e.style.display='none';
330
+ }
331
+ }
332
+ }
333
+ hideQuickEdit();
334
+
335
+ //var nameFields={};
336
+ updateNames=function(langF,langT)
337
+ {
338
+ if(!theList) return;
339
+ var rows=theList.getElementsByTagName('TR');
340
+ for(var r=0; r<rows.length; r++)
341
+ {
342
+ var dnm, tr=rows[r];
343
+ var td=tr.getElementsByTagName('TD')[0];
344
+ var divs=td.getElementsByTagName('DIV');
345
+ for(var d=0; d<divs.length; d++)
346
+ {
347
+ var e=divs[d];
348
+ if(e.className!=='name')
349
+ continue;
350
+ dnm=e.innerHTML;
351
+ break;
352
+ }
353
+ if(adminLanguage!=qTranslateConfig.default_language){
354
+ var translator=build_translator(adminLanguage,qTranslateConfig.default_language);
355
+ dnm=translator[dnm];
356
+ }
357
+ var nms=qTranslateConfig.term_name[dnm]||{};
358
+ var nmF = nms[langF]||'';
359
+ var nmT = nms[langT]||'';
360
+ var items=td.getElementsByClassName('row-title');
361
+ for(var i=0; i<items.length; ++i)
362
+ {
363
+ var e=items[i];
364
+ if(nmF)
365
+ e.innerHTML = e.innerHTML.replace(nmF,nmT);
366
+ else
367
+ e.innerHTML += nmT;
368
+ }
369
+ }
370
+ }
371
+
372
+ var tagCloud=document.getElementsByClassName('tagcloud')[0];
373
+ updateTagCloud=function(langF,langT)
374
+ {
375
+ if(!tagCloud) return;
376
+ var items=tagCloud.getElementsByTagName('A');
377
+ if(!items.length) return;
378
+ var translator=build_translator(langF,langT);
379
+ for(var i=0; i<items.length; ++i)
380
+ {
381
+ var e=items[i];
382
+ var nmF=e.innerHTML;
383
+ var nmT=translator[nmF];
384
+ if(!nmT) continue;
385
+ e.innerHTML=nmT;
386
+ }
387
+ }
388
+
389
+ updateNamesAndTagCloud=function(langF,langT)
390
+ {
391
+ updateNames(langF,langT);
392
+ updateTagCloud(langF,langT);
393
+ }
394
+ if(adminLanguage!==activeLanguage)
395
+ updateNamesAndTagCloud(adminLanguage,activeLanguage);
396
+
397
+ // Swap fields
398
+ var newNameField=qtranxj_ce('input', {name: nameField.name, className: 'hidden', value: nameField.value}, form, true);
399
+ nameField.name='';
400
+
401
+ // Load text
402
+ var names = qTranslateConfig.term_name[nameField.value] || {};
403
+ if (activeLanguage !== qTranslateConfig.default_language){
404
+ nameField.value=names[activeLanguage] || '';
405
+ }
406
+
407
+ editinline_activated=function()
408
+ {
409
+ //c('editinline_activated:'+this.innerHTML);
410
+ return true;
411
+ }
412
+
413
+ var editinlines=document.getElementsByClassName('editinline');
414
+ //c('editinlines.length='+editinlines.length);
415
+ for(var i=0; i<editinlines.length; ++i)
416
+ {
417
+ var e=editinlines[i];
418
+ if(e.tagName!=='A') continue;
419
+ e.addEventListener( 'click', editinline_activated);
420
+ }
421
+
422
+ onTabSwitch=function()
423
+ {
424
+ if(activeLanguage === this.lang) return;
425
+ nameField.value=names[this.lang] || '';
426
+ updateNamesAndTagCloud(activeLanguage,this.lang);
427
+ activeLanguage = this.lang;
428
+ }
429
+
430
+ var langs=qTranslateConfig.enabled_languages;
431
+ var newNameFields={};
432
+ for(var i=0; i<langs.length; ++i)
433
+ {
434
+ var lang=langs[i];
435
+ newNameFields[lang]=qtranxj_ce('input', {name: 'qtranx_term_'+lang, className: 'hidden', value: name[lang] || ''}, form, true);
436
+ }
437
+ // Add listeners for fields change
438
+ nameField.onblur=function()
439
+ {
440
+ var lang=languageSwitch.getActiveLanguage();
441
+ newNameFields[lang].value=this.value;
442
+ names[lang]=this.value;
443
+ if (lang === qTranslateConfig.default_language)
444
+ {
445
+ newNameField.value=this.value;
446
+ }
447
+ };
448
+ return true;
449
+ }
450
+
451
+ function postEdit()
452
+ {
453
+ var form=ge('post');
454
+ if(!form) return false;
455
+
456
+ var titleField=ge('title');
457
+ if(titleField) addContentHookC(titleField,form);
458
+
459
+ var wpEditorAreas=form.getElementsByClassName('wp-editor-area');
460
+ for(var i=0; i<wpEditorAreas.length; ++i){
461
+ var wpEditorArea=wpEditorAreas[i];
462
+ addContentHookC(wpEditorArea,form);
463
+ }
464
+
465
+ var captionField=ge('attachment_caption');
466
+ if(captionField) addContentHookC(captionField,form);
467
+
468
+ //c('qTranslateConfig.custom_fields.length='+qTranslateConfig.custom_fields.length);
469
+ for(var i=0; i<qTranslateConfig.custom_fields.length; ++i){
470
+ var id=qTranslateConfig.custom_fields[i];
471
+ var sep;
472
+ if(id.indexOf('<')==0 || id.indexOf('[')==0){
473
+ sep=id.substring(0,1);
474
+ id=id.substring(1);
475
+ }
476
+ var f=ge(id);
477
+ addContentHook(f,form,sep);
478
+ }
479
+
480
+ for(var i=0; i<qTranslateConfig.custom_field_classes.length; ++i){
481
+ var nm=qTranslateConfig.custom_field_classes[i];
482
+ var sep;
483
+ if(nm.indexOf('<')==0 || nm.indexOf('[')==0){
484
+ sep=nm.substring(0,1);
485
+ nm=nm.substring(1);
486
+ }
487
+ var fields=form.getElementsByClassName(nm);
488
+ for(var j=0; j<fields.length; ++j){
489
+ f=fields[j];
490
+ addContentHook(f,form,sep);
491
+ }
492
+ }
493
+
494
+ var alttextField=ge('attachment_alt');
495
+ if(alttextField) addContentHookB(alttextField,form);
496
+
497
+ //var post_name_field=ge('post_name');
498
+ //if (post_name_field) addContentHookB(post_name_field,form);
499
+
500
+ // Slug
501
+ function convertURL(url,lang)
502
+ {
503
+ switch (qTranslateConfig.url_mode.toString())
504
+ {
505
+ case '1':
506
+ if (url.search){
507
+ url.search+="&lang="+lang;
508
+ }else{
509
+ url.search="?lang="+lang;
510
+ }
511
+ break;
512
+ case '2':
513
+ var homepath=qTranslateConfig.url_info_home;
514
+ var i=url.pathname.indexOf(homepath);
515
+ url.pathname=homepath+lang+url.pathname.substring(i+homepath.length-1);
516
+ break;
517
+ case '3':
518
+ url.host=lang+'.'+url.host;
519
+ break;
520
+ }
521
+ }
522
+
523
+ var btnViewPostA;//a node of 'View Page/Post' link.
524
+ var origUrl, langUrl;
525
+ var slugSamplePermalink;//'sample-permalink' node
526
+ var origSamplePermalink;
527
+ function setSlugLanguage(lang)
528
+ {
529
+ if(!btnViewPostA){
530
+ var btnViewPost=ge('view-post-btn');
531
+ if (!btnViewPost || !btnViewPost.children.length) return;
532
+ btnViewPostA=btnViewPost.children[0];
533
+ if(btnViewPostA.tagName != 'A') return;
534
+ origUrl=btnViewPostA.href;
535
+ langUrl=qtranxj_ce('a',{});
536
+ }
537
+
538
+ langUrl.href=origUrl;
539
+ convertURL(langUrl,lang);
540
+ btnViewPostA.href=langUrl.href;
541
+
542
+ var btnPreviewAction=ge('preview-action');
543
+ if (btnPreviewAction && btnPreviewAction.children.length)
544
+ {
545
+ btnPreviewAction.children[0].href=langUrl.href;
546
+ }
547
+
548
+ if(qTranslateConfig.url_mode!=1){//!QTX_URL_QUERY
549
+ if(!slugSamplePermalink){
550
+ var slugEl=ge('sample-permalink');
551
+ if (slugEl && slugEl.childNodes.length){
552
+ slugSamplePermalink=slugEl.childNodes[0];//span
553
+ origSamplePermalink=slugSamplePermalink.nodeValue;
554
+ //var slugEdit=ge('editable-post-name');
555
+ }
556
+ }
557
+ if(slugSamplePermalink){
558
+ langUrl.href=origSamplePermalink;
559
+ convertURL(langUrl,lang);
560
+ slugSamplePermalink.nodeValue=langUrl.href;
561
+ }
562
+ }
563
+ }
564
+ setSlugLanguage(activeLanguage);
565
+
566
+ onTabSwitch=function()
567
+ {
568
+ for(var key in contentHooks){
569
+ var h=contentHooks[key];
570
+ h.contentField.value=h.contents[this.lang];
571
+ }
572
+ if(alttextField){
573
+ alttextField.value=alttexts[this.lang];
574
+ }
575
+ setSlugLanguage(this.lang);
576
+ if (!window.tinyMCE) return;
577
+ for(var i=0; i<tinyMCE.editors.length; ++i){
578
+ var ed=tinyMCE.editors[i];
579
+ var h=contentHooks[ed.id];
580
+ if(!h) continue;
581
+ ed.setContent(h.contentField.value);//, {format: 'raw'}
582
+ }
583
+ }
584
+
585
+ function setEditorHooks(e)
586
+ {
587
+ //window.onbeforeunload = function(){};
588
+ var id = e.id;
589
+ //c('setEditorHooks: id='+id);
590
+ if (!id) return;
591
+ var h=contentHooks[id];
592
+ if(h.mce) return;
593
+ h.mce=e;
594
+ e.getBody().addEventListener('blur',function(){ updateFusedValueH(e.id, e.getContent());});
595
+ //c('h.contentField.value='+h.contentField.value);
596
+ //e.setContent(h.contentField.value);
597
+ }
598
+
599
+ // Add listeners for fields change
600
+ window.addEventListener('load', function(){
601
+ if (!window.tinyMCE){
602
+ //alert('qTranslate-X error: !window.tinyMCE. Please report this incident to the developers.');
603
+ return;
604
+ }
605
+ for(var i=0; i<tinyMCE.editors.length; ++i){
606
+ var ed=tinyMCE.editors[i];
607
+ setEditorHooks(ed);
608
+ }
609
+ for(var key in contentHooks){
610
+ var h=contentHooks[key];
611
+ if(h.mce) continue;
612
+ if(h.contentField.tagName!=='TEXTAREA') continue;
613
+ tinyMCEPreInit.mceInit[key].init_instance_callback=function(ed){ setEditorHooks(ed); }
614
+ }
615
+ });
616
+ return true;
617
+ }
618
+
619
+ function optionsEdit()
620
+ {
621
+ var forms=document.getElementsByTagName('FORM');
622
+ if(!forms.length) return false;
623
+ var form=forms[0];
624
+
625
+ addContentHookB(ge('blogname'),form);
626
+ addContentHookB(ge('blogdescription'),form);
627
+
628
+ onTabSwitch=function()
629
+ {
630
+ for(var key in contentHooks){
631
+ var h=contentHooks[key];
632
+ h.contentField.value=h.contents[this.lang];
633
+ }
634
+ }
635
+
636
+ return true;
637
+ }
638
+
639
+ setLangCookie=function()
640
+ {
641
+ document.cookie='wp_qtrans_edit_language='+this.lang;
642
+ }
643
+
644
+ var matches = location.pathname.match(/(\/wp-admin\/([^\/]*))#x2F;);
645
+ switch(matches && matches[1])
646
+ {
647
+ case "/wp-admin/post.php":
648
+ case "/wp-admin/post-new.php":
649
+ if(!postEdit()) return;
650
+ break;
651
+ case "/wp-admin/edit-tags.php":
652
+ if(!tagEdit()) return;
653
+ break;
654
+ case "/wp-admin/options-general.php":
655
+ if(location.search.indexOf('page=')>=0) return;
656
+ if(!optionsEdit()) return;
657
+ break;
658
+ default: return;
659
+ }
660
+
661
+ var langSwitchWrap=qtranxj_ce('ul', {className: 'qtranxs-lang-switch-wrap'});
662
+ {
663
+ //var header=w.getElementsByTagName('h2')[0];
664
+ //header.parentNode.insertBefore(langSwitchWrap, header.nextElementSibling);
665
+ var w=document.getElementsByClassName('wrap')[0];
666
+ var f=w.getElementsByTagName('form')[0];
667
+ f.parentNode.insertBefore(langSwitchWrap, f);
668
+ languageSwitch=new LanguageSwitch(langSwitchWrap,activeLanguage);
669
+ languageSwitch.onSwitch(onTabSwitch);
670
+ languageSwitch.onSwitch(setLangCookie);
671
+ }
672
+ }
673
+
674
+ function LanguageSwitch(target,initial_language)
675
+ {
676
+ var langs=qTranslateConfig.enabled_languages, langNames=qTranslateConfig.language_name, activeLanguage=initial_language;
677
+ var tabSwitches={};
678
+ var onTabSwitch=[];
679
+ function switchTab()
680
+ {
681
+ var tabSwitch=this;
682
+ if (!tabSwitch.lang){
683
+ alert('qTranslate-X: This should not have happened: Please, report this incident to the developers: !tabSwitch.lang');
684
+ return;
685
+ }
686
+ if ( activeLanguage === tabSwitch.lang ){
687
+ return;
688
+ }
689
+ if (activeLanguage)
690
+ {
691
+ tabSwitches[activeLanguage].classList.remove('active');
692
+ }
693
+ activeLanguage=tabSwitch.lang;
694
+ tabSwitch.classList.add('active');
695
+ for(var i=0; i<onTabSwitch.length; ++i)
696
+ {
697
+ onTabSwitch[i].call(this);
698
+ }
699
+ }
700
+ location.pathname.indexOf();
701
+ for(var i=0; i<langs.length; ++i)
702
+ {
703
+ //var flags_location=qTranslateConfig.WP_CONTENT_URL+qTranslateConfig.flag_location;
704
+ var flag_location=qTranslateConfig.flag_location;
705
+ var lang=langs[i];
706
+ var tabSwitch=qtranxj_ce ('li', {lang: lang, className: 'qtranxs-lang-switch', onclick: switchTab }, target );
707
+ qtranxj_ce('img', {src: flag_location+qTranslateConfig.flag[lang]}, tabSwitch);
708
+ qtranxj_ce('span', {innerHTML: langNames[lang]}, tabSwitch);
709
+ tabSwitches[lang]=tabSwitch;
710
+ if ( activeLanguage == lang )
711
+ tabSwitch.classList.add('active');
712
+ }
713
+ this.getActiveLanguage=function()
714
+ {
715
+ return activeLanguage;
716
+ }
717
+ this.onSwitch=function(callback)
718
+ {
719
+ if (typeof callback==='function')
720
+ {
721
+ onTabSwitch.push(callback);
722
+ }
723
+ }
724
+ }
725
+
726
+ new qTranslateX;
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<o.length;n++)o[n].call(this)}}var t=qTranslateConfig.enabled_languages,r=qTranslateConfig.language_name,i=n,l={},o=[];location.pathname.indexOf();for(var s=0;s<t.length;s++){var g=qTranslateConfig.WP_CONTENT_URL+qTranslateConfig.flag_location,u=t[s],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&&o.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,o;if(i.length>1)l=/<!--:([a-z]{2})-->/gi,o=/<!--:-->/gi;else{var s=/(\[:[a-z]{2}\])/gi;if(i=e.xsplit(s),!qtranxj_isArray(i))return n;l=/\[:([a-z]{2})\]/gi}if(!i.length)return n;if(1==i.length)for(var g=i[0],u=0;u<qTranslateConfig.enabled_languages.length;u++){var t=qTranslateConfig.enabled_languages[u];n[t]+=g}else for(var c,t=!1,a=0;a<i.length;a++){var g=i[a];g.length&&(null!=(c=l.exec(g))?t=c[1]:o&&o.test(g)?t=!1:t&&(n[t]+=g,t=!1))}for(var f=/(<!--more-->|<!--nextpage-->)+#x2F;gi,a=0;a<n.length;a++)n[a]=n[a].replace(f,"");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(),r=/(<!--more-->|<!--nextpage-->)+#x2F;gi;a.contents[t]=n.replace(r,""),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[s],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 o=r[qTranslateConfig.default_language];if(!o)continue;i||(i=o+"("+qTranslateConfig.default_language+")"),l||(l=o+"("+qTranslateConfig.default_language+")")}a[i]=l}return a};var o=e("the-list");hideQuickEdit=function(){if(o)for(var e=o.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(o)for(var a=o.getElementsByTagName("TR"),t=0;t<a.length;t++){for(var r,i=a[t],s=i.getElementsByTagName("TD")[0],g=s.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=s.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,o=t[l];o&&(i.innerHTML=o)}}},updateNamesAndTagCloud=function(e,n){updateNames(e,n),updateTagCloud(e,n)},l!==s&&updateNamesAndTagCloud(l,s);var u=qtranxj_ce("input",{name:r.name,className:"hidden",value:r.value},i,!0);r.name="";var c=qTranslateConfig.term_name[r.value]||{};s!==qTranslateConfig.default_language&&(r.value=c[s]||""),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(){s!==this.lang&&(r.value=c[this.lang]||"",updateNamesAndTagCloud(s,this.lang),s=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=e.pathname.indexOf(qTranslateConfig.url_info.home);e.pathname=qTranslateConfig.url_info.home+n+e.pathname.substring(a+qTranslateConfig.url_info.home.length-1);break;case"3":e.host=n+"."+e.host}}function l(n){if(!C){var a=e("view-post-btn");if(!a||!a.children.length)return;if(C=a.children[0],"A"!=C.tagName)return;q=C.href,w=qtranxj_ce("a",{})}w.href=q,i(w,n),C.href=w.href;var t=e("preview-action");if(t&&t.children.length&&(t.children[0].href=w.href),1!=qTranslateConfig.url_mode){if(!x){var r=e("sample-permalink");r&&r.childNodes.length&&(x=r.childNodes[0],b=x.nodeValue)}x&&(w.href=b,i(w,n),x.nodeValue=w.href)}}function o(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)}var T=e("attachment_alt");T&&r(T,u);var C,q,w,x,b;return l(s),onTabSwitch=function(){for(var e in g){var n=g[e];n.contentField.value=n.contents[this.lang]}if(T&&(T.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];o(n)}for(var a in g){var t=g[a];t.mce||"TEXTAREA"===t.contentField.tagName&&(tinyMCEPreInit.mceInit[a].init_instance_callback=function(e){o(e)})}}}),!0}function o(){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 s=qtranxj_get_cookie("qtrans_edit_language");s||(s=qTranslateConfig.language);var g={};setLangCookie=function(){document.cookie="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(!o())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,s),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],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;
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.7.8
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
@@ -111,6 +111,7 @@ define('QTX_INTEGER', 3);
111
define('QTX_URL', 4);
112
define('QTX_LANGUAGE', 5);
113
define('QTX_ARRAY', 6);
114
115
define('QTX_URL_QUERY', 1);
116
define('QTX_URL_PATH', 2);
@@ -121,6 +122,11 @@ define('QTX_DATE_OVERRIDE', 2);
121
define('QTX_DATE', 3);
122
define('QTX_STRFTIME', 4);
123
124
$q_config = array();
125
126
// enable the use of following languages (order=>language)
@@ -132,12 +138,14 @@ $q_config['enabled_languages'] = array(
132
133
// sets default language
134
$q_config['default_language'] = 'en';
135
136
// enables browser language detection
137
$q_config['detect_browser_language'] = true;
138
139
// hide pages without content
140
$q_config['hide_untranslated'] = false;
141
142
// automatically update .mo files
143
$q_config['auto_update_mo'] = true;
@@ -145,6 +153,9 @@ $q_config['auto_update_mo'] = true;
145
// hide language tag for default language
146
$q_config['hide_default_language'] = true;
147
148
// sets default url mode
149
// QTX_URL_QUERY(1) - query (questionmark)
150
// QTX_URL_PATH(2) - pre-path
@@ -310,11 +321,14 @@ $q_config['flag']['tr'] = 'tr.png';
310
$q_config['flag_location'] = 'plugins/qtranslate-x/flags/';
311
312
// Don't convert URLs to this file types
313
- $q_config['ignore_file_types'] = 'gif,jpg,jpeg,png,pdf,swf,tif,rar,zip,7z,mpg,divx,mpeg,avi,css,js';
314
315
/* DEFAULT CONFIGURATION PART ENDS HERE */
316
317
- $q_config['term_name'] = array();
318
319
// Full country names as locales for Windows systems
320
$q_config['windows_locale']['aa'] = "Afar";
@@ -500,4 +514,19 @@ if(is_admin()){
500
501
// set hooks at the end
502
require_once(dirname(__FILE__)."/qtranslate_hooks.php");
503
?>
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
111
define('QTX_URL', 4);
112
define('QTX_LANGUAGE', 5);
113
define('QTX_ARRAY', 6);
114
+ //define('QTX_ARRAY_STRING', 7);
115
116
define('QTX_URL_QUERY', 1);
117
define('QTX_URL_PATH', 2);
122
define('QTX_DATE', 3);
123
define('QTX_STRFTIME', 4);
124
125
+ define('QTX_COOKIE_NAME_FRONT','wp_qtrans_front_language');
126
+ define('QTX_COOKIE_NAME_ADMIN','wp_qtrans_admin_language');
127
+
128
+ define('QTX_IGNORE_FILE_TYPES','gif,jpg,jpeg,png,pdf,swf,tif,rar,zip,7z,mpg,divx,mpeg,avi,css,js');
129
+
130
$q_config = array();
131
132
// enable the use of following languages (order=>language)
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;
145
146
// hide pages without content
147
$q_config['hide_untranslated'] = false;
148
+ $q_config['show_displayed_language_prefix'] = true;
149
150
// automatically update .mo files
151
$q_config['auto_update_mo'] = true;
153
// hide language tag for default language
154
$q_config['hide_default_language'] = true;
155
156
+ //enables compatibility with former qtrans_* functions
157
+ $q_config['qtrans_compatibility'] = false;
158
+
159
// sets default url mode
160
// QTX_URL_QUERY(1) - query (questionmark)
161
// QTX_URL_PATH(2) - pre-path
321
$q_config['flag_location'] = 'plugins/qtranslate-x/flags/';
322
323
// Don't convert URLs to this file types
324
+ //$q_config['ignore_file_types'] = explode(',',QTX_IGNORE_FILE_TYPES);
325
+ $q_config['custom_fields'] = array();
326
+ $q_config['custom_field_classes'] = array();
327
+ $q_config['text_field_filters'] = array();
328
329
/* DEFAULT CONFIGURATION PART ENDS HERE */
330
331
+ $q_config['term_name'] = array();//is it in use?
332
333
// Full country names as locales for Windows systems
334
$q_config['windows_locale']['aa'] = "Afar";
514
515
// set hooks at the end
516
require_once(dirname(__FILE__)."/qtranslate_hooks.php");
517
+
518
+ /* not working this way
519
+ if(file_exists(WP_PLUGIN_DIR.'/mqtranslate/mqtranslate.php')
520
+ ||file_exists(WP_PLUGIN_DIR.'/qtranslate/qtranslate.php')
521
+ //||file_exists(WP_PLUGIN_DIR.'/qtranslate-xp/ppqtranslate.php')
522
+ //||file_exists(WP_PLUGIN_DIR.'/ztranslate/ztranslate.php')
523
+ ){
524
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
525
+ if(!is_plugin_active( 'mqtranslate/mqtranslate.php' )
526
+ && !is_plugin_active( 'qtranslate/qtranslate.php' )
527
+ ){
528
+ require_once(dirname(__FILE__)."/qtranslate_compatibility.php");
529
+ }
530
+ }
531
+ */
532
?>
qtranslate_compatibility.php ADDED
@@ -0,0 +1,28 @@
1
+ <?php
2
+ if(!function_exists('qtrans_getLanguage')){
3
+ function qtrans_getLanguage(){
4
+ return qtranxf_getLanguage();
5
+ }
6
+ }
7
+ if(!function_exists('qtrans_convertURL')){
8
+ function qtrans_convertURL($url='', $lang='', $forceadmin = false, $showDefaultLanguage = false){
9
+ return qtranxf_convertURL($url, $lang, $forceadmin, $showDefaultLanguage);
10
+ }
11
+ }
12
+ if(!function_exists('qtrans_use')){
13
+ function qtrans_use($lang, $text, $show_available=false){
14
+ return qtranxf_use($lang, $text, $show_available);
15
+ }
16
+ }
17
+ if (!function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')){
18
+ function qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($content){
19
+ return qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($content);
20
+ }
21
+ }
22
+ if(!function_exists('qtrans_useTermLib')){
23
+ function qtrans_useTermLib($obj){ return qtranxf_useTermLib($obj); }
24
+ }
25
+ if(!function_exists('qtrans_getSortedLanguages')){
26
+ function qtrans_getSortedLanguages($reverse = false){ return qtranxf_getSortedLanguages($reverse); }
27
+ }
28
+ ?>
qtranslate_configuration.php CHANGED
@@ -17,6 +17,9 @@
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
require_once(dirname(__FILE__)."/admin/import_export.php");
21
require_once(dirname(__FILE__)."/admin/activation_hook.php");
22
@@ -40,12 +43,15 @@ function qtranxf_update_config()
40
delete_option('qtranslate_url_mode');
41
delete_option('qtranslate_detect_browser_language');
42
delete_option('qtranslate_hide_untranslated');
43
delete_option('qtranslate_auto_update_mo');
44
delete_option('qtranslate_next_update_mo');
45
delete_option('qtranslate_hide_default_language');
46
delete_option('qtranslate_custom_fields');
47
if(isset($_POST['qtranslate_reset3'])) {
48
delete_option('qtranslate_term_name');
49
}
50
}
51
}
@@ -56,12 +62,29 @@ function qtranxf_add_admin_js () {
56
//wp_register_script( 'qtranslate-script', plugins_url( '/qtranslate.js', __FILE__ ) );
57
wp_register_script( 'qtranslate-script', plugins_url( '/qtranslate.min.js', __FILE__ ) );
58
wp_enqueue_script( 'qtranslate-script' );
59
wp_deregister_script( 'autosave' );//autosave script saves the active language only and messes it up later in a hard way
60
//echo '<script>var qTranslateConfig='.json_encode($q_config).';</script>';
61
?>
62
<script type="text/javascript">
63
// <![CDATA[
64
- var qTranslateConfig=<?php echo json_encode($q_config); ?>;
65
function qtranxj_getcookie(cname)
66
{
67
var nm = cname + "=";
@@ -233,7 +256,7 @@ function qtranxf_language_form($lang = '', $language_code = '', $language_name =
233
<label for="language_locale"><?php _e('Locale', 'qtranslate') ?></label>
234
<input name="language_locale" id="language_locale" type="text" value="<?php echo $language_locale; ?>" size="5" maxlength="5"/>
235
<p>
236
- <?php _e('PHP and Wordpress Locale for the language. (Example: en_US)', 'qtranslate'); ?><br />
237
<?php _e('You will need to install the .mo file for this language.', 'qtranslate'); ?>
238
</p>
239
</div>
@@ -251,8 +274,8 @@ function qtranxf_language_form($lang = '', $language_code = '', $language_name =
251
<label for="language_na_message"><?php _e('Not Available Message', 'qtranslate') ?></label>
252
<input name="language_na_message" id="language_na_message" type="text" value="<?php echo $language_na_message; ?>"/>
253
<p>
254
- <?php _e('Message to display if post is not available in the requested language. (Example: Sorry, this entry is only available in %LANG:, : and %.)', 'qtranslate'); ?><br />
255
- <?php _e('%LANG:&lt;normal_seperator&gt;:&lt;last_seperator&gt;% generates a list of languages seperated by &lt;normal_seperator&gt; except for the last one, where &lt;last_seperator&gt; will be used instead.', 'qtranslate'); ?><br />
256
</p>
257
</div>
258
<?php
@@ -275,11 +298,20 @@ function qtranxf_updateSetting($var, $type = QTX_STRING) {
275
case QTX_ARRAY:
276
if(!isset($_POST[$var])) return false;
277
$val=preg_split('/[\s,]+/',$_POST[$var]);
278
$diff=array_diff($q_config[$var],$val);
279
if(empty($diff)) return false;
280
$q_config[$var] = $val;
281
- update_option('qtranslate_'.$var, $q_config[$var]);
282
return true;
283
case QTX_BOOLEAN:
284
if(isset($_POST[$var])&&$_POST[$var]==1) {
285
if($q_config[$var]) return false;
@@ -302,6 +334,32 @@ function qtranxf_updateSetting($var, $type = QTX_STRING) {
302
return false;
303
}
304
305
function qtranxf_language_columns($columns) {
306
return array(
307
'flag' => 'Flag',
@@ -369,14 +427,19 @@ function qtranxf_conf() {
369
// save settings
370
qtranxf_updateSetting('default_language', QTX_LANGUAGE);
371
qtranxf_updateSetting('flag_location', QTX_URL);
372
- qtranxf_updateSetting('ignore_file_types', QTX_STRING);
373
qtranxf_updateSetting('detect_browser_language', QTX_BOOLEAN);
374
qtranxf_updateSetting('hide_untranslated', QTX_BOOLEAN);
375
qtranxf_updateSetting('use_strftime', QTX_INTEGER);
376
qtranxf_updateSetting('url_mode', QTX_INTEGER);
377
qtranxf_updateSetting('auto_update_mo', QTX_BOOLEAN);
378
qtranxf_updateSetting('hide_default_language', QTX_BOOLEAN);
379
qtranxf_updateSetting('custom_fields', QTX_ARRAY);
380
if(isset($_POST['update_mo_now']) && $_POST['update_mo_now']=='1' && qtranxf_updateGettextDatabases(true))
381
$message = __('Gettext databases updated.', 'qtranslate');
382
}
@@ -598,7 +661,7 @@ function qtranxf_conf() {
598
<td>
599
<fieldset id="qtranxs-languages-menu"><legend class="hidden"><?php _e('Default Language', 'qtranslate') ?></legend>
600
<?php
601
- foreach ( qtranxf_getSortedLanguages() as $key => $language ) {
602
echo "\t<label title='" . $q_config['language_name'][$language] . "'><input type='radio' name='default_language' value='" . $language . "'";
603
if ( $language == $q_config['default_language'] ) {
604
echo " checked='checked'";
@@ -607,21 +670,22 @@ function qtranxf_conf() {
607
echo ' <a href="'.add_query_arg('moveup', $language, $clean_uri).'"><img src="'.WP_PLUGIN_URL.'/qtranslate-x/arrowup.png" alt="up" /></a>';
608
echo ' <a href="'.add_query_arg('movedown', $language, $clean_uri).'"><img src="'.WP_PLUGIN_URL.'/qtranslate-x/arrowdown.png" alt="down" /></a>';
609
echo ' <img src="' . trailingslashit(WP_CONTENT_URL) .$q_config['flag_location'].$q_config['flag'][$language] . '" alt="' . $q_config['language_name'][$language] . '" /> ';
610
- echo ' '.$q_config['language_name'][$language] . "</label><br />\n";
611
}
612
?>
613
- </br>
614
- <?php printf(__('Choose the default language of your blog. This is the language which will be shown on %s. You can also change the order the languages by clicking on the arrows above.', 'qtranslate'), get_bloginfo('url')); ?>
615
</fieldset>
616
</td>
617
</tr>
618
<tr valign="top">
619
<th scope="row"><?php _e('Hide Untranslated Content', 'qtranslate');?></th>
620
<td>
621
- <label for="hide_untranslated"><input type="checkbox" name="hide_untranslated" id="hide_untranslated" value="1"<?php echo ($q_config['hide_untranslated'])?' checked="checked"':''; ?>/> <?php _e('Hide Content which is not available for the selected language.', 'qtranslate'); ?></label>
622
<br/>
623
- <?php _e('When checked, posts will be hidden if the content is not available for the selected language. If unchecked, a message will appear showing all the languages the content is available in.', 'qtranslate'); ?>
624
- <?php _e('This function will not work correctly if you installed qTranslate on a blog with existing entries. In this case you will need to take a look at "Convert Database" under "Advanced Settings".', 'qtranslate'); ?>
625
</td>
626
</tr>
627
<tr valign="top">
@@ -629,7 +693,7 @@ function qtranxf_conf() {
629
<td>
630
<label for="detect_browser_language"><input type="checkbox" name="detect_browser_language" id="detect_browser_language" value="1"<?php echo ($q_config['detect_browser_language'])?' checked="checked"':''; ?>/> <?php _e('Detect the language of the browser and redirect accordingly.', 'qtranslate'); ?></label>
631
<br/>
632
- <?php _e('When the frontpage is visited via bookmark/external link/type-in, the visitor will be forwarded to the correct URL for the language specified by his browser.', 'qtranslate'); ?>
633
</td>
634
</tr>
635
</table>
@@ -640,11 +704,12 @@ function qtranxf_conf() {
640
<th scope="row"><?php _e('URL Modification Mode', 'qtranslate') ?></th>
641
<td>
642
<fieldset><legend class="hidden"><?php _e('URL Modification Mode', 'qtranslate') ?></legend>
643
- <label title="Pre-Path Mode"><input type="radio" name="url_mode" value="<?php echo QTX_URL_PATH; ?>" <?php echo ($q_config['url_mode']==QTX_URL_PATH)?"checked=\"checked\"":""; ?> /> <?php echo __('Use Pre-Path Mode (Default, puts /en/ in front of URL)', 'qtranslate').'. SEO '.__('friendly', 'qtranslate').'.'; ?></label><br />
644
- <label title="Pre-Domain Mode"><input type="radio" name="url_mode" value="<?php echo QTX_URL_DOMAIN; ?>" <?php echo ($q_config['url_mode']==QTX_URL_DOMAIN)?"checked=\"checked\"":""; ?> /> <?php echo __('Use Pre-Domain Mode (uses http://en.yoursite.com)', 'qtranslate').'. '.__('You will need to configure DNS sub-domains on your site.', 'qtranslate'); ?></label><br />
645
- <label title="Query Mode"><input type="radio" name="url_mode" value="<?php echo QTX_URL_QUERY; ?>" <?php echo ($q_config['url_mode']==QTX_URL_QUERY)?"checked=\"checked\"":""; ?> /> <?php echo __('Use Query Mode (?lang=en)', 'qtranslate').'. '.__('Most SEO unfriendly, not recommended.', 'qtranslate'); ?></label><br />
646
- </fieldset><br/>
647
- <?php _e('Pre-Path and Pre-Domain mode will only work with mod_rewrite/pretty permalinks. Additional Configuration is needed for Pre-Domain mode!', 'qtranslate'); ?><br/>
648
<label for="hide_default_language"><input type="checkbox" name="hide_default_language" id="hide_default_language" value="1"<?php echo ($q_config['hide_default_language'])?' checked="checked"':''; ?>/> <?php _e('Hide URL language information for default language.', 'qtranslate'); ?></label>
649
</td>
650
</tr>
@@ -653,15 +718,15 @@ function qtranxf_conf() {
653
<td>
654
<?php echo trailingslashit(WP_CONTENT_URL); ?><input type="text" name="flag_location" id="flag_location" value="<?php echo $q_config['flag_location']; ?>" style="width:50%"/>
655
<br/>
656
- <?php _e('Path to the flag images under wp-content, with trailing slash. (Default: plugins/qtranslate-x/flags/)', 'qtranslate'); ?>
657
</td>
658
</tr>
659
<tr valign="top">
660
<th scope="row"><?php _e('Ignore Links', 'qtranslate');?></th>
661
<td>
662
- <input type="text" name="ignore_file_types" id="ignore_file_types" value="<?php echo $q_config['ignore_file_types']; ?>" style="width:100%"/>
663
<br/>
664
- <?php _e('Don\'t convert Links to files of the given file types. (Default: gif,jpg,jpeg,png,pdf,swf,tif,rar,zip,7z,mpg,divx,mpeg,avi,css,js)', 'qtranslate'); ?>
665
</td>
666
</tr>
667
<tr valign="top">
@@ -671,27 +736,54 @@ function qtranxf_conf() {
671
<br/>
672
<label for="update_mo_now"><input type="checkbox" name="update_mo_now" id="update_mo_now" value="1" /> <?php _e('Update Gettext databases now.', 'qtranslate'); ?></label>
673
<br/>
674
- <?php _e('qTranslate will query the Wordpress Localisation Repository every week and download the latest Gettext Databases (.mo Files).', 'qtranslate'); ?>
675
</td>
676
</tr>
677
<tr valign="top">
678
<th scope="row"><?php _e('Date / Time Conversion', 'qtranslate');?></th>
679
<td>
680
- <label><input type="radio" name="use_strftime" value="<?php echo QTX_DATE; ?>" <?php echo ($q_config['use_strftime']==QTX_DATE)?' checked="checked"':''; ?>/> <?php _e('Use emulated date function.', 'qtranslate'); ?></label><br />
681
- <label><input type="radio" name="use_strftime" value="<?php echo QTX_DATE_OVERRIDE; ?>" <?php echo ($q_config['use_strftime']==QTX_DATE_OVERRIDE)?' checked="checked"':''; ?>/> <?php _e('Use emulated date function and replace formats with the predefined formats for each language.', 'qtranslate'); ?></label><br />
682
- <label><input type="radio" name="use_strftime" value="<?php echo QTX_STRFTIME; ?>" <?php echo ($q_config['use_strftime']==QTX_STRFTIME)?' checked="checked"':''; ?>/> <?php _e('Use strftime instead of date.', 'qtranslate'); ?></label><br />
683
- <label><input type="radio" name="use_strftime" value="<?php echo QTX_STRFTIME_OVERRIDE; ?>" <?php echo ($q_config['use_strftime']==QTX_STRFTIME_OVERRIDE)?' checked="checked"':''; ?>/> <?php _e('Use strftime instead of date and replace formats with the predefined formats for each language.', 'qtranslate'); ?></label><br />
684
- <?php _e('Depending on the mode selected, additional customizations of the theme may be needed.', 'qtranslate'); ?>
685
</td>
686
</tr>
687
<tr valign="top">
688
- <th scope="row"><?php _e('Custom Fields', 'qtranslate');?></th>
689
<td>
690
- <input type="text" name="custom_fields" id="qtranxs_custom_fields" value="<?php echo implode(' ',$q_config['custom_fields']); ?>" style="width:100%">
691
- <p><?php printf(__('Enter "id" attribute of text fields from your theme, which you wish to translate. This applies to post, page and media editors (/wp-admin/post*). To lookup "id", right-click on the field in the post or the page editor and choose "Inspect Element". Look for an attribute of the field named "id". Enter it here, as many as you need, space-separated. After saving configuration, these fields will start responding to the language switching buttons, and you can enter different text for each language. For more information, read %sFAQ%s.', 'qtranslate'),'<a href="https://wordpress.org/plugins/qtranslate-x/faq/">','</a>'); ?></p>
692
</td>
693
</tr>
694
- <?php/*
695
<tr>
696
<th scope="row"><?php _e('Debugging Information', 'qtranslate');?></th>
697
<td>
@@ -708,7 +800,7 @@ function qtranxf_conf() {
708
?></textarea>
709
</td>
710
</tr>
711
- */?>
712
</table>
713
<?php qtranxf_admin_section_end('advanced'); ?>
714
<?php do_action('qtranslate_configuration', $clean_uri); ?>
@@ -826,7 +918,7 @@ function qtranxf_nav_menu_metabox( $object )
826
</div>
827
<span class="list-controls hide-if-no-js">
828
<a href="javascript:void(0);" class="help" onclick="jQuery( '#help-login-links' ).toggle();"><?php _e( 'Help' ); ?></a>
829
- <span class="hide-if-js" id="help-login-links"><br /><a name="help-login-links"></a>
830
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.
831
</span>
832
</span>
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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
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
}
62
//wp_register_script( 'qtranslate-script', plugins_url( '/qtranslate.js', __FILE__ ) );
63
wp_register_script( 'qtranslate-script', plugins_url( '/qtranslate.min.js', __FILE__ ) );
64
wp_enqueue_script( 'qtranslate-script' );
65
+
66
+ wp_dequeue_script('autosave');
67
wp_deregister_script( 'autosave' );//autosave script saves the active language only and messes it up later in a hard way
68
+
69
//echo '<script>var qTranslateConfig='.json_encode($q_config).';</script>';
70
+ $keys=array('enabled_languages','default_language','language','term_name','custom_fields','custom_field_classes','url_mode');
71
+ foreach($keys as $key){
72
+ $config[$key]=$q_config[$key];
73
+ }
74
+ $config['url_info_home']=$q_config['url_info']['home'];
75
+ //$config['WP_CONTENT_URL']=trailingslashit(WP_CONTENT_URL);
76
+ $config['flag_location']=trailingslashit(WP_CONTENT_URL).$q_config['flag_location'];
77
+ $config['flag']=array();
78
+ $config['language_name']=array();
79
+ foreach($q_config['enabled_languages'] as $lang)
80
+ {
81
+ $config['flag'][$lang]=$q_config['flag'][$lang];
82
+ $config['language_name'][$lang]=$q_config['language_name'][$lang];
83
+ }
84
?>
85
<script type="text/javascript">
86
// <![CDATA[
87
+ var qTranslateConfig=<?php echo json_encode($config); ?>;
88
function qtranxj_getcookie(cname)
89
{
90
var nm = cname + "=";
256
<label for="language_locale"><?php _e('Locale', 'qtranslate') ?></label>
257
<input name="language_locale" id="language_locale" type="text" value="<?php echo $language_locale; ?>" size="5" maxlength="5"/>
258
<p>
259
+ <?php _e('PHP and Wordpress Locale for the language. (Example: en_US)', 'qtranslate'); ?><br/>
260
<?php _e('You will need to install the .mo file for this language.', 'qtranslate'); ?>
261
</p>
262
</div>
274
<label for="language_na_message"><?php _e('Not Available Message', 'qtranslate') ?></label>
275
<input name="language_na_message" id="language_na_message" type="text" value="<?php echo $language_na_message; ?>"/>
276
<p>
277
+ <?php _e('Message to display if post is not available in the requested language. (Example: Sorry, this entry is only available in %LANG:, : and %.)', 'qtranslate'); ?><br/>
278
+ <?php _e('%LANG:&lt;normal_seperator&gt;:&lt;last_seperator&gt;% generates a list of languages seperated by &lt;normal_seperator&gt; except for the last one, where &lt;last_seperator&gt; will be used instead.', 'qtranslate'); ?><br/>
279
</p>
280
</div>
281
<?php
298
case QTX_ARRAY:
299
if(!isset($_POST[$var])) return false;
300
$val=preg_split('/[\s,]+/',$_POST[$var]);
301
+ if( qtranxf_array_compare($q_config[$var],$val) ) return false;
302
+ $q_config[$var] = $val;
303
+ update_option('qtranslate_'.$var, $q_config[$var]);
304
+ return true;
305
+ /*
306
+ case QTX_ARRAY_STRING:
307
+ if(!isset($_POST[$var])) return false;
308
+ $val=preg_split('/[\s,]+/',strtolower($_POST[$var]));
309
$diff=array_diff($q_config[$var],$val);
310
if(empty($diff)) return false;
311
$q_config[$var] = $val;
312
+ update_option('qtranslate_'.$var, implode(',',$val));
313
return true;
314
+ */
315
case QTX_BOOLEAN:
316
if(isset($_POST[$var])&&$_POST[$var]==1) {
317
if($q_config[$var]) return false;
334
return false;
335
}
336
337
+ function qtranxf_updateSettingIgnoreFileTypes() {
338
+ global $q_config;
339
+ if(!isset($_POST['submit'])) return false;
340
+ $var='ignore_file_types';
341
+ if(!isset($_POST[$var])) return false;
342
+ $posted=preg_split('/[\s,]+/',strtolower($_POST[$var]));
343
+ $val=explode(',',QTX_IGNORE_FILE_TYPES);
344
+ foreach($posted as $v){
345
+ if(empty($v)) continue;
346
+ if(in_array($v,$val)) continue;
347
+ $val[]=$v;
348
+ }
349
+ if( qtranxf_array_compare($q_config[$var],$val) ) return false;
350
+ $q_config[$var] = $val;
351
+ update_option('qtranslate_'.$var, implode(',',$val));
352
+ return true;
353
+ }
354
+
355
+ function qtranxf_array_compare($a,$b) {
356
+ if(count($a)!=count($b)) return false;
357
+ //can be optimized
358
+ $diff_a=array_diff($a,$b);
359
+ $diff_b=array_diff($b,$a);
360
+ return empty($diff_a) && empty($diff_b);
361
+ }
362
+
363
function qtranxf_language_columns($columns) {
364
return array(
365
'flag' => 'Flag',
427
// save settings
428
qtranxf_updateSetting('default_language', QTX_LANGUAGE);
429
qtranxf_updateSetting('flag_location', QTX_URL);
430
+ //qtranxf_updateSetting('ignore_file_types', QTX_ARRAY_STRING);
431
+ qtranxf_updateSettingIgnoreFileTypes();
432
qtranxf_updateSetting('detect_browser_language', QTX_BOOLEAN);
433
qtranxf_updateSetting('hide_untranslated', QTX_BOOLEAN);
434
+ qtranxf_updateSetting('show_displayed_language_prefix', QTX_BOOLEAN);
435
qtranxf_updateSetting('use_strftime', QTX_INTEGER);
436
qtranxf_updateSetting('url_mode', QTX_INTEGER);
437
qtranxf_updateSetting('auto_update_mo', QTX_BOOLEAN);
438
qtranxf_updateSetting('hide_default_language', QTX_BOOLEAN);
439
+ qtranxf_updateSetting('qtrans_compatibility', QTX_BOOLEAN);
440
qtranxf_updateSetting('custom_fields', QTX_ARRAY);
441
+ qtranxf_updateSetting('custom_field_classes', QTX_ARRAY);
442
+ qtranxf_updateSetting('text_field_filters', QTX_ARRAY);
443
if(isset($_POST['update_mo_now']) && $_POST['update_mo_now']=='1' && qtranxf_updateGettextDatabases(true))
444
$message = __('Gettext databases updated.', 'qtranslate');
445
}
661
<td>
662
<fieldset id="qtranxs-languages-menu"><legend class="hidden"><?php _e('Default Language', 'qtranslate') ?></legend>
663
<?php
664
+ foreach ( qtranxf_getSortedLanguages() as $key => $language ) {
665
echo "\t<label title='" . $q_config['language_name'][$language] . "'><input type='radio' name='default_language' value='" . $language . "'";
666
if ( $language == $q_config['default_language'] ) {
667
echo " checked='checked'";
670
echo ' <a href="'.add_query_arg('moveup', $language, $clean_uri).'"><img src="'.WP_PLUGIN_URL.'/qtranslate-x/arrowup.png" alt="up" /></a>';
671
echo ' <a href="'.add_query_arg('movedown', $language, $clean_uri).'"><img src="'.WP_PLUGIN_URL.'/qtranslate-x/arrowdown.png" alt="down" /></a>';
672
echo ' <img src="' . trailingslashit(WP_CONTENT_URL) .$q_config['flag_location'].$q_config['flag'][$language] . '" alt="' . $q_config['language_name'][$language] . '" /> ';
673
+ echo ' '.$q_config['language_name'][$language] . "</label><br/>\n";
674
}
675
?>
676
+ <small><?php printf(__('Choose the default language of your blog. This is the language which will be shown on %s. You can also change the order the languages by clicking on the arrows above.', 'qtranslate'), get_bloginfo('url')); ?></small>
677
</fieldset>
678
</td>
679
</tr>
680
<tr valign="top">
681
<th scope="row"><?php _e('Hide Untranslated Content', 'qtranslate');?></th>
682
<td>
683
+ <label for="hide_untranslated"><input type="checkbox" name="hide_untranslated" id="hide_untranslated" value="1"<?php if($q_config['hide_untranslated']) echo ' checked="checked"'; ?>/> <?php _e('Hide Content which is not available for the selected language.', 'qtranslate'); ?></label>
684
<br/>
685
+ <small><?php _e('When checked, posts will be hidden if the content is not available for the selected language. If unchecked, a message will appear showing all the languages the content is available in.', 'qtranslate'); ?>
686
+ <?php _e('This function will not work correctly if you installed qTranslate on a blog with existing entries. In this case you will need to take a look at "Convert Database" under "Advanced Settings".', 'qtranslate'); ?></small>
687
+ <br/><br/>
688
+ <label for="show_displayed_language_prefix"><input type="checkbox" name="show_displayed_language_prefix" id="show_displayed_language_prefix" value="1"<?php if($q_config['show_displayed_language_prefix']) echo ' checked="checked"'; ?>/> <?php _e('Show displayed language prefix when content is not available for the selected language.', 'qtranslate'); ?></label>
689
</td>
690
</tr>
691
<tr valign="top">
693
<td>
694
<label for="detect_browser_language"><input type="checkbox" name="detect_browser_language" id="detect_browser_language" value="1"<?php echo ($q_config['detect_browser_language'])?' checked="checked"':''; ?>/> <?php _e('Detect the language of the browser and redirect accordingly.', 'qtranslate'); ?></label>
695
<br/>
696
+ <small><?php _e('When the frontpage is visited via bookmark/external link/type-in, the visitor will be forwarded to the correct URL for the language specified by his browser.', 'qtranslate'); ?></small>
697
</td>
698
</tr>
699
</table>
704
<th scope="row"><?php _e('URL Modification Mode', 'qtranslate') ?></th>
705
<td>
706
<fieldset><legend class="hidden"><?php _e('URL Modification Mode', 'qtranslate') ?></legend>
707
+ <label title="Pre-Path Mode"><input type="radio" name="url_mode" value="<?php echo QTX_URL_PATH; ?>" <?php echo ($q_config['url_mode']==QTX_URL_PATH)?"checked=\"checked\"":""; ?> /> <?php echo __('Use Pre-Path Mode (Default, puts /en/ in front of URL)', 'qtranslate').'. SEO '.__('friendly', 'qtranslate').'.'; ?></label><br/>
708
+ <label title="Pre-Domain Mode"><input type="radio" name="url_mode" value="<?php echo QTX_URL_DOMAIN; ?>" <?php echo ($q_config['url_mode']==QTX_URL_DOMAIN)?"checked=\"checked\"":""; ?> /> <?php echo __('Use Pre-Domain Mode (uses http://en.yoursite.com)', 'qtranslate').'. '.__('You will need to configure DNS sub-domains on your site.', 'qtranslate'); ?></label><br/>
709
+ <label title="Query Mode"><input type="radio" name="url_mode" value="<?php echo QTX_URL_QUERY; ?>" <?php echo ($q_config['url_mode']==QTX_URL_QUERY)?"checked=\"checked\"":""; ?> /> <?php echo __('Use Query Mode (?lang=en)', 'qtranslate').'. '.__('Most SEO unfriendly, not recommended.', 'qtranslate'); ?></label><br/>
710
+ </fieldset>
711
+ <small><?php _e('Pre-Path and Pre-Domain mode will only work with mod_rewrite/pretty permalinks. Additional Configuration is needed for Pre-Domain mode!', 'qtranslate'); ?></small>
712
+ <br/><br/>
713
<label for="hide_default_language"><input type="checkbox" name="hide_default_language" id="hide_default_language" value="1"<?php echo ($q_config['hide_default_language'])?' checked="checked"':''; ?>/> <?php _e('Hide URL language information for default language.', 'qtranslate'); ?></label>
714
</td>
715
</tr>
718
<td>
719
<?php echo trailingslashit(WP_CONTENT_URL); ?><input type="text" name="flag_location" id="flag_location" value="<?php echo $q_config['flag_location']; ?>" style="width:50%"/>
720
<br/>
721
+ <small><?php _e('Path to the flag images under wp-content, with trailing slash. (Default: plugins/qtranslate-x/flags/)', 'qtranslate'); ?></small>
722
</td>
723
</tr>
724
<tr valign="top">
725
<th scope="row"><?php _e('Ignore Links', 'qtranslate');?></th>
726
<td>
727
+ <input type="text" name="ignore_file_types" id="ignore_file_types" value="<?php echo implode(',',array_diff($q_config['ignore_file_types'],explode(',',QTX_IGNORE_FILE_TYPES))); ?>" style="width:100%"/>
728
<br/>
729
+ <small><?php printf(__('Don\'t convert links to files of the given file types. (Always included: %s)', 'qtranslate'),implode(', ',explode(',',QTX_IGNORE_FILE_TYPES))); ?></small>
730
</td>
731
</tr>
732
<tr valign="top">
736
<br/>
737
<label for="update_mo_now"><input type="checkbox" name="update_mo_now" id="update_mo_now" value="1" /> <?php _e('Update Gettext databases now.', 'qtranslate'); ?></label>
738
<br/>
739
+ <small><?php _e('qTranslate will query the Wordpress Localisation Repository every week and download the latest Gettext Databases (.mo Files).', 'qtranslate'); ?></small>
740
</td>
741
</tr>
742
<tr valign="top">
743
<th scope="row"><?php _e('Date / Time Conversion', 'qtranslate');?></th>
744
<td>
745
+ <label><input type="radio" name="use_strftime" value="<?php echo QTX_DATE; ?>" <?php echo ($q_config['use_strftime']==QTX_DATE)?' checked="checked"':''; ?>/> <?php _e('Use emulated date function.', 'qtranslate'); ?></label><br/>
746
+ <label><input type="radio" name="use_strftime" value="<?php echo QTX_DATE_OVERRIDE; ?>" <?php echo ($q_config['use_strftime']==QTX_DATE_OVERRIDE)?' checked="checked"':''; ?>/> <?php _e('Use emulated date function and replace formats with the predefined formats for each language.', 'qtranslate'); ?></label><br/>
747
+ <label><input type="radio" name="use_strftime" value="<?php echo QTX_STRFTIME; ?>" <?php echo ($q_config['use_strftime']==QTX_STRFTIME)?' checked="checked"':''; ?>/> <?php _e('Use strftime instead of date.', 'qtranslate'); ?></label><br/>
748
+ <label><input type="radio" name="use_strftime" value="<?php echo QTX_STRFTIME_OVERRIDE; ?>" <?php echo ($q_config['use_strftime']==QTX_STRFTIME_OVERRIDE)?' checked="checked"':''; ?>/> <?php _e('Use strftime instead of date and replace formats with the predefined formats for each language.', 'qtranslate'); ?></label><br/>
749
+ <small><?php _e('Depending on the mode selected, additional customizations of the theme may be needed.', 'qtranslate'); ?></small>
750
+ </td>
751
+ </tr>
752
+ <tr valign="top">
753
+ <th scope="row"><?php echo __('Custom Fields', 'qtranslate');?></th>
754
+ <td>
755
+ <?php printf(__('Enter "id" or "class" attribute of text fields from your theme, which you wish to translate. This applies to post, page and media editors (/wp-admin/post*). To lookup "id" or "class", right-click on the field in the post or the page editor and choose "Inspect Element". Look for an attribute of the field named "id" or "class". Enter it below, as many as you need, space- or comma-separated. After saving configuration, these fields will start responding to the language switching buttons, and you can enter different text for each language. The input fields of type %s will be parsed using %s syntax, while single line text fields will use %s syntax. If you need to override this behaviour, prepend prefix %s or %s to the name of the field to specify which syntax to use. For more information, read %sFAQ%s.', 'qtranslate'),'\'textarea\'',esc_html('<!--:-->'),'[:]','\'<\'','\'[\'','<a href="https://wordpress.org/plugins/qtranslate-x/faq/">','</a>'); ?>
756
+ </td>
757
+ </tr>
758
+ <tr valign="top">
759
+ <th scope="row" style="text-align: right">id:</th>
760
+ <td>
761
+ <input type="text" name="custom_fields" id="qtranxs_custom_fields" value="<?php echo implode(' ',$q_config['custom_fields']); ?>" style="width:100%"><br/>
762
+ <small><?php _e('The value of "id" attribute is normally unique within one page, otherwise the first field found, having an id specified, is picked up.', 'qtranslate'); ?></small>
763
+ </td>
764
+ </tr>
765
+ <tr valign="top">
766
+ <th scope="row" style="text-align: right">class:</th>
767
+ <td>
768
+ <input type="text" name="custom_field_classes" id="qtranxs_custom_field_classes" value="<?php echo implode(' ',$q_config['custom_field_classes']); ?>" style="width:100%"><br>
769
+ <small><?php printf(__('All the fields of specified classes will respond to Language Switching Buttons. Be careful not to include a class, which would affect language-neutral fields. If you cannot uniquely identify a field needed neither by %s, nor by %s attribute, report the issue on %sSupport Forum%s', 'qtranslate'),'"id"', '"class"', '<a href="https://wordpress.org/support/plugin/qtranslate-x">','</a>'); ?></small>
770
+ </td>
771
+ </tr>
772
+ <tr valign="top">
773
+ <th scope="row"><?php echo __('Custom Filters', 'qtranslate');?></th>
774
+ <td>
775
+ <input type="text" name="text_field_filters" id="qtranxs_text_field_filters" value="<?php echo implode(' ',$q_config['text_field_filters']); ?>" style="width:100%"><br>
776
+ <small><?php printf(__('Names of filters (which are enabled on theme or other plugins via %s function) to add translation to. For more information, read %sFAQ%s.', 'qtranslate'),'apply_filters()','<a href="https://wordpress.org/plugins/qtranslate-x/faq/">','</a>'); ?></small>
777
</td>
778
</tr>
779
<tr valign="top">
780
+ <th scope="row"><?php _e('Compatibility Functions', 'qtranslate');?></th>
781
<td>
782
+ <label for="qtrans_compatibility"><input type="checkbox" name="qtrans_compatibility" id="qtrans_compatibility" value="1"<?php echo ($q_config['qtrans_compatibility'])?' checked="checked"':''; ?>/>&nbsp;<?php printf(__('Enable function names compatibility for %s.', 'qtranslate'), 'qtrans_getLanguage, qtrans_convertURL, qtrans_use, qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage, qtranxf_useTermLib and qtrans_getSortedLanguages'); ?></label><br/>
783
+ <small><?php printf(__('Some plugins and themes use direct calls to the functions listed, which are defined in former %s plugin and some of its forks. Turning this flag on will enable those function to exists, which will make the dependent plugins and themes to work. WordPress policy prohibits to define functions with the same names as in other plugins, since it generates user-unfriendly fatal errors, when two conflicting plugins are activated simultaneously. Before turning this option on, you have to make sure that there are no other plugins active, which define those functions.', 'qtranslate'), '<a href="https://wordpress.org/plugins/qtranslate/" target="_blank">qTranslate</a>'); ?></small>
784
</td>
785
</tr>
786
+ <?php /*
787
<tr>
788
<th scope="row"><?php _e('Debugging Information', 'qtranslate');?></th>
789
<td>
800
?></textarea>
801
</td>
802
</tr>
803
+ */ ?>
804
</table>
805
<?php qtranxf_admin_section_end('advanced'); ?>
806
<?php do_action('qtranslate_configuration', $clean_uri); ?>
918
</div>
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>
qtranslate_core.php CHANGED
@@ -17,6 +17,9 @@
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
/* qTranslate Functions */
21
22
function qtranxf_init() {
@@ -28,82 +31,40 @@ function qtranxf_init() {
28
do_action('qtranxf_init_begin');
29
30
qtranxf_loadConfig();
31
- if(isset($_COOKIE['qtrans_cookie_test'])) {
32
- $q_config['cookie_enabled'] = true;
33
- } else {
34
- $q_config['cookie_enabled'] = false;
35
- }
36
-
37
- // update Gettext Databases if on Backend
38
- if(defined('WP_ADMIN') && $q_config['auto_update_mo']) qtranxf_updateGettextDatabases();
39
-
40
- // update definitions if neccesary
41
- if(defined('WP_ADMIN') && current_user_can('manage_categories')) qtranxf_updateTermLibrary();
42
-
43
- // extract url information
44
- $q_config['url_info'] = qtranxf_extractURL($_SERVER['REQUEST_URI'], $_SERVER["HTTP_HOST"], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
45
-
46
- $q_config['WP_CONTENT_URL'] = trailingslashit(WP_CONTENT_URL);
47
-
48
- // set test cookie
49
- setcookie('qtrans_cookie_test', 'qTranslateookie Test', 0, $q_config['url_info']['home'], $q_config['url_info']['host']);
50
- // check cookies for admin
51
- if(defined('WP_ADMIN')) {
52
- if(isset($_GET['lang']) && qtranxf_isEnabled($_GET['lang'])) {
53
- $q_config['language'] = $q_config['url_info']['language'];
54
- setcookie('qtrans_admin_language', $q_config['language'], time()+60*60*24*30);
55
- } elseif(isset($_COOKIE['qtrans_admin_language']) && qtranxf_isEnabled($_COOKIE['qtrans_admin_language'])) {
56
- $q_config['language'] = $_COOKIE['qtrans_admin_language'];
57
- } else {
58
- $q_config['language'] = $q_config['default_language'];
59
- }
60
- } else {
61
- $q_config['language'] = $q_config['url_info']['language'];
62
}
63
-
64
$q_config['language'] = apply_filters('qtranslate_language', $q_config['language']);
65
-
66
- // detect language and forward if needed
67
- if($q_config['detect_browser_language'] && $q_config['url_info']['redirect'] && !isset($_COOKIE['qtrans_cookie_test']) && $q_config['url_info']['language'] == $q_config['default_language']) {
68
- $target = false;
69
- $prefered_languages = array();
70
- if(isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) && preg_match_all("#([^;,]+)(;[^,0-9]*([0-9\.]+)[^,]*)?#i",$_SERVER["HTTP_ACCEPT_LANGUAGE"], $matches, PREG_SET_ORDER)) {
71
- $priority = 1.0;
72
- foreach($matches as $match) {
73
- if(!isset($match[3])) {
74
- $pr = $priority;
75
- $priority -= 0.001;
76
- } else {
77
- $pr = floatval($match[3]);
78
- }
79
- $prefered_languages[$match[1]] = $pr;
80
- }
81
- arsort($prefered_languages, SORT_NUMERIC);
82
- foreach($prefered_languages as $language => $priority) {
83
- if(strlen($language)>2) $language = substr($language,0,2);
84
- if(qtranxf_isEnabled($language)) {
85
- if($q_config['hide_default_language'] && $language == $q_config['default_language']) break;
86
- $target = qtranxf_convertURL(get_option('home'),$language);
87
- break;
88
- }
89
- }
90
- }
91
- $target = apply_filters("qtranslate_language_detect_redirect", $target);
92
- if($target !== false) {
93
- wp_redirect($target);
94
- exit();
95
- }
96
- }
97
-
98
- /*
99
- // Check for WP Secret Key Missmatch
100
global $wp_default_secret_key;
101
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) {
102
global $error;
103
$error = __('Your $wp_default_secret_key is mismatchting with your AUTH_KEY. This might cause you not to be able to login anymore.', 'qtranslate');
104
}
105
- */
106
-
107
// Filter all options for language tags
108
if(!defined('WP_ADMIN')) {
109
$alloptions = wp_load_alloptions();
@@ -111,27 +72,37 @@ function qtranxf_init() {
111
add_filter('option_'.$option, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
112
}
113
}
114
-
115
// load plugin translations
116
load_plugin_textdomain('qtranslate', false, dirname(plugin_basename( __FILE__ )).'/lang');
117
-
118
// remove traces of language (or better not?)
119
//unset($_GET['lang']);
120
- $_SERVER['REQUEST_URI'] = $q_config['url_info']['url'];
121
- $_SERVER['HTTP_HOST'] = $q_config['url_info']['host'];
122
-
123
// fix url to prevent xss
124
$q_config['url_info']['url'] = qtranxf_convertURL(add_query_arg('lang',$q_config['default_language'],$q_config['url_info']['url']));
125
126
//allow other plugins to initialize whatever they need
127
do_action('qtranxf_init');
128
129
- /* /"WordPress SEO" plugin support - not yet
130
//if(is_plugin_active( 'wordpress-seo/wp-seo.php' )){//in admin only
131
if ( defined( 'WPSEO_FILE' ) ) {
132
//add_filter('wpseo_replacements', 'qtranxf_wpseo_replacements', 0);
133
add_filter('wpseo_replacements', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0);
134
- }*/
135
}
136
137
function qtranxf_resolveLangCase($lang,&$caseredirect)
@@ -150,22 +121,50 @@ function qtranxf_resolveLangCase($lang,&$caseredirect)
150
return FALSE;
151
}
152
153
// returns cleaned string and language information
154
- function qtranxf_extractURL($url, $host = '', $referer = '') {
155
global $q_config;
156
$home = qtranxf_parseURL(get_option('home'));
157
- $home['path'] = trailingslashit($home['path']);
158
$referer = qtranxf_parseURL($referer);
159
160
$result = array();
161
$result['url'] = $url;
162
$result['original_url'] = $url;
163
$result['host'] = $host;
164
$result['redirect'] = false;
165
$result['internal_referer'] = false;
166
$result['home'] = $home['path'];
167
- $caseredirect=false;
168
169
switch($q_config['url_mode']) {
170
case QTX_URL_PATH:
171
// pre url
@@ -173,10 +172,10 @@ function qtranxf_extractURL($url, $host = '', $referer = '') {
173
if($url) {
174
// might have language information
175
if(preg_match("#^([a-z]{2})(/.*)?$#i",$url,$match)) {
176
- $lang = qtranxf_resolveLangCase($match[1],$caseredirect);
177
- if($lang){
178
// found language information
179
- $result['language'] = $lang;
180
$result['url'] = $home['path'].substr($url, 3);
181
}
182
}
@@ -186,53 +185,38 @@ function qtranxf_extractURL($url, $host = '', $referer = '') {
186
// pre domain
187
if($host) {
188
if(preg_match("#^([a-z]{2}).#i",$host,$match)) {
189
- $lang = qtranxf_resolveLangCase($match[1],$caseredirect);
190
- if($lang){
191
// found language information
192
- $result['language'] = $lang;
193
$result['host'] = substr($host, 3);
194
}
195
}
196
}
197
- break;
198
- }
199
-
200
- if (isset($result['language'])){
201
- setcookie('language', $lang, time()+1209600, COOKIEPATH);
202
- }else{
203
- if (isset($_COOKIE['language'])){
204
- $lang=qtranxf_resolveLangCase($_COOKIE['language'],$caseredirect);
205
- if($lang){
206
- $result['language']=$lang;
207
- if($caseredirect){
208
- setcookie('language', $lang, time()+1209600, COOKIEPATH);
209
- $caseredirect=false;
210
- }
211
- }
212
- }else{
213
- $result['language']=$q_config['default_language'];
214
- }
215
}
216
217
- // check if referer is internal
218
- if($referer['host']==$result['host'] && qtranxf_startsWith($referer['path'], $home['path'])) {
219
// user coming from internal link
220
$result['internal_referer'] = true;
221
}
222
223
- if(isset($_GET['lang'])){
224
- $lang = qtranxf_resolveLangCase($_GET['lang'],$caseredirect);
225
if($lang){
226
- // language override given
227
- $result['language'] = $lang;
228
$result['url'] = preg_replace("#(&|\?)lang=".$lang."&?#i","$1",$result['url']);
229
$result['url'] = preg_replace("#[\?\&]+$#i","",$result['url']);
230
- } elseif($home['host'] == $result['host'] && $home['path'] == $result['url']) {
231
if(empty($referer['host'])||!$q_config['hide_default_language']) {
232
$result['redirect'] = true;
233
}else{
234
// check if activating language detection is possible
235
if(preg_match("#^([a-z]{2}).#i",$referer['host'],$match)) {
236
$lang = qtranxf_resolveLangCase($match[1],$cs);
237
if($lang) {
238
// found language information
@@ -247,24 +231,144 @@ function qtranxf_extractURL($url, $host = '', $referer = '') {
247
}
248
}
249
250
- if($caseredirect){
251
- $url=$result['host'].$result['url'];
252
if(isset($_SERVER['HTTPS']))
253
- $url='https://'.$url;
254
else
255
- $url='http://'.$url;
256
- $url=qtranxf_convertURL($url,$lang,false,true);
257
- header('Location: '.$url);
258
- exit();
259
}
260
-
261
return $result;
262
}
263
264
function qtranxf_validateBool($var, $default) {
265
if($var==='0') return false; elseif($var==='1') return true; else return $default;
266
}
267
268
// loads config via get_option and defaults to values set on top
269
function qtranxf_loadConfig() {
270
global $q_config;
@@ -285,12 +389,11 @@ function qtranxf_loadConfig() {
285
$use_strftime = get_option('qtranslate_use_strftime');
286
$ignore_file_types = get_option('qtranslate_ignore_file_types');
287
$url_mode = get_option('qtranslate_url_mode');
288
- $detect_browser_language = get_option('qtranslate_detect_browser_language');
289
- $hide_untranslated = get_option('qtranslate_hide_untranslated');
290
- $auto_update_mo = get_option('qtranslate_auto_update_mo');
291
$term_name = get_option('qtranslate_term_name');
292
- $hide_default_language = get_option('qtranslate_hide_default_language');
293
- $custom_fields = get_option('qtranslate_custom_fields');
294
295
// default if not set
296
if(!is_array($date_formats)) $date_formats = $q_config['date_format'];
@@ -301,17 +404,36 @@ function qtranxf_loadConfig() {
301
if(!is_array($language_names)) $language_names = $q_config['language_name'];
302
if(!is_array($enabled_languages)) $enabled_languages = $q_config['enabled_languages'];
303
if(!is_array($term_name)) $term_name = $q_config['term_name'];
304
- if(!is_array($custom_fields)) $custom_fields = array();
305
- if(empty($ignore_file_types)) $ignore_file_types = $q_config['ignore_file_types'];
306
if(empty($default_language)) $default_language = $q_config['default_language'];
307
if(empty($use_strftime)) $use_strftime = $q_config['use_strftime'];
308
if(empty($url_mode)) $url_mode = $q_config['url_mode'];
309
if(!is_string($flag_location) || $flag_location==='') $flag_location = $q_config['flag_location'];
310
$detect_browser_language = qtranxf_validateBool($detect_browser_language, $q_config['detect_browser_language']);
311
$hide_untranslated = qtranxf_validateBool($hide_untranslated, $q_config['hide_untranslated']);
312
$auto_update_mo = qtranxf_validateBool($auto_update_mo, $q_config['auto_update_mo']);
313
$hide_default_language = qtranxf_validateBool($hide_default_language, $q_config['hide_default_language']);
314
-
315
// url fix for upgrading users
316
$flag_location = trailingslashit(preg_replace('#^wp-content/#','',$flag_location));
317
@@ -330,23 +452,45 @@ function qtranxf_loadConfig() {
330
$q_config['default_language'] = $default_language;
331
$q_config['flag_location'] = $flag_location;
332
$q_config['use_strftime'] = $use_strftime;
333
- $q_config['ignore_file_types'] = $ignore_file_types;
334
$q_config['url_mode'] = $url_mode;
335
- $q_config['detect_browser_language'] = $detect_browser_language;
336
- $q_config['hide_untranslated'] = $hide_untranslated;
337
- $q_config['auto_update_mo'] = $auto_update_mo;
338
- $q_config['hide_default_language'] = $hide_default_language;
339
$q_config['term_name'] = $term_name;
340
- $q_config['custom_fields'] = $custom_fields;
341
342
do_action('qtranslate_loadConfig');
343
}
344
345
- // saves entire configuration