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-->)+$/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-->)+$/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\/([^\/]*))$/);
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-->)+$/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-->)+$/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\/([^\/]*))$/);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\/([^\/]*))$/);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
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  function qtranxf_saveConfig() {
347
  global $q_config;
348
 
349
- // save everything
350
  update_option('qtranslate_language_names', $q_config['language_name']);
351
  update_option('qtranslate_enabled_languages', $q_config['enabled_languages']);
352
  update_option('qtranslate_default_language', $q_config['default_language']);
@@ -356,28 +500,21 @@ function qtranxf_saveConfig() {
356
  update_option('qtranslate_na_messages', $q_config['not_available']);
357
  update_option('qtranslate_date_formats', $q_config['date_format']);
358
  update_option('qtranslate_time_formats', $q_config['time_format']);
359
- update_option('qtranslate_ignore_file_types', $q_config['ignore_file_types']);
360
  update_option('qtranslate_url_mode', $q_config['url_mode']);
361
  update_option('qtranslate_term_name', $q_config['term_name']);
362
  update_option('qtranslate_use_strftime', $q_config['use_strftime']);
363
- update_option('qtranslate_custom_fields', $q_config['custom_fields']);
364
- if($q_config['detect_browser_language'])
365
- update_option('qtranslate_detect_browser_language', '1');
366
- else
367
- update_option('qtranslate_detect_browser_language', '0');
368
- if($q_config['hide_untranslated'])
369
- update_option('qtranslate_hide_untranslated', '1');
370
- else
371
- update_option('qtranslate_hide_untranslated', '0');
372
- if($q_config['auto_update_mo'])
373
- update_option('qtranslate_auto_update_mo', '1');
374
- else
375
- update_option('qtranslate_auto_update_mo', '0');
376
- if($q_config['hide_default_language'])
377
- update_option('qtranslate_hide_default_language', '1');
378
- else
379
- update_option('qtranslate_hide_default_language', '0');
380
-
381
  do_action('qtranslate_saveConfig');
382
  }
383
 
@@ -409,15 +546,17 @@ function qtranxf_updateGettextDatabaseFiles($lcr,$locale,$dstdir,$srcdir){
409
  $mo=$dstdir.$locale.'.mo';
410
  qtranxf_updateGettextDatabaseFile($lcr,$mo);
411
  }
412
- if(!$m) return;
413
  }
414
 
415
  function qtranxf_updateGettextDatabase($locale,$repository){
 
416
  $dstdir=trailingslashit(WP_LANG_DIR);
417
  $tmpfile=$dstdir.$locale.'.mo.filepart';
418
  if(!$ll = @fopen($tmpfile,'a'))
419
  return false; // cannot access .mo file
420
  fclose($ll);
 
421
  $wp_version = $GLOBALS['wp_version'];
422
  // try to find a .mo file
423
  if(!($locale == 'en_US' && $lcr=@fopen('http://www.qianqin.de/wp-content/languages/'.$locale.'.mo','r')))
@@ -615,26 +754,56 @@ function qtranxf_convertBlogInfoURL($url, $what) {
615
  return qtranxf_convertURL($url);
616
  }
617
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
618
  if (!function_exists('qtranxf_convertURL')){
619
  function qtranxf_convertURL($url='', $lang='', $forceadmin = false, $showDefaultLanguage = false) {
620
  global $q_config;
621
-
622
  // invalid language
623
  if($url=='') $url = esc_url($q_config['url_info']['url']);
624
  if($lang=='') $lang = $q_config['language'];
625
  if(defined('WP_ADMIN')&&!$forceadmin) return $url;
626
  if(!qtranxf_isEnabled($lang)) return "";
627
-
628
  // & workaround
629
  $url = str_replace('&amp;','&',$url);
630
  $url = str_replace('&#038;','&',$url);
631
-
632
  // check for trailing slash
633
  $nottrailing = (strpos($url,'?')===false && strpos($url,'#')===false && substr($url,-1,1)!='/');
634
-
635
  // check if it's an external link
636
  $urlinfo = qtranxf_parseURL($url);
637
- $home = rtrim(get_option('home'),"/");
638
  if($urlinfo['host']!='') {
639
  // check for already existing pre-domain language information
640
  if($q_config['url_mode'] == QTX_URL_DOMAIN && preg_match("#^([a-z]{2}).#i",$urlinfo['host'],$match)) {
@@ -657,33 +826,35 @@ function qtranxf_convertURL($url='', $lang='', $forceadmin = false, $showDefault
657
  $url = substr($url,strlen($homeinfo['path']));
658
  }
659
  }
660
-
661
  // check for query language information and remove if found
662
  if(preg_match("#(&|\?)lang=([^&\#]+)#i",$url,$match) && qtranxf_isEnabled($match[2])) {
663
  $url = preg_replace("#(&|\?)lang=".$match[2]."&?#i","$1",$url);
664
  }
665
-
666
  // remove any slashes out front
667
  $url = ltrim($url,"/");
668
-
669
  // remove any useless trailing characters
670
  $url = rtrim($url,"?&");
671
 
672
- // reparse url without home path
673
  $urlinfo = qtranxf_parseURL($url);
674
-
675
  // check if its a link to an ignored file type
676
- $ignore_file_types = preg_split('/\s*,\s*/', strtolower($q_config['ignore_file_types']));
677
- $pathinfo = pathinfo($urlinfo['path']);
678
- if(isset($pathinfo['extension']) && in_array(strtolower($pathinfo['extension']), $ignore_file_types)) {
679
- return $home."/".$url;
680
- }
 
681
 
682
  // ignore wp internal links
683
- if(preg_match("#^(wp-login.php|wp-signup.php|wp-register.php|wp-admin/)#", $url)) {
 
684
  return $home."/".$url;
685
  }
686
-
687
  switch($q_config['url_mode']) {
688
  case QTX_URL_PATH: // pre url
689
  // might already have language information
@@ -699,7 +870,7 @@ function qtranxf_convertURL($url='', $lang='', $forceadmin = false, $showDefault
699
  if(!$q_config['hide_default_language']||$lang!=$q_config['default_language']) $home = preg_replace("#//#","//".$lang.".",$home,1);
700
  break;
701
  default: // query
702
- if(!$q_config['hide_default_language']||$lang!=$q_config['default_language']){
703
  if(strpos($url,'?')===false) {
704
  $url .= '?';
705
  } else {
@@ -708,9 +879,9 @@ function qtranxf_convertURL($url='', $lang='', $forceadmin = false, $showDefault
708
  $url .= "lang=".$lang;
709
  }
710
  }
711
-
712
  // see if cookies are activated
713
- if(!$q_config['cookie_enabled'] && !$q_config['url_info']['internal_referer'] && $urlinfo['path'] == '' && $lang == $q_config['default_language'] && $q_config['language'] != $q_config['default_language'] && $q_config['hide_default_language']) {
714
  // :( now we have to make unpretty URLs
715
  $url = preg_replace("#(&|\?)lang=".$match[2]."&?#i","$1",$url);
716
  if(strpos($url,'?')===false) {
@@ -720,14 +891,14 @@ function qtranxf_convertURL($url='', $lang='', $forceadmin = false, $showDefault
720
  }
721
  $url .= "lang=".$lang;
722
  }
723
-
724
  // &amp; workaround
725
  $complete = str_replace('&','&amp;',$home."/".$url);
726
 
727
  // remove trailing slash if there wasn't one to begin with
728
  if($nottrailing && strpos($complete,'?')===false && strpos($complete,'#')===false && substr($complete,-1,1)=='/')
729
  $complete = substr($complete,0,-1);
730
-
731
  return $complete;
732
  }
733
  }
@@ -884,13 +1055,25 @@ function qtranxf_use($lang, $text, $show_available=false) {
884
  // content not available in requested language (bad!!) what now?
885
  if(!$show_available){
886
  // check if content is available in default language, if not return first language found. (prevent empty result)
887
- if($lang!=$q_config['default_language'])
888
- return "(".$q_config['language_name'][$q_config['default_language']].") ".qtranxf_use($q_config['default_language'], $text, $show_available);
 
 
 
 
 
 
 
 
 
 
889
  foreach($content as $language => $lang_text) {
890
  $lang_text = trim($lang_text);
891
- if(!empty($lang_text)) {
 
892
  return "(".$q_config['language_name'][$language].") ".$lang_text;
893
- }
 
894
  }
895
  }
896
  // display selection for available languages
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
  /* qTranslate Functions */
24
 
25
  function qtranxf_init() {
31
  do_action('qtranxf_init_begin');
32
 
33
  qtranxf_loadConfig();
34
+
35
+ if(defined('WP_ADMIN')){
36
+ // update Gettext Databases if on Backend
37
+ if($q_config['auto_update_mo']) qtranxf_updateGettextDatabases();
38
+ // update definitions if neccesary
39
+ if(current_user_can('manage_categories')) qtranxf_updateTermLibrary();
40
+ $q_config['cookie_enabled']=isset($_COOKIE[QTX_COOKIE_NAME_ADMIN]);
41
+ }else{
42
+ $q_config['cookie_enabled']=isset($_COOKIE[QTX_COOKIE_NAME_FRONT]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
+
45
+ $host=$_SERVER['HTTP_HOST'];
46
+ //on different port, it will not work for now
47
+ //if(isset($_SERVER['SERVER_PORT']) && !empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT']!='80'){
48
+ // $host.=':'.$_SERVER['SERVER_PORT'];
49
+ //}
50
+ //qtranxf_dbg_log('qtranxf_init: IP='.$_SERVER['REMOTE_ADDR']);
51
+ //qtranxf_dbg_log('qtranxf_init: URL='.$host.$_SERVER['REQUEST_URI']);
52
+ //qtranxf_dbg_log('qtranxf_init: POST: ',$_POST);
53
+ $q_config['url_info'] = qtranxf_detect_language($_SERVER['REQUEST_URI'], $host, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
54
+ //qtranxf_dbg_log('qtranxf_init: url_info: ',$q_config['url_info']);
55
+
56
+ $q_config['language'] = $q_config['url_info']['language'];
57
  $q_config['language'] = apply_filters('qtranslate_language', $q_config['language']);
58
+
59
+ /*
60
+ // Check for WP Secret Key Mismatch
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  global $wp_default_secret_key;
62
  if(strpos($q_config['url_info']['url'],'wp-login.php')!==false && defined('AUTH_KEY') && isset($wp_default_secret_key) && $wp_default_secret_key != AUTH_KEY) {
63
  global $error;
64
  $error = __('Your $wp_default_secret_key is mismatchting with your AUTH_KEY. This might cause you not to be able to login anymore.', 'qtranslate');
65
  }
66
+ */
67
+
68
  // Filter all options for language tags
69
  if(!defined('WP_ADMIN')) {
70
  $alloptions = wp_load_alloptions();
72
  add_filter('option_'.$option, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
73
  }
74
  }
75
+
76
  // load plugin translations
77
  load_plugin_textdomain('qtranslate', false, dirname(plugin_basename( __FILE__ )).'/lang');
78
+
79
  // remove traces of language (or better not?)
80
  //unset($_GET['lang']);
81
+ //qtranxf_dbg_log('qtranxf_init: REQUEST_URI='.$_SERVER['REQUEST_URI']);
82
+ //$_SERVER['REQUEST_URI'] = $q_config['url_info']['url'];
83
+ //$_SERVER['HTTP_HOST'] = $q_config['url_info']['host'];
84
+ //qtranxf_dbg_log('qtranxf_init: REQUEST_URI='.$_SERVER['REQUEST_URI']);
85
+
86
  // fix url to prevent xss
87
  $q_config['url_info']['url'] = qtranxf_convertURL(add_query_arg('lang',$q_config['default_language'],$q_config['url_info']['url']));
88
 
89
+ if($q_config['qtrans_compatibility']){
90
+ require_once(dirname(__FILE__)."/qtranslate_compatibility.php");
91
+ }
92
+
93
  //allow other plugins to initialize whatever they need
94
  do_action('qtranxf_init');
95
 
96
+ /*
97
+ //"WordPress SEO" plugin support - not yet
98
  //if(is_plugin_active( 'wordpress-seo/wp-seo.php' )){//in admin only
99
  if ( defined( 'WPSEO_FILE' ) ) {
100
  //add_filter('wpseo_replacements', 'qtranxf_wpseo_replacements', 0);
101
  add_filter('wpseo_replacements', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0);
102
+ }
103
+ */
104
+ //qtranxf_dbg_log('qtranxf_init: url_info.url='.$q_config['url_info']['url']);
105
+ //qtranxf_dbg_log('qtranxf_init: language='.$q_config['language']);
106
  }
107
 
108
  function qtranxf_resolveLangCase($lang,&$caseredirect)
121
  return FALSE;
122
  }
123
 
124
+ function qtranxf_get_language_cookie()
125
+ {
126
+ if(defined('WP_ADMIN')){
127
+ if(isset($_COOKIE[QTX_COOKIE_NAME_ADMIN])) return $_COOKIE[QTX_COOKIE_NAME_ADMIN];
128
+ }else{
129
+ if(isset($_COOKIE[QTX_COOKIE_NAME_FRONT])) return $_COOKIE[QTX_COOKIE_NAME_FRONT];
130
+ }
131
+ return false;
132
+ }
133
+
134
+ function qtranxf_set_language_cookie($lang,$cookie_path)
135
+ {
136
+ if(defined('WP_ADMIN')){
137
+ $cookie_name = QTX_COOKIE_NAME_ADMIN;
138
+ $cookie_path = trailingslashit($cookie_path).'wp-admin';
139
+ }else{
140
+ $cookie_name = QTX_COOKIE_NAME_FRONT;
141
+ if(strlen($cookie_path)>1)
142
+ $cookie_path=untrailingslashit($cookie_path);
143
+ }
144
+ //qtranxf_dbg_log('qtranxf_set_language_cookie: COOKIEPATH='.COOKIEPATH.'; cookie_path='.$cookie_path.'; lang='.$lang);
145
+ setcookie($cookie_name, $lang, time()+31536000, $cookie_path);//one year
146
+ //two weeks 1209600
147
+ }
148
+
149
  // returns cleaned string and language information
150
+ //former qtranxf_extractURL
151
+ function qtranxf_detect_language($url, $host, $referer) {
152
  global $q_config;
153
  $home = qtranxf_parseURL(get_option('home'));
154
+ $home['path'] = isset($home['path'])?trailingslashit($home['path']):'/';
155
  $referer = qtranxf_parseURL($referer);
156
 
157
  $result = array();
158
+ //$result['language'] = $q_config['default_language'];
159
  $result['url'] = $url;
160
  $result['original_url'] = $url;
161
  $result['host'] = $host;
162
  $result['redirect'] = false;
163
  $result['internal_referer'] = false;
164
  $result['home'] = $home['path'];
 
165
 
166
+ $doredirect=false;
167
+ $lang_url=null;
168
  switch($q_config['url_mode']) {
169
  case QTX_URL_PATH:
170
  // pre url
172
  if($url) {
173
  // might have language information
174
  if(preg_match("#^([a-z]{2})(/.*)?$#i",$url,$match)) {
175
+ $lang_url = qtranxf_resolveLangCase($match[1],$doredirect);
176
+ if($lang_url){
177
  // found language information
178
+ //$result['language'] = $lang_url;
179
  $result['url'] = $home['path'].substr($url, 3);
180
  }
181
  }
185
  // pre domain
186
  if($host) {
187
  if(preg_match("#^([a-z]{2}).#i",$host,$match)) {
188
+ $lang_url = qtranxf_resolveLangCase($match[1],$doredirect);
189
+ if($lang_url){
190
  // found language information
191
+ //$result['language'] = $lang_url;
192
  $result['host'] = substr($host, 3);
193
  }
194
  }
195
  }
196
+ default: break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  }
198
+ //qtranxf_dbg_log('qtranxf_detect_language: url='.$url);
199
+ //qtranxf_dbg_log('qtranxf_detect_language: lang_url='.$lang_url);
200
 
201
+ // check if referrer is internal
202
+ if( $referer['host']==$result['host'] && qtranxf_startsWith($referer['path'], $home['path']) ) {
203
  // user coming from internal link
204
  $result['internal_referer'] = true;
205
  }
206
 
207
+ $lang=null;
208
+ if(isset($_GET['lang'])){// language override given
209
+ $lang = qtranxf_resolveLangCase($_GET['lang'],$doredirect);
210
  if($lang){
 
 
211
  $result['url'] = preg_replace("#(&|\?)lang=".$lang."&?#i","$1",$result['url']);
212
  $result['url'] = preg_replace("#[\?\&]+$#i","",$result['url']);
213
+ } elseif($home['host'] == $result['host'] && $home['path'] == $result['url']) {
214
  if(empty($referer['host'])||!$q_config['hide_default_language']) {
215
  $result['redirect'] = true;
216
  }else{
217
  // check if activating language detection is possible
218
  if(preg_match("#^([a-z]{2}).#i",$referer['host'],$match)) {
219
+ $cs=false;
220
  $lang = qtranxf_resolveLangCase($match[1],$cs);
221
  if($lang) {
222
  // found language information
231
  }
232
  }
233
 
234
+ if($lang){
235
+ //qtranxf_dbg_log('qtranxf_detect_language: GET[lang]='.$lang);
236
+ if($lang_url && $lang !== $lang_url) $doredirect=true;
237
+ }else if($lang_url){
238
+ $lang = $lang_url;
239
+ if($q_config['hide_default_language'] && $lang_url == $q_config['default_language'])
240
+ $doredirect=true;
241
+ }else{
242
+ $lang=qtranxf_get_language_cookie();
243
+ if($lang){
244
+ $cs=false;
245
+ $lang=qtranxf_resolveLangCase($lang,$cs);
246
+ //qtranxf_dbg_log('qtranxf_detect_language: cookie: lang='.$lang);
247
+ }
248
+
249
+ if(!$lang && $q_config['detect_browser_language']){
250
+ $lang=qtranxf_http_negotiate_language();
251
+ //qtranxf_dbg_log('qtranxf_detect_language: browser: lang='.$lang);
252
+ }
253
+
254
+ if(!$lang)
255
+ $lang = $q_config['default_language'];
256
+
257
+ if(!defined('WP_ADMIN') && !defined('DOING_CRON')
258
+ && (!$q_config['hide_default_language'] || $lang != $q_config['default_language'])
259
+ ){
260
+ $url_parsed=parse_url($url);
261
+ //qtranxf_dbg_log('qtranxf_detect_language: url_parsed:',$url_parsed);
262
+ $b=false;
263
+ if(isset($url_parsed['path'])){
264
+ $path=$url_parsed['path'];
265
+ $b=qtranxf_language_nutral_path($path);
266
+ }
267
+ if(!$b){
268
+ //qtranxf_dbg_log('qtranxf_detect_language: ignored_file_type=false; path='.$path);
269
+ $doredirect=true;
270
+ //}else{
271
+ // qtranxf_dbg_log('qtranxf_detect_language: ignored_file_type=true; path='.$path);
272
+ }
273
+ }
274
+ }
275
+
276
+ if($doredirect){
277
+ $urlto=$result['host'].$result['url'];
278
  if(isset($_SERVER['HTTPS']))
279
+ $urlto='https://'.$urlto;
280
  else
281
+ $urlto='http://'.$urlto;
282
+ //if(isset($_SERVER['QUERY_STRING'])) $url=
283
+ $target=qtranxf_convertURL($urlto,$lang,false,!$q_config['hide_default_language']);
284
+ $target = apply_filters('qtranslate_language_detect_redirect', $target, $result);
285
+ if($target!==false){
286
+ //qtranxf_dbg_log('qtranxf_detect_language:doredirect: url='.$url);
287
+ //qtranxf_dbg_log('qtranxf_detect_language:doredirect: target='.$target);
288
+ //qtranxf_dbg_log('qtranxf_detect_language:doredirect: POST: ',$_POST);
289
+ $url_parsed=parse_url($url);
290
+ $tgt_parsed=parse_url($target);
291
+ if(isset($url_parsed['path']) && isset($tgt_parsed['path']) && $url_parsed['path'] != $tgt_parsed['path']){
292
+ qtranxf_set_language_cookie($lang,$result['home']);
293
+ wp_redirect($target);
294
+ //header('Location: '.$target);
295
+ exit();
296
+ //}else{
297
+ // qtranxf_dbg_log('qtranxf_detect_language:doredirect: cancelled');
298
+ }
299
+ }
300
  }
301
+ //if(!$lang) $lang = $q_config['default_language'];
302
+ qtranxf_set_language_cookie($lang,$result['home']);
303
+ $result['language'] = $lang;
304
  return $result;
305
  }
306
 
307
+ function qtranxf_get_browser_language(){
308
+ //qtranxf_dbg_log('qtranxf_get_browser_language: HTTP_ACCEPT_LANGUAGE:',$_SERVER["HTTP_ACCEPT_LANGUAGE"]);
309
+ if(!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) return null;
310
+ if(!preg_match_all("#([^;,]+)(;[^,0-9]*([0-9\.]+)[^,]*)?#i",$_SERVER["HTTP_ACCEPT_LANGUAGE"], $matches, PREG_SET_ORDER)) return null;
311
+ $prefered_languages = array();
312
+ $priority = 1.0;
313
+ foreach($matches as $match) {
314
+ if(!isset($match[3])) {
315
+ $pr = $priority;
316
+ $priority -= 0.001;
317
+ } else {
318
+ $pr = floatval($match[3]);
319
+ }
320
+ $prefered_languages[$match[1]] = $pr;
321
+ }
322
+ arsort($prefered_languages, SORT_NUMERIC);
323
+ //qtranxf_dbg_echo('qtranxf_get_browser_language: prefered_languages:',$prefered_languages);
324
+ foreach($prefered_languages as $language => $priority) {
325
+ if(strlen($language)>2) $language = substr($language,0,2);
326
+ if(qtranxf_isEnabled($language))
327
+ return $language;
328
+ }
329
+ }
330
+
331
+ function qtranxf_http_negotiate_language(){
332
+ if(function_exists('http_negotiate_language')){
333
+ $supported=array();
334
+ $supported[]=str_replace('_','-',$q_config['locale'][$q_config['default_language']]);
335
+ foreach($q_config['available_languages'] as $lang){
336
+ $supported[]=str_replace('_','-',$q_config['locale'][$lang]);
337
+ }
338
+ $lang = http_negotiate_language($supported);
339
+ //qtranxf_dbg_log('qtranxf_http_negotiate_language:http_negotiate_language: lang='.$lang);
340
+ }else{
341
+ $lang = qtranxf_get_browser_language();
342
+ //qtranxf_dbg_log('qtranxf_http_negotiate_language:qtranxf_get_browser_language: lang='.$lang);
343
+ }
344
+ return $lang;
345
+ }
346
+
347
  function qtranxf_validateBool($var, $default) {
348
  if($var==='0') return false; elseif($var==='1') return true; else return $default;
349
  }
350
 
351
+ function qtranxf_load_option($nm) {
352
+ global $q_config;
353
+ $val = get_option('qtranslate_'.$nm);
354
+ if(empty($val)) return;
355
+ $q_config[$nm]=$val;
356
+ }
357
+
358
+ function qtranxf_load_option_array($nm) {
359
+ global $q_config;
360
+ $val = get_option('qtranslate_'.$nm);
361
+ if(!is_array($val)) return;
362
+ $q_config[$nm]=$val;
363
+ }
364
+
365
+ function qtranxf_load_option_bool($nm) {
366
+ global $q_config;
367
+ $val = get_option('qtranslate_'.$nm);
368
+ if($val==='0') $q_config[$nm] = false;
369
+ elseif($val==='1') $q_config[$nm] = true;
370
+ }
371
+
372
  // loads config via get_option and defaults to values set on top
373
  function qtranxf_loadConfig() {
374
  global $q_config;
389
  $use_strftime = get_option('qtranslate_use_strftime');
390
  $ignore_file_types = get_option('qtranslate_ignore_file_types');
391
  $url_mode = get_option('qtranslate_url_mode');
 
 
 
392
  $term_name = get_option('qtranslate_term_name');
393
+
394
+ qtranxf_load_option_array('custom_fields');
395
+ qtranxf_load_option_array('custom_field_classes');
396
+ qtranxf_load_option_array('text_field_filters');
397
 
398
  // default if not set
399
  if(!is_array($date_formats)) $date_formats = $q_config['date_format'];
404
  if(!is_array($language_names)) $language_names = $q_config['language_name'];
405
  if(!is_array($enabled_languages)) $enabled_languages = $q_config['enabled_languages'];
406
  if(!is_array($term_name)) $term_name = $q_config['term_name'];
 
 
407
  if(empty($default_language)) $default_language = $q_config['default_language'];
408
  if(empty($use_strftime)) $use_strftime = $q_config['use_strftime'];
409
  if(empty($url_mode)) $url_mode = $q_config['url_mode'];
410
  if(!is_string($flag_location) || $flag_location==='') $flag_location = $q_config['flag_location'];
411
+
412
+ qtranxf_load_option_bool('detect_browser_language');
413
+ qtranxf_load_option_bool('hide_untranslated');
414
+ qtranxf_load_option_bool('show_displayed_language_prefix');
415
+ qtranxf_load_option_bool('auto_update_mo');
416
+ qtranxf_load_option_bool('hide_default_language');
417
+ qtranxf_load_option_bool('qtrans_compatibility');
418
+ /*
419
+ $detect_browser_language = get_option('qtranslate_detect_browser_language');
420
+ $hide_untranslated = get_option('qtranslate_hide_untranslated');
421
+ $show_displayed_language_prefix = get_option('qtranslate_show_displayed_language_prefix');
422
+ $auto_update_mo = get_option('qtranslate_auto_update_mo');
423
+ $hide_default_language = get_option('qtranslate_hide_default_language');
424
+
425
  $detect_browser_language = qtranxf_validateBool($detect_browser_language, $q_config['detect_browser_language']);
426
  $hide_untranslated = qtranxf_validateBool($hide_untranslated, $q_config['hide_untranslated']);
427
+ $show_displayed_language_prefix = qtranxf_validateBool($show_displayed_language_prefix, $q_config['show_displayed_language_prefix']);
428
  $auto_update_mo = qtranxf_validateBool($auto_update_mo, $q_config['auto_update_mo']);
429
  $hide_default_language = qtranxf_validateBool($hide_default_language, $q_config['hide_default_language']);
430
+
431
+ $q_config['detect_browser_language'] = $detect_browser_language;
432
+ $q_config['hide_untranslated'] = $hide_untranslated;
433
+ $q_config['show_displayed_language_prefix'] = $show_displayed_language_prefix;
434
+ $q_config['auto_update_mo'] = $auto_update_mo;
435
+ $q_config['hide_default_language'] = $hide_default_language;
436
+ */
437
  // url fix for upgrading users
438
  $flag_location = trailingslashit(preg_replace('#^wp-content/#','',$flag_location));
439
 
452
  $q_config['default_language'] = $default_language;
453
  $q_config['flag_location'] = $flag_location;
454
  $q_config['use_strftime'] = $use_strftime;
455
+
456
+ //$q_config['ignore_file_types'] = $ignore_file_types;
457
+ $val=explode(',',QTX_IGNORE_FILE_TYPES);
458
+ if(!empty($ignore_file_types)){
459
+ $vals=preg_split('/[\s,]+/', strtolower($ignore_file_types));
460
+ foreach($vals as $v){
461
+ if(empty($v)) continue;
462
+ if(in_array($v,$val)) continue;
463
+ $val[]=$v;
464
+ }
465
+ }
466
+ $q_config['ignore_file_types'] = $val;
467
+
468
  $q_config['url_mode'] = $url_mode;
 
 
 
 
469
  $q_config['term_name'] = $term_name;
 
470
 
471
+ foreach($q_config['text_field_filters'] as $nm){
472
+ add_filter($nm, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
473
+ }
474
  do_action('qtranslate_loadConfig');
475
  }
476
 
477
+ function qtranxf_update_option($nm) {
478
+ global $q_config;
479
+ update_option('qtranslate_'.$nm, $q_config[$nm]);
480
+ }
481
+
482
+ function qtranxf_update_option_bool($nm) {
483
+ global $q_config;
484
+ if($q_config[$nm])
485
+ update_option('qtranslate_'.$nm, '1');
486
+ else
487
+ update_option('qtranslate_'.$nm, '0');
488
+ }
489
+
490
+ // saves entire configuration - it should be in admin only?
491
  function qtranxf_saveConfig() {
492
  global $q_config;
493
 
 
494
  update_option('qtranslate_language_names', $q_config['language_name']);
495
  update_option('qtranslate_enabled_languages', $q_config['enabled_languages']);
496
  update_option('qtranslate_default_language', $q_config['default_language']);
500
  update_option('qtranslate_na_messages', $q_config['not_available']);
501
  update_option('qtranslate_date_formats', $q_config['date_format']);
502
  update_option('qtranslate_time_formats', $q_config['time_format']);
503
+ update_option('qtranslate_ignore_file_types', implode(',',$q_config['ignore_file_types']));
504
  update_option('qtranslate_url_mode', $q_config['url_mode']);
505
  update_option('qtranslate_term_name', $q_config['term_name']);
506
  update_option('qtranslate_use_strftime', $q_config['use_strftime']);
507
+
508
+ qtranxf_update_option('custom_fields');
509
+ qtranxf_update_option('custom_field_classes');
510
+ qtranxf_update_option('text_field_filters');
511
+
512
+ qtranxf_update_option_bool('detect_browser_language');
513
+ qtranxf_update_option_bool('hide_untranslated');
514
+ qtranxf_update_option_bool('show_displayed_language_prefix');
515
+ qtranxf_update_option_bool('auto_update_mo');
516
+ qtranxf_update_option_bool('hide_default_language');
517
+
 
 
 
 
 
 
 
518
  do_action('qtranslate_saveConfig');
519
  }
520
 
546
  $mo=$dstdir.$locale.'.mo';
547
  qtranxf_updateGettextDatabaseFile($lcr,$mo);
548
  }
549
+ if(!$srcdir) return;
550
  }
551
 
552
  function qtranxf_updateGettextDatabase($locale,$repository){
553
+ //wp_download_language_pack() - todo: use this function
554
  $dstdir=trailingslashit(WP_LANG_DIR);
555
  $tmpfile=$dstdir.$locale.'.mo.filepart';
556
  if(!$ll = @fopen($tmpfile,'a'))
557
  return false; // cannot access .mo file
558
  fclose($ll);
559
+ $m='';
560
  $wp_version = $GLOBALS['wp_version'];
561
  // try to find a .mo file
562
  if(!($locale == 'en_US' && $lcr=@fopen('http://www.qianqin.de/wp-content/languages/'.$locale.'.mo','r')))
754
  return qtranxf_convertURL($url);
755
  }
756
 
757
+ // check if it is a link to an ignored file type
758
+ function qtranxf_ignored_file_type($path) {
759
+ global $q_config;
760
+ //$pathinfo = pathinfo($path);//too much overhead
761
+ //qtranxf_dbg_echo('qtranxf_ignored_file_type: pathinfo:',$pathinfo);
762
+ //if(!isset($pathinfo['extension'])) return false;
763
+ //$ext=strtolower($pathinfo['extension']);
764
+ $i=strpos($path,'?');
765
+ if($i!==FALSE){
766
+ $path=substr($path,0,$i);
767
+ }
768
+ $i=strpos($path,'#');
769
+ if($i!==FALSE){
770
+ $path=substr($path,0,$i);
771
+ }
772
+ $i=strrpos($path,'.');
773
+ //qtranxf_dbg_echo('qtranxf_ignored_file_type: path='.$path.'; i='.$i);
774
+ if($i===FALSE) return false;
775
+ $ext=substr($path,$i+1);
776
+ //qtranxf_dbg_echo('qtranxf_ignored_file_type: ext='.$ext);
777
+ return in_array($ext, $q_config['ignore_file_types']);
778
+ }
779
+
780
+ function qtranxf_language_nutral_path($path) {
781
+ //qtranxf_dbg_echo('qtranxf_language_nutral_path: path='.$path);
782
+ if(preg_match("#^(wp-login.php|wp-signup.php|wp-register.php|wp-cron.php|wp-admin/)#", $path)) return true;
783
+ if(qtranxf_ignored_file_type($path)) return true;
784
+ return false;
785
+ }
786
+
787
  if (!function_exists('qtranxf_convertURL')){
788
  function qtranxf_convertURL($url='', $lang='', $forceadmin = false, $showDefaultLanguage = false) {
789
  global $q_config;
790
+
791
  // invalid language
792
  if($url=='') $url = esc_url($q_config['url_info']['url']);
793
  if($lang=='') $lang = $q_config['language'];
794
  if(defined('WP_ADMIN')&&!$forceadmin) return $url;
795
  if(!qtranxf_isEnabled($lang)) return "";
796
+
797
  // & workaround
798
  $url = str_replace('&amp;','&',$url);
799
  $url = str_replace('&#038;','&',$url);
800
+
801
  // check for trailing slash
802
  $nottrailing = (strpos($url,'?')===false && strpos($url,'#')===false && substr($url,-1,1)!='/');
803
+
804
  // check if it's an external link
805
  $urlinfo = qtranxf_parseURL($url);
806
+ $home = rtrim(get_option('home'),'/');
807
  if($urlinfo['host']!='') {
808
  // check for already existing pre-domain language information
809
  if($q_config['url_mode'] == QTX_URL_DOMAIN && preg_match("#^([a-z]{2}).#i",$urlinfo['host'],$match)) {
826
  $url = substr($url,strlen($homeinfo['path']));
827
  }
828
  }
829
+
830
  // check for query language information and remove if found
831
  if(preg_match("#(&|\?)lang=([^&\#]+)#i",$url,$match) && qtranxf_isEnabled($match[2])) {
832
  $url = preg_replace("#(&|\?)lang=".$match[2]."&?#i","$1",$url);
833
  }
834
+
835
  // remove any slashes out front
836
  $url = ltrim($url,"/");
837
+
838
  // remove any useless trailing characters
839
  $url = rtrim($url,"?&");
840
 
841
+ // re-parse url without home path
842
  $urlinfo = qtranxf_parseURL($url);
843
+
844
  // check if its a link to an ignored file type
845
+ //$ignore_file_types = preg_split('/\s*,\s*/', strtolower($q_config['ignore_file_types']));
846
+ //$pathinfo = pathinfo($urlinfo['path']);
847
+ //if(isset($pathinfo['extension']) && in_array(strtolower($pathinfo['extension']), $ignore_file_types)) {
848
+ //if(qtranxf_ignored_file_type($urlinfo['path'])){
849
+ // return $home."/".$url;
850
+ //}
851
 
852
  // ignore wp internal links
853
+ //if(preg_match("#^(wp-login.php|wp-signup.php|wp-register.php|wp-admin/)#", $url)) {
854
+ if(qtranxf_language_nutral_path($url)) {
855
  return $home."/".$url;
856
  }
857
+
858
  switch($q_config['url_mode']) {
859
  case QTX_URL_PATH: // pre url
860
  // might already have language information
870
  if(!$q_config['hide_default_language']||$lang!=$q_config['default_language']) $home = preg_replace("#//#","//".$lang.".",$home,1);
871
  break;
872
  default: // query
873
+ if(!$q_config['hide_default_language'] || $lang!=$q_config['default_language'] || $showDefaultLanguage){
874
  if(strpos($url,'?')===false) {
875
  $url .= '?';
876
  } else {
879
  $url .= "lang=".$lang;
880
  }
881
  }
882
+
883
  // see if cookies are activated
884
+ if($q_config['hide_default_language'] && !$showDefaultLanguage && !$q_config['cookie_enabled'] && !$q_config['url_info']['internal_referer'] && $urlinfo['path'] == '' && $lang == $q_config['default_language'] && $q_config['language'] != $q_config['default_language']) {
885
  // :( now we have to make unpretty URLs
886
  $url = preg_replace("#(&|\?)lang=".$match[2]."&?#i","$1",$url);
887
  if(strpos($url,'?')===false) {
891
  }
892
  $url .= "lang=".$lang;
893
  }
894
+
895
  // &amp; workaround
896
  $complete = str_replace('&','&amp;',$home."/".$url);
897
 
898
  // remove trailing slash if there wasn't one to begin with
899
  if($nottrailing && strpos($complete,'?')===false && strpos($complete,'#')===false && substr($complete,-1,1)=='/')
900
  $complete = substr($complete,0,-1);
901
+
902
  return $complete;
903
  }
904
  }
1055
  // content not available in requested language (bad!!) what now?
1056
  if(!$show_available){
1057
  // check if content is available in default language, if not return first language found. (prevent empty result)
1058
+ if($lang!=$q_config['default_language']){
1059
+ $language = $q_config['default_language'];
1060
+ //$lang_text = qtranxf_use($language, $text, $show_available);
1061
+ $lang_text = $content[$language];
1062
+ $lang_text = trim($lang_text);
1063
+ if(!empty($lang_text)){
1064
+ if ($q_config['show_displayed_language_prefix'])
1065
+ return "(".$q_config['language_name'][$language].") ".$lang_text;
1066
+ else
1067
+ return $lang_text;
1068
+ }
1069
+ }
1070
  foreach($content as $language => $lang_text) {
1071
  $lang_text = trim($lang_text);
1072
+ if(empty($lang_text)) continue;
1073
+ if ($q_config['show_displayed_language_prefix'])
1074
  return "(".$q_config['language_name'][$language].") ".$lang_text;
1075
+ else
1076
+ return $lang_text;
1077
  }
1078
  }
1079
  // display selection for available languages
qtranslate_frontend.php CHANGED
@@ -17,29 +17,108 @@
17
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
  */
19
 
20
- add_filter( 'wp_get_nav_menu_items', 'qtranxf_get_nav_menu_items', 0, 3 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  function qtranxf_get_nav_menu_items( $items, $menu, $args )
22
  {
23
  global $q_config;
24
  $language=$q_config['language'];
25
- $flag_location=$q_config['WP_CONTENT_URL'].$q_config['flag_location'];
26
  $itemid=0;
27
  $menu_order=0;
28
  $qtransmenu=null;
 
 
 
 
29
  foreach($items as $item)
30
  {
31
  if($itemid<$item->ID) $itemid=$item->ID;
32
  if($menu_order<$item->menu_order) $menu_order=$item->menu_order;
33
  if( !isset( $item->url ) || strstr( $item->url, '#qtransLangSw' ) === FALSE ) continue;
34
- $item->title=__('Language','qtranslate').':'.'&nbsp;<img src="'.$flag_location.$q_config['flag'][$language].'">';
35
- $item->url=null;
36
- //$item->classes[] = 'qtranxs-flag-'.$language;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  $item->classes[] = 'qtranxs-lang-menu';
38
  $qtransmenu = $item;
39
  }
40
  if(!$qtransmenu) return $items;
41
  foreach($q_config['enabled_languages'] as $lang)
42
  {
 
 
 
 
43
  $item=new WP_Post((object)array('ID' => ++$itemid));
44
  //$item->db_id=$item->ID;
45
  $item->menu_item_parent=$qtransmenu->ID;
@@ -49,31 +128,23 @@ function qtranxf_get_nav_menu_items( $items, $menu, $args )
49
  //$item->object_id=0;
50
  $item->type='custom';
51
  $item->type_label='Custom';
52
- $item->title='<img src="'.$flag_location.$q_config['flag'][$lang].'">&nbsp;'.$q_config['language_name'][$lang];
 
 
 
53
  $item->post_title=$item->title;
54
  $item->post_name='language-menuitem-'.$lang;
55
  if($lang!=$language)
56
  $item->url=qtranxf_convertURL($url, $lang, false, true);
57
  $item->classes=array();
58
- //$item->classes[] = 'qtranxs-flag-'.$lang;
59
  $item->classes[] = 'qtranxs-lang-menu-item';
60
  $items[]=$item;
61
  ++$menu->count;
62
  }
63
  return $items;
64
  }
65
-
66
- function qtranxf_add_lang_icons ()
67
- {
68
- global $q_config;
69
- echo "<style>\n";
70
- foreach($q_config['enabled_languages'] as $lang)
71
- {
72
- echo '.qtranxs-flag-'.$lang.' {background-image: url('.trailingslashit(WP_CONTENT_URL).$q_config['flag_location'].$q_config['flag'][$lang]."); background-repeat: no-repeat;}\n";
73
- }
74
- echo "</style>\n";
75
- }
76
- add_filter('wp_head', 'qtranxf_add_lang_icons');
77
 
78
  function qtranxf_postsFilter($posts) {
79
  if(is_array($posts)) {
@@ -106,20 +177,30 @@ function qtranxf_excludeUntranslatedPosts($where) {
106
  // don't filter untranslated posts in admin
107
  add_filter('posts_where_request', 'qtranxf_excludeUntranslatedPosts');
108
 
109
- $qtranxv_home=get_home_url().'/';
110
- function qtranxf_home_url($href)
 
 
 
 
 
 
 
 
 
 
 
 
111
  {
112
  global $qtranxv_home;
113
- if ($href===$qtranxv_home)
114
- {
115
- return qtranxf_convertURL($qtranxv_home);
116
- }
117
- else
118
- {
119
  return $href;
120
  }
121
  }
122
- add_filter('home_url', 'qtranxf_home_url');
 
123
 
124
  function qtranxf_esc_html($text) {
125
  //echo "\nqtranxf_esc_html:text=$text\n";
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
+ function qtranxf_add_lang_icons_css ()
24
+ {
25
+ global $q_config;
26
+ echo '<style type="text/css">'.PHP_EOL;
27
+ foreach($q_config['enabled_languages'] as $lang)
28
+ {
29
+ echo '.qtranxs_flag_'.$lang.' {background-image: url('.trailingslashit(WP_CONTENT_URL).$q_config['flag_location'].$q_config['flag'][$lang].'); background-repeat: no-repeat;}'.PHP_EOL;
30
+ }
31
+ do_action('qtranxf_head_add_css');
32
+ echo '</style>'.PHP_EOL;
33
+ }
34
+ //add_filter('wp_head', 'qtranxf_add_lang_icons_css');
35
+
36
+ function qtranxf_head(){
37
+ global $q_config;
38
+ echo "\n<meta http-equiv=\"Content-Language\" content=\"".str_replace('_','-',$q_config['locale'][$q_config['language']])."\" />\n";
39
+ qtranxf_add_lang_icons_css();
40
+ /*
41
+ $css = "<style type=\"text/css\" media=\"screen\">\n";
42
+ $css .=".qtranxs_flag span { display:none }\n";
43
+ $css .=".qtranxs_flag { height:12px; width:18px; display:block }\n";
44
+ $css .=".qtranxs_flag_and_text { padding-left:20px }\n";
45
+ $baseurl = WP_CONTENT_URL;
46
+ if(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == '1' || $_SERVER['HTTPS'] == 'on')) {
47
+ $baseurl = preg_replace('#^http://#','https://', $baseurl);
48
+ }
49
+ foreach($q_config['enabled_languages'] as $language) {
50
+ $css .=".qtranxs_flag_".$language." { background:url(".$baseurl.'/'.$q_config['flag_location'].$q_config['flag'][$language].") no-repeat }\n";
51
+ }
52
+ //$css .= get_option('qtranslate_widget_css',QTX_WIDGET_CSS);
53
+ $css .="</style>\n";
54
+ echo apply_filters('qtranslate_header_css',$css);
55
+ */
56
+ // skip the rest if 404 //what if the menu is still shown through 404.php?
57
+ //if(is_404()) return;
58
+ // set links to translations of current page
59
+ foreach($q_config['enabled_languages'] as $language) {
60
+ if($language != qtranxf_getLanguage())
61
+ echo '<link hreflang="'.$language.'" href="'.qtranxf_convertURL('',$language).'" rel="alternate" />'."\n";
62
+ }
63
+ }
64
+ add_action('wp_head', 'qtranxf_head');
65
+
66
  function qtranxf_get_nav_menu_items( $items, $menu, $args )
67
  {
68
  global $q_config;
69
  $language=$q_config['language'];
70
+ $flag_location=trailingslashit(WP_CONTENT_URL).$q_config['flag_location'];
71
  $itemid=0;
72
  $menu_order=0;
73
  $qtransmenu=null;
74
+ $altlang=null;
75
+ $url='';//it will keep the same page
76
+ $tp='LM';
77
+ $flags=true;
78
  foreach($items as $item)
79
  {
80
  if($itemid<$item->ID) $itemid=$item->ID;
81
  if($menu_order<$item->menu_order) $menu_order=$item->menu_order;
82
  if( !isset( $item->url ) || strstr( $item->url, '#qtransLangSw' ) === FALSE ) continue;
83
+ $qs=explode('?',$item->url);
84
+ if(count($qs)>1){
85
+ $pars=explode('&',$qs[1]);
86
+ foreach($pars as $par){
87
+ $ps=explode('=',$par);
88
+ switch($ps[0]){
89
+ case 'flags': $flags=($ps[1]!='no'); break;
90
+ case 'type': $tp=$ps[1]; break;
91
+ }
92
+ }
93
+ }
94
+ if($tp=='AL'){
95
+ foreach($q_config['enabled_languages'] as $lang){
96
+ if($lang==$language) continue;
97
+ $toplang=$lang;
98
+ $altlang=$lang;
99
+ break;
100
+ }
101
+ $item->title=$q_config['language_name'][$toplang];
102
+ $item->url=qtranxf_convertURL($url, $altlang, false, true);
103
+ }else{
104
+ $toplang=$language;
105
+ $item->title=__('Language','qtranslate');
106
+ $item->url=null;
107
+ }
108
+ if($flags){
109
+ $item->title.=':&nbsp;<img src="'.$flag_location.$q_config['flag'][$toplang].'">';
110
+ }
111
+ //$item->classes[] = 'qtranxs_flag_'.$language;
112
  $item->classes[] = 'qtranxs-lang-menu';
113
  $qtransmenu = $item;
114
  }
115
  if(!$qtransmenu) return $items;
116
  foreach($q_config['enabled_languages'] as $lang)
117
  {
118
+ if($tp=='AL'){
119
+ if($lang==$language) continue;
120
+ if($lang==$altlang ) continue;
121
+ }
122
  $item=new WP_Post((object)array('ID' => ++$itemid));
123
  //$item->db_id=$item->ID;
124
  $item->menu_item_parent=$qtransmenu->ID;
128
  //$item->object_id=0;
129
  $item->type='custom';
130
  $item->type_label='Custom';
131
+ $item->title=$q_config['language_name'][$lang];
132
+ if($flags){
133
+ $item->title='<img src="'.$flag_location.$q_config['flag'][$lang].'">&nbsp;'.$item->title;
134
+ }
135
  $item->post_title=$item->title;
136
  $item->post_name='language-menuitem-'.$lang;
137
  if($lang!=$language)
138
  $item->url=qtranxf_convertURL($url, $lang, false, true);
139
  $item->classes=array();
140
+ //$item->classes[] = 'qtranxs_flag_'.$lang;
141
  $item->classes[] = 'qtranxs-lang-menu-item';
142
  $items[]=$item;
143
  ++$menu->count;
144
  }
145
  return $items;
146
  }
147
+ add_filter( 'wp_get_nav_menu_items', 'qtranxf_get_nav_menu_items', 0, 3 );
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  function qtranxf_postsFilter($posts) {
150
  if(is_array($posts)) {
177
  // don't filter untranslated posts in admin
178
  add_filter('posts_where_request', 'qtranxf_excludeUntranslatedPosts');
179
 
180
+ function qtranxf_home_url($url, $path, $orig_scheme, $blog_id)
181
+ {
182
+ global $q_config;
183
+ //qtranxf_dbg_log('qtranxf_home_url: url='.$url.'; path='.$path.'; orig_scheme='.$orig_scheme);
184
+ $url=qtranxf_convertURL($url,'',false,!$q_config['hide_default_language']);
185
+ //if((empty($path) && $q_config['url_mode'] == QT_URL_PATH) || $path == '/' || !empty($q_config['url_info']['explicit_default_language'])){
186
+ // $url=qtranxf_convertURL($url, '', false, $q_config['url_info']['explicit_default_language']);
187
+ //}
188
+ //qtranxf_dbg_log('qtranxf_home_url: new='.$url,wp_debug_backtrace_summary(null,0,false));
189
+ return $url;
190
+ }
191
+ /*
192
+ $qtranxv_home=trailingslashit(get_home_url());
193
+ function qtranxf_home_url($url, $path, $orig_scheme, $blog_id)
194
  {
195
  global $qtranxv_home;
196
+ if ($href===$qtranxv_home){
197
+ return qtranxf_convertURL($href);
198
+ }else{
 
 
 
199
  return $href;
200
  }
201
  }
202
+ */
203
+ add_filter('home_url', 'qtranxf_home_url', 0, 4);
204
 
205
  function qtranxf_esc_html($text) {
206
  //echo "\nqtranxf_esc_html:text=$text\n";
qtranslate_hooks.php CHANGED
@@ -17,47 +17,28 @@
17
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
  */
19
 
20
- /* qTranslate-X Hooks */
 
21
 
22
- function qtranxf_header(){
23
- global $q_config;
24
- echo "\n<meta http-equiv=\"Content-Language\" content=\"".str_replace('_','-',$q_config['locale'][$q_config['language']])."\" />\n";
25
- $css = "<style type=\"text/css\" media=\"screen\">\n";
26
- $css .=".qtranxf_flag span { display:none }\n";
27
- $css .=".qtranxf_flag { height:12px; width:18px; display:block }\n";
28
- $css .=".qtranxf_flag_and_text { padding-left:20px }\n";
29
- $baseurl = WP_CONTENT_URL;
30
- if(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == '1' || $_SERVER['HTTPS'] == 'on')) {
31
- $baseurl = preg_replace('#^http://#','https://', $baseurl);
32
- }
33
- foreach($q_config['enabled_languages'] as $language) {
34
- $css .=".qtranxf_flag_".$language." { background:url(".$baseurl.'/'.$q_config['flag_location'].$q_config['flag'][$language].") no-repeat }\n";
35
- }
36
- $css .="</style>\n";
37
- // skip the rest if 404
38
- if(is_404()) return;
39
- // set links to translations of current page
40
- foreach($q_config['enabled_languages'] as $language) {
41
- if($language != qtranxf_getLanguage())
42
- echo '<link hreflang="'.$language.'" href="'.qtranxf_convertURL('',$language).'" rel="alternate" />'."\n";
43
- }
44
- }
45
 
46
  function qtranxf_localeForCurrentLanguage($locale){
47
  global $q_config;
48
  // try to figure out the correct locale
 
 
49
  $locale = array();
50
- $locale[] = $q_config['locale'][$q_config['language']].".utf8";
51
- $locale[] = $q_config['locale'][$q_config['language']]."@euro";
52
- $locale[] = $q_config['locale'][$q_config['language']];
53
- $locale[] = $q_config['windows_locale'][$q_config['language']];
54
- $locale[] = $q_config['language'];
55
-
56
  // return the correct locale and most importantly set it (wordpress doesn't, which is bad)
57
- // only set LC_TIME as everyhing else doesn't seem to work with windows
58
  setlocale(LC_TIME, $locale);
59
-
60
- return $q_config['locale'][$q_config['language']];
61
  }
62
 
63
  function qtranxf_useCurrentLanguageIfNotFoundShowAvailable($content) {
@@ -67,6 +48,9 @@ function qtranxf_useCurrentLanguageIfNotFoundShowAvailable($content) {
67
 
68
  function qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($content) {
69
  global $q_config;
 
 
 
70
  return qtranxf_use($q_config['language'], $content, false);
71
  }
72
 
@@ -183,13 +167,34 @@ function qtranxf_supercache_dir($uri) {
183
  }
184
  $uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', $uri ) ) ) );
185
  $uri = str_replace( '\\', '', $uri );
186
- $uri = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])) . $uri; // To avoid XSS attacs
187
  return $uri;
188
  }
189
  add_filter('supercache_dir', 'qtranxf_supercache_dir',0);
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  // Hooks (Actions)
192
- add_action('wp_head', 'qtranxf_header');
193
  // add_action('category_edit_form', 'qtranxf_modifyTermFormFor');
194
  // //add_action('post_tag_edit_form', 'qtranxf_modifyTermFormFor');
195
  // add_action('link_category_edit_form', 'qtranxf_modifyTermFormFor');
@@ -200,6 +205,11 @@ add_action('widgets_init', 'qtranxf_widget_init');
200
  add_action('plugins_loaded', 'qtranxf_init', 2);
201
 
202
  // Hooks (execution time critical filters)
 
 
 
 
 
203
  add_filter('the_content', 'qtranxf_useCurrentLanguageIfNotFoundShowAvailable', 0);
204
  add_filter('the_excerpt', 'qtranxf_useCurrentLanguageIfNotFoundShowAvailable', 0);
205
  add_filter('the_excerpt_rss', 'qtranxf_useCurrentLanguageIfNotFoundShowAvailable', 0);
@@ -228,7 +238,6 @@ add_filter('get_wp_title_rss', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLa
228
  add_filter('wp_title_rss', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
229
  add_filter('the_title_rss', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
230
  add_filter('the_content_rss', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
231
- add_filter('gettext', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
232
  add_filter('get_pages', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
233
  add_filter('category_description', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
234
  add_filter('bloginfo_rss', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
@@ -239,9 +248,10 @@ add_filter('link_name', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage'
239
  add_filter('link_description', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
240
  add_filter('pre_option_rss_language', 'qtranxf_getLanguage',0);
241
  add_filter('the_author', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
242
- add_filter( "_wp_post_revision_field_post_title", 'qtranxf_showAllSeperated', 0);
243
- add_filter( "_wp_post_revision_field_post_content", 'qtranxf_showAllSeperated', 0);
244
- add_filter( "_wp_post_revision_field_post_excerpt", 'qtranxf_showAllSeperated', 0);
 
245
 
246
  // // Hooks (execution time non-critical filters)
247
  add_filter('author_feed_link', 'qtranxf_convertURL');
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
+ /* qTranslate-X Hooks */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  function qtranxf_localeForCurrentLanguage($locale){
26
  global $q_config;
27
  // try to figure out the correct locale
28
+ $lang = $q_config['language'];
29
+ $locale_lang=$q_config['locale'][$lang];
30
  $locale = array();
31
+ $locale[] = $locale_lang.".utf8";
32
+ $locale[] = $locale_lang."@euro";
33
+ $locale[] = $locale_lang;
34
+ $locale[] = $q_config['windows_locale'][$lang];
35
+ $locale[] = $lang;
36
+
37
  // return the correct locale and most importantly set it (wordpress doesn't, which is bad)
38
+ // only set LC_TIME as everything else doesn't seem to work with windows
39
  setlocale(LC_TIME, $locale);
40
+
41
+ return $locale_lang;
42
  }
43
 
44
  function qtranxf_useCurrentLanguageIfNotFoundShowAvailable($content) {
48
 
49
  function qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($content) {
50
  global $q_config;
51
+ //if(!isset($q_config['language'])){
52
+ // qtranxf_dbg_log('$q_config[language] is not set:',debug_backtrace());
53
+ //}
54
  return qtranxf_use($q_config['language'], $content, false);
55
  }
56
 
167
  }
168
  $uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', $uri ) ) ) );
169
  $uri = str_replace( '\\', '', $uri );
170
+ $uri = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])) . $uri; // To avoid XSS attacks
171
  return $uri;
172
  }
173
  add_filter('supercache_dir', 'qtranxf_supercache_dir',0);
174
 
175
+ //function qtranxf_gettext($translated_text, $text, $domain) {
176
+ function qtranxf_gettext($translated_text) {
177
+ //same as qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage
178
+ global $q_config;
179
+ if(!isset($q_config['language'])){
180
+ //qtranxf_dbg_log('$q_config[language] is not set:',debug_backtrace());
181
+ return $translated_text;
182
+ }
183
+ return qtranxf_use($q_config['language'], $translated_text, false);
184
+ }
185
+
186
+ //function qtranxf_gettext_with_context($translated_text, $text, $context, $domain) {
187
+ function qtranxf_gettext_with_context($translated_text) {
188
+ //same as qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage
189
+ global $q_config;
190
+ if(!isset($q_config['language'])){
191
+ //qtranxf_dbg_log('$q_config[language] is not set:',debug_backtrace());
192
+ return $translated_text;
193
+ }
194
+ return qtranxf_use($q_config['language'], $translated_text, false);
195
+ }
196
+
197
  // Hooks (Actions)
 
198
  // add_action('category_edit_form', 'qtranxf_modifyTermFormFor');
199
  // //add_action('post_tag_edit_form', 'qtranxf_modifyTermFormFor');
200
  // add_action('link_category_edit_form', 'qtranxf_modifyTermFormFor');
205
  add_action('plugins_loaded', 'qtranxf_init', 2);
206
 
207
  // Hooks (execution time critical filters)
208
+ add_filter('gettext', 'qtranxf_gettext',0);
209
+ add_filter('gettext_with_context', 'qtranxf_gettext_with_context',0);
210
+ //add_filter('gettext', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
211
+ //add_filter('gettext_with_context', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
212
+
213
  add_filter('the_content', 'qtranxf_useCurrentLanguageIfNotFoundShowAvailable', 0);
214
  add_filter('the_excerpt', 'qtranxf_useCurrentLanguageIfNotFoundShowAvailable', 0);
215
  add_filter('the_excerpt_rss', 'qtranxf_useCurrentLanguageIfNotFoundShowAvailable', 0);
238
  add_filter('wp_title_rss', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
239
  add_filter('the_title_rss', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
240
  add_filter('the_content_rss', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
 
241
  add_filter('get_pages', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
242
  add_filter('category_description', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
243
  add_filter('bloginfo_rss', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
248
  add_filter('link_description', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
249
  add_filter('pre_option_rss_language', 'qtranxf_getLanguage',0);
250
  add_filter('the_author', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
251
+
252
+ add_filter('_wp_post_revision_field_post_title', 'qtranxf_showAllSeperated', 0);
253
+ add_filter('_wp_post_revision_field_post_content', 'qtranxf_showAllSeperated', 0);
254
+ add_filter('_wp_post_revision_field_post_excerpt', 'qtranxf_showAllSeperated', 0);
255
 
256
  // // Hooks (execution time non-critical filters)
257
  add_filter('author_feed_link', 'qtranxf_convertURL');
qtranslate_services.php CHANGED
@@ -17,6 +17,9 @@
17
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
  */
19
 
 
 
 
20
  /* qTranslate Services */
21
 
22
  // generate public key
@@ -377,7 +380,7 @@ function qts_config_hook($request_uri) {
377
  <?php if(!qts_isOpenSSLAvailable()) { printf(__('<div id="message" class="error fade"><p>qTranslate Services could not load <a href="%s">OpenSSL</a>!</p></div>'), 'http://www.php.net/manual/book.openssl.php'); } ?>
378
  <label for="qtranslate_services"><input type="checkbox" name="qtranslate_services" id="qtranslate_services" value="1"<?php echo ($q_config['qtranslate_services'])?' checked="checked"':''; ?>/> <?php _e('Enable qTranslate Services', 'qtranslate'); ?></label>
379
  <br/>
380
- <?php _e('With qTranslate Services, you will be able to use professional human translation services with a few clicks.', 'qtranslate'); ?><br />
381
  </td>
382
  </tr>
383
  <?php
@@ -404,7 +407,7 @@ function qts_config_hook($request_uri) {
404
  </tfoot>
405
  <?php
406
  foreach($orders as $order) {
407
- $post = &get_post($order['post_id']);
408
  if(!$post) continue;
409
  $post->post_title = esc_html(qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($post->post_title));
410
  ?>
@@ -506,7 +509,7 @@ function qts_UpdateOrder($order_id) {
506
  // update db if post is updated
507
  if(isset($result['order_status']) && $result['order_status']==QTS_STATE_CLOSED) {
508
  $order['post_id'] = intval($order['post_id']);
509
- $post = &get_post($order['post_id']);
510
  $title = qtranxf_split($post->post_title);
511
  $content = qtranxf_split($post->post_content);
512
  $title[$order['target_language']] = $result['order_translated_title'];
@@ -542,7 +545,7 @@ function qts_service() {
542
  if(isset($_REQUEST['target_language'])&&qtranxf_isEnabled($_REQUEST['target_language']))
543
  $translate_to = $_REQUEST['target_language'];
544
  if($translate_to == $translate_from) $translate_to = '';
545
- $post = &get_post($post_id);
546
  if(!$post) {
547
  printf(__('Post with id "%s" not found!','qtranslate'), $post_id);
548
  return;
@@ -627,7 +630,7 @@ function qts_service() {
627
  if(isset($answer['error'])) {
628
  $error = sprintf(__('An error occured: %s', 'qtranslate'), $qts_error_messages[$answer['error']]);
629
  if($answer['message']!='') {
630
- $error.='<br />'.sprintf(__('Additional information: %s', 'qtranslate'), qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($answer['message']));
631
  }
632
  }
633
  if(isset($answer['order_id'])) {
@@ -838,7 +841,7 @@ function qts_quote() {
838
  $service_id = $_POST['service_id'];
839
  $translate_from = $_POST['translate_from'];
840
  $translate_to = $_POST['translate_to'];
841
- $post = &get_post($_POST['post_id']);
842
  $post = qtranxf_use($translate_from, $post);
843
  $post_title = $post->post_title;
844
  $post_content = $post->post_content;
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
  /* qTranslate Services */
24
 
25
  // generate public key
380
  <?php if(!qts_isOpenSSLAvailable()) { printf(__('<div id="message" class="error fade"><p>qTranslate Services could not load <a href="%s">OpenSSL</a>!</p></div>'), 'http://www.php.net/manual/book.openssl.php'); } ?>
381
  <label for="qtranslate_services"><input type="checkbox" name="qtranslate_services" id="qtranslate_services" value="1"<?php echo ($q_config['qtranslate_services'])?' checked="checked"':''; ?>/> <?php _e('Enable qTranslate Services', 'qtranslate'); ?></label>
382
  <br/>
383
+ <small><?php _e('With qTranslate Services, you will be able to use professional human translation services with a few clicks.', 'qtranslate'); ?></small>
384
  </td>
385
  </tr>
386
  <?php
407
  </tfoot>
408
  <?php
409
  foreach($orders as $order) {
410
+ $p = get_post($order['post_id']); $post = &$p;
411
  if(!$post) continue;
412
  $post->post_title = esc_html(qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($post->post_title));
413
  ?>
509
  // update db if post is updated
510
  if(isset($result['order_status']) && $result['order_status']==QTS_STATE_CLOSED) {
511
  $order['post_id'] = intval($order['post_id']);
512
+ $p=get_post($order['post_id']); $post = &$p;
513
  $title = qtranxf_split($post->post_title);
514
  $content = qtranxf_split($post->post_content);
515
  $title[$order['target_language']] = $result['order_translated_title'];
545
  if(isset($_REQUEST['target_language'])&&qtranxf_isEnabled($_REQUEST['target_language']))
546
  $translate_to = $_REQUEST['target_language'];
547
  if($translate_to == $translate_from) $translate_to = '';
548
+ $p = get_post($post_id); $post = &$p;
549
  if(!$post) {
550
  printf(__('Post with id "%s" not found!','qtranslate'), $post_id);
551
  return;
630
  if(isset($answer['error'])) {
631
  $error = sprintf(__('An error occured: %s', 'qtranslate'), $qts_error_messages[$answer['error']]);
632
  if($answer['message']!='') {
633
+ $error.='<br/>'.sprintf(__('Additional information: %s', 'qtranslate'), qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($answer['message']));
634
  }
635
  }
636
  if(isset($answer['order_id'])) {
841
  $service_id = $_POST['service_id'];
842
  $translate_from = $_POST['translate_from'];
843
  $translate_to = $_POST['translate_to'];
844
+ $p = get_post($_POST['post_id']); $post = &$p;
845
  $post = qtranxf_use($translate_from, $post);
846
  $post_title = $post->post_title;
847
  $post_content = $post->post_content;
qtranslate_utils.php CHANGED
@@ -17,23 +17,63 @@
17
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
  */
19
 
 
 
 
20
  /* qTranslate-X Utilities */
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  function qtranxf_parseURL($url) {
23
- $r = '!(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?';
24
- $r .= '(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))?!i';
25
-
26
- preg_match ( $r, $url, $out );
27
- $result = @array(
28
- "scheme" => $out[1],
29
- "host" => $out[4].(($out[5]=='')?'':':'.$out[5]),
30
- "user" => $out[2],
31
- "pass" => $out[3],
32
- "path" => $out[6],
33
- "query" => $out[7],
34
- "fragment" => $out[8]
35
- );
36
- return $result;
 
 
 
 
 
 
 
 
37
  }
38
 
39
  function qtranxf_stripSlashesIfNecessary($str) {
@@ -102,8 +142,8 @@ function qtranxf_getAvailableLanguages($text) {
102
  function qtranxf_isAvailableIn($post_id, $language='') {
103
  global $q_config;
104
  if($language == '') $language = $q_config['default_language'];
105
- $post = &get_post($post_id);
106
- $languages = qtranxf_getAvailableLanguages($post->post_content);
107
  return in_array($language,$languages);
108
  }
109
 
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
  /* qTranslate-X Utilities */
24
 
25
+ /*
26
+ if(defined('WP_DEBUG')&&WP_DEBUG){
27
+ if(!function_exists('qtranxf_dbg_log')){
28
+ function qtranxf_dbg_log($msg,$var=null){
29
+ //$d=ABSPATH.'/wp-logs';
30
+ //if(!file_exists($d)) mkdir($d);
31
+ //$f=$d.'/qtranslate.log';
32
+ $f=WP_CONTENT_DIR.'/debug-qtranslate.log';
33
+ if($var)
34
+ $msg .= "\n".var_export($var,true);
35
+ error_log($msg."\n",3,$f);
36
+ }
37
+ }
38
+ if(!function_exists('qtranxf_dbg_echo')){
39
+ function qtranxf_dbg_echo($msg,$var=null){
40
+ if($var)
41
+ $msg .= "<br>\n".var_export($var,true);
42
+ echo $msg."<br>\n";
43
+ }
44
+ }
45
+ assert_options(ASSERT_BAIL,true);
46
+ //}else{
47
+ // function qtranxf_dbg_log($msg,$var=null){}
48
+ // function qtranxf_dbg_echo($msg){}
49
+ //assert_options(ASSERT_ACTIVE,false);
50
+ //assert_options(ASSERT_WARNING,false);
51
+ //assert_options(ASSERT_QUIET_EVAL,true);
52
+ }// */
53
+
54
  function qtranxf_parseURL($url) {
55
+ /*
56
+ if(function_exists('parse_url')){
57
+ $result = parse_url($url);
58
+ if(!isset($result['path'])) $result['path']='';
59
+ if(!isset($result['host'])) $result['host']='';
60
+ if(isset($result['port'])) $result['host'].=':'.$result['port'];
61
+ }else{
62
+ */
63
+ $r = '!(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?';
64
+ $r .= '(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))?!i';
65
+ preg_match ( $r, $url, $out );
66
+ $result = @array(
67
+ "scheme" => $out[1],
68
+ "host" => $out[4].(($out[5]=='')?'':':'.$out[5]),
69
+ "user" => $out[2],
70
+ "pass" => $out[3],
71
+ "path" => $out[6],
72
+ "query" => $out[7],
73
+ "fragment" => $out[8]
74
+ );
75
+ // }
76
+ return $result;
77
  }
78
 
79
  function qtranxf_stripSlashesIfNecessary($str) {
142
  function qtranxf_isAvailableIn($post_id, $language='') {
143
  global $q_config;
144
  if($language == '') $language = $q_config['default_language'];
145
+ $p = get_post($post_id); $post = &$p;
146
+ $languages = qtranxf_getAvailableLanguages($post->post_content);
147
  return in_array($language,$languages);
148
  }
149
 
qtranslate_widget.php CHANGED
@@ -17,50 +17,88 @@
17
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
  */
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  /* qTranslate-X Widget */
21
 
22
  class qTranslateXWidget extends WP_Widget {
23
  function qTranslateXWidget() {
24
- $widget_ops = array('classname' => 'qtranxs-widget', 'description' => __('Allows your visitors to choose a Language.', 'qtranslate') );
25
  $this->WP_Widget('qtranslate', __('qTranslate Language Chooser', 'qtranslate'), $widget_ops);
 
26
  }
27
-
28
  function widget($args, $instance) {
29
  extract($args);
30
-
 
 
31
  echo $before_widget;
32
- $title = empty($instance['title']) ? __('Language', 'qtranslate') : apply_filters('widget_title', $instance['title']);
33
- $hide_title = empty($instance['hide-title']) ? false : 'on';
 
 
 
 
 
 
 
34
  $type = $instance['type'];
35
  if($type!='text'&&$type!='image'&&$type!='both'&&$type!='dropdown') $type='text';
36
-
37
- if($hide_title!='on') { echo $before_title . $title . $after_title; };
38
- qtranxf_generateLanguageSelectCode($type, $this->id);
39
  echo $after_widget;
40
  }
41
-
 
 
42
  function update($new_instance, $old_instance) {
43
  $instance = $old_instance;
44
  $instance['title'] = $new_instance['title'];
45
  if(isset($new_instance['hide-title'])) $instance['hide-title'] = $new_instance['hide-title'];
46
  $instance['type'] = $new_instance['type'];
47
-
48
  return $instance;
49
  }
50
-
51
  function form($instance) {
52
- $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'hide-title' => false, 'type' => 'text' ) );
53
  $title = $instance['title'];
54
  $hide_title = $instance['hide-title'];
55
  $type = $instance['type'];
 
 
56
  ?>
57
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'qtranslate'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
58
- <p><label for="<?php echo $this->get_field_id('hide-title'); ?>"><?php _e('Hide Title:', 'qtranslate'); ?> <input type="checkbox" id="<?php echo $this->get_field_id('hide-title'); ?>" name="<?php echo $this->get_field_name('hide-title'); ?>" <?php echo ($hide_title=='on')?'checked="checked"':''; ?>/></label></p>
59
- <p><?php _e('Display:', 'qtranslate'); ?></p>
60
- <p><label for="<?php echo $this->get_field_id('type'); ?>1"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>1" value="text"<?php echo ($type=='text')?' checked="checked"':'' ?>/> <?php _e('Text only', 'qtranslate'); ?></label></p>
61
- <p><label for="<?php echo $this->get_field_id('type'); ?>2"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>2" value="image"<?php echo ($type=='image')?' checked="checked"':'' ?>/> <?php _e('Image only', 'qtranslate'); ?></label></p>
62
- <p><label for="<?php echo $this->get_field_id('type'); ?>3"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>3" value="both"<?php echo ($type=='both')?' checked="checked"':'' ?>/> <?php _e('Text and Image', 'qtranslate'); ?></label></p>
63
- <p><label for="<?php echo $this->get_field_id('type'); ?>4"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>4" value="dropdown"<?php echo ($type=='dropdown')?' checked="checked"':'' ?>/> <?php _e('Dropdown Box', 'qtranslate'); ?></label></p>
 
64
  <?php
65
  }
66
  }
@@ -71,67 +109,70 @@ function qtranxf_generateLanguageSelectCode($style='', $id='') {
71
  if($style=='') $style='text';
72
  if(is_bool($style)&&$style) $style='image';
73
  if(is_404()) $url = get_option('home'); else $url = '';
74
- if($id=='') $id = 'qtranslate';
75
  $id .= '-chooser';
 
76
  switch($style) {
77
  case 'image':
78
  case 'text':
79
  case 'dropdown':
80
- echo '<ul class="qtranxf_language_chooser" id="'.$id.'">';
81
- foreach(qtranxf_getSortedLanguages() as $language) {
82
  $classes = array('lang-'.$language);
83
- if($language == $q_config['language'])
84
- $classes[] = 'active';
85
- echo '<li class="'. implode(' ', $classes) .'"><a href="'.qtranxf_convertURL($url, $language, false, true).'"';
 
86
  // set hreflang
87
- echo ' hreflang="'.$language.'" title="'.$q_config['language_name'][$language].'"';
 
88
  if($style=='image')
89
- //echo ' class="qtranxf_flag qtranxf_flag_'.$language.'"';
 
 
 
90
  echo '>';
91
- if($style=='image')
92
- {
93
- echo '<img src="'.trailingslashit(WP_CONTENT_URL).$q_config['flag_location'].$q_config['flag'][$language].'"></img>';
94
- }
95
  echo '<span';
96
- if($style=='image')
97
- echo ' style="display:none"';
98
- echo '>'.$q_config['language_name'][$language].'</span></a></li>';
99
  }
100
- echo "</ul><div class=\"qtranxf_widget_end\"></div>";
101
  if($style=='dropdown') {
102
- echo "<script type=\"text/javascript\">\n// <![CDATA[\r\n";
103
- echo "var lc = document.getElementById('".$id."');\n";
104
- echo "var s = document.createElement('select');\n";
105
- echo "s.id = 'qtranxs_select_".$id."';\n";
106
- echo "lc.parentNode.insertBefore(s,lc);";
107
  // create dropdown fields for each language
108
- foreach(qtranxf_getSortedLanguages() as $language) {
109
- echo qtranxf_insertDropDownElement($language, qtranxf_convertURL($url, $language, false, true), $id);
110
  }
111
  // hide html language chooser text
112
- echo "s.onchange = function() { document.location.href = this.value;}\n";
113
- echo "lc.style.display='none';\n";
114
- echo "// ]]>\n</script>\n";
115
  }
116
  break;
117
  case 'both':
118
- echo '<ul class="qtranxf_language_chooser" id="'.$id.'">';
119
- foreach(qtranxf_getSortedLanguages() as $language) {
120
  echo '<li';
121
  if($language == $q_config['language'])
122
  echo ' class="active"';
123
- echo '><a href="'.qtranxf_convertURL($url, $language).'"';
124
- echo ' class="qtranxf_flag_'.$language.' qtranxf_flag_and_text" title="'.$q_config['language_name'][$language].'">';
125
- echo '<img src="'.trailingslashit(WP_CONTENT_URL).$q_config['flag_location'].$q_config['flag'][$language].'"></img>';
126
- echo '<span>'.$q_config['language_name'][$language].'</span></a></li>';
127
  }
128
- echo "</ul><div class=\"qtranxf_widget_end\"></div>";
129
  break;
130
  }
131
  }
132
 
133
  function qtranxf_widget_init() {
134
- register_widget('qTranslateXWidget');
 
135
  }
136
-
137
  ?>
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
+ define('QTX_WIDGET_CSS',
24
+ '.qtranxs_widget ul { margin: 0; }
25
+ .qtranxs_widget ul li
26
+ {
27
+ display: inline; /* horizontal list, use "list-item" or other appropriate value for vertical list */
28
+ list-style-type: none; /* use "initial" or other to enable bullets */
29
+ margin: 0 5px 0 0; /* adjust spacing between items */
30
+ opacity: 0.5;
31
+ -o-transition: 1s ease opacity;
32
+ -moz-transition: 1s ease opacity;
33
+ -webkit-transition: 1s ease opacity;
34
+ transition: 1s ease opacity;
35
+ }
36
+ //.qtranxs_widget ul li span { margin: 0 5px 0 0; } /* other way to control spacing */
37
+ .qtranxs_widget ul li.active { opacity: 0.8; }
38
+ .qtranxs_widget ul li:hover { opacity: 1; }
39
+ .qtranxs_widget img { box-shadow: none; vertical-align: middle; }
40
+ .qtranxs_flag { height:12px; width:18px; display:block; }
41
+ .qtranxs_flag_and_text { padding-left:20px; }
42
+ .qtranxs_flag span { display:none; }
43
+ ');
44
+
45
  /* qTranslate-X Widget */
46
 
47
  class qTranslateXWidget extends WP_Widget {
48
  function qTranslateXWidget() {
49
+ $widget_ops = array('classname' => 'qtranxs_widget', 'description' => __('Allows your visitors to choose a Language.', 'qtranslate') );
50
  $this->WP_Widget('qtranslate', __('qTranslate Language Chooser', 'qtranslate'), $widget_ops);
51
+ //add_action('qtranxf_head_add_css',array($this,'head_add_css'));
52
  }
53
+
54
  function widget($args, $instance) {
55
  extract($args);
56
+ echo '<style type="text/css">'.PHP_EOL;
57
+ echo empty($instance['widget-css']) ? QTX_WIDGET_CSS : $instance['widget-css'];
58
+ echo '</style>'.PHP_EOL;
59
  echo $before_widget;
60
+ //$title = empty($instance['title']) ? __('Language', 'qtranslate') : apply_filters('widget_title', $instance['title']);
61
+ //$hide_title = empty($instance['hide-title']) ? false : 'on';
62
+ if(empty($instance['hide-title'])) {
63
+ $title = $instance['title'];
64
+ if(empty($title))
65
+ $title=__('Language', 'qtranslate');
66
+ $title=apply_filters('qtranxf_widget_title',$title.':');
67
+ echo $before_title . $title . $after_title;
68
+ }
69
  $type = $instance['type'];
70
  if($type!='text'&&$type!='image'&&$type!='both'&&$type!='dropdown') $type='text';
71
+ qtranxf_generateLanguageSelectCode($type, $this->id);
 
 
72
  echo $after_widget;
73
  }
74
+
75
+ //function head_add_css() { echo $widget_options['widget-css']; }
76
+
77
  function update($new_instance, $old_instance) {
78
  $instance = $old_instance;
79
  $instance['title'] = $new_instance['title'];
80
  if(isset($new_instance['hide-title'])) $instance['hide-title'] = $new_instance['hide-title'];
81
  $instance['type'] = $new_instance['type'];
82
+ $instance['widget-css'] = $new_instance['widget-css'];
83
  return $instance;
84
  }
85
+
86
  function form($instance) {
87
+ $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'hide-title' => false, 'type' => 'text', 'widget-css' => QTX_WIDGET_CSS ) );
88
  $title = $instance['title'];
89
  $hide_title = $instance['hide-title'];
90
  $type = $instance['type'];
91
+ $widget_css = $instance['widget-css'];
92
+ if(empty($widget_css)) $widget_css=QTX_WIDGET_CSS;
93
  ?>
94
+ <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'qtranslate'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
95
+ <p><label for="<?php echo $this->get_field_id('hide-title'); ?>"><?php _e('Hide Title:', 'qtranslate'); ?> <input type="checkbox" id="<?php echo $this->get_field_id('hide-title'); ?>" name="<?php echo $this->get_field_name('hide-title'); ?>" <?php echo ($hide_title=='on')?'checked="checked"':''; ?>/></label></p>
96
+ <p><?php _e('Display:', 'qtranslate'); ?></p>
97
+ <p><label for="<?php echo $this->get_field_id('type'); ?>1"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>1" value="text"<?php echo ($type=='text')?' checked="checked"':'' ?>/> <?php _e('Text only', 'qtranslate'); ?></label></p>
98
+ <p><label for="<?php echo $this->get_field_id('type'); ?>2"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>2" value="image"<?php echo ($type=='image')?' checked="checked"':'' ?>/> <?php _e('Image only', 'qtranslate'); ?></label></p>
99
+ <p><label for="<?php echo $this->get_field_id('type'); ?>3"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>3" value="both"<?php echo ($type=='both')?' checked="checked"':'' ?>/> <?php _e('Text and Image', 'qtranslate'); ?></label></p>
100
+ <p><label for="<?php echo $this->get_field_id('type'); ?>4"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>4" value="dropdown"<?php echo ($type=='dropdown')?' checked="checked"':'' ?>/> <?php _e('Dropdown Box', 'qtranslate'); ?></label></p>
101
+ <p><label for="<?php echo $this->get_field_id('widget-css'); ?>"><?php echo __('Widget', 'qtranslate').' CSS:'; ?></label><br><textarea class="widefat" rows="6" name="<?php echo $this->get_field_name('widget-css'); ?>" id="<?php echo $this->get_field_id('widget-css'); ?>" /><?php echo esc_attr($widget_css); ?></textarea><br><small><?php _e('To reset to default, clear the text.','qtranslate'); ?></small></p>
102
  <?php
103
  }
104
  }
109
  if($style=='') $style='text';
110
  if(is_bool($style)&&$style) $style='image';
111
  if(is_404()) $url = get_option('home'); else $url = '';
112
+ if($id=='') $id = 'qtranslate';
113
  $id .= '-chooser';
114
+ $flag_location=trailingslashit(WP_CONTENT_URL).$q_config['flag_location'];
115
  switch($style) {
116
  case 'image':
117
  case 'text':
118
  case 'dropdown':
119
+ echo PHP_EOL.'<ul class="qtranxs_language_chooser" id="'.$id.'">'.PHP_EOL;
120
+ foreach(qtranxf_getSortedLanguages() as $language) {
121
  $classes = array('lang-'.$language);
122
+ if($language == $q_config['language']) $classes[] = 'active';
123
+ echo '<li class="'. implode(' ', $classes) .'"><a href="'.qtranxf_convertURL($url, $language, false, true).'"';
124
+ //echo '<li'; if($language == $q_config['language']) echo ' class="active"';
125
+ //echo '><a href="'.qtranxf_convertURL($url, $language, false, true).'"';
126
  // set hreflang
127
+ echo ' hreflang="'.$language.'"';
128
+ echo ' title="'.$q_config['language_name'][$language].'"';
129
  if($style=='image')
130
+ echo ' class="qtranxs_image qtranxs_image_'.$language.'"';
131
+ // echo ' class="qtranxs_flag qtranxs_flag_'.$language.'"';
132
+ elseif($style=='text')
133
+ echo ' class="qtranxs_text qtranxs_text_'.$language.'"';
134
  echo '>';
135
+ if($style=='image') echo '<img src="'.$flag_location.$q_config['flag'][$language].'"/>';
 
 
 
136
  echo '<span';
137
+ if($style=='image') echo ' style="display:none"';
138
+ echo '>'.$q_config['language_name'][$language].'</span>';
139
+ echo '</a></li>'.PHP_EOL;
140
  }
141
+ echo '</ul><div class="qtranxs_widget_end"></div>'.PHP_EOL;
142
  if($style=='dropdown') {
143
+ echo '<script type="text/javascript">'.PHP_EOL.'// <![CDATA['.PHP_EOL;
144
+ echo "var lc = document.getElementById('".$id."');".PHP_EOL;
145
+ echo "var s = document.createElement('select');".PHP_EOL;
146
+ echo "s.id = 'qtranxs_select_".$id."';".PHP_EOL;
147
+ echo "lc.parentNode.insertBefore(s,lc);".PHP_EOL;
148
  // create dropdown fields for each language
149
+ foreach(qtranxf_getSortedLanguages() as $language) {
150
+ echo qtranxf_insertDropDownElement($language, qtranxf_convertURL($url, $language, false, true), $id);
151
  }
152
  // hide html language chooser text
153
+ echo "s.onchange = function() { document.location.href = this.value;}".PHP_EOL;
154
+ echo "lc.style.display='none';".PHP_EOL;
155
+ echo '// ]]>'.PHP_EOL.'</script>'.PHP_EOL;
156
  }
157
  break;
158
  case 'both':
159
+ echo PHP_EOL.'<ul class="qtranxs_language_chooser" id="'.$id.'">'.PHP_EOL;
160
+ foreach(qtranxf_getSortedLanguages() as $language) {
161
  echo '<li';
162
  if($language == $q_config['language'])
163
  echo ' class="active"';
164
+ echo '><a href="'.qtranxf_convertURL($url, $language, false, true).'"';
165
+ echo ' class="qtranxs_flag_'.$language.' qtranxs_flag_and_text" title="'.$q_config['language_name'][$language].'">';
166
+ //echo '<img src="'.$flag_location.$q_config['flag'][$language].'"></img>';
167
+ echo '<span>'.$q_config['language_name'][$language].'</span></a></li>'.PHP_EOL;
168
  }
169
+ echo '</ul><div class="qtranxs_widget_end"></div>'.PHP_EOL;
170
  break;
171
  }
172
  }
173
 
174
  function qtranxf_widget_init() {
175
+ register_widget('qTranslateXWidget');
176
+ do_action('qtranxf_widget_init');
177
  }
 
178
  ?>
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === qTranslate-X ===
2
  Developed by: qTranslate Team based on original code by Qian Qin
3
  Contributors: johnclause, chineseleper, Vavooon
4
  Tags: multilingual, language, admin, tinymce, bilingual, widget, switcher, i18n, l10n, multilanguage, translation
5
  Requires at least: 3.9
6
  Tested up to: 4.1
7
- Stable tag: 2.7.8
8
  License: GPLv3 or later
9
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QEXEK3HX8AR6U
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -29,11 +29,15 @@ qTranslate-X makes creation of multilingual content as easy as working with a si
29
  - One language for each URL - Users and SEO will thank you for not mixing multilingual content.
30
  - qTranslate-X supports unlimited number of languages, which can be easily added/modified/deleted via a comfortable Configuration Page at Settings->Languages.
31
  - You may use [Google XML Sitemaps v3 for qTranslate](https://wordpress.org/plugins/google-xml-sitemaps-v3-for-qtranslate/) plugin to rebuild your XML sitemap for better SEO support.
 
 
32
 
33
  You may still find a lot of useful information through reading [qTranslate](https://wordpress.org/plugins/qtranslate/ "Original qTranslate plugin")'s original documentation, which is not duplicated here in full. There are also other plugins, which offer multilingual support, but it seems that Qian Qin has very good original back-end design, and many people have been pleasantly using his plugin ever since. It stores all translations in the same single post, which makes it easy to maintain and to use it with other plugins. However, the user interface of former qTranslate got out of sync with the recent versions of Wordpress, especially after WP went to TinyMCE 4. There is a number of forks of qTranslate, see for example, [mqTranslate](https://wordpress.org/plugins/mqtranslate/ "mqTranslate plugin"), [qTranslate Plus](https://wordpress.org/plugins/qtranslate-xp/ "qTranslate Plus plugin") and [zTranslate](https://wordpress.org/plugins/ztranslate/ "zTranslate plugin"). They all try to fix qTranslate's user interface preserving its original back-end, which is what this plugin does too. This plugin is a hybrid of all of them and fixes a few bugs in each of them. It also has many new features too, like theme custom translatable fields, for example. We hope that this plugin is the most complete working version which combines the best features of [qTranslate](https://wordpress.org/plugins/qtranslate/ "Original qTranslate plugin"), [mqTranslate](https://wordpress.org/plugins/mqtranslate/ "mqTranslate fork"), [qTranslate Plus](https://wordpress.org/plugins/qtranslate-xp/ "qTranslate Plus fork") and [zTranslate](https://wordpress.org/plugins/ztranslate/ "zTranslate fork").
34
 
35
  We suggest all mentioned authors to get together and to continue supporting one single qTranslate-ish plugin in a joint effort.
36
 
 
 
37
  == Installation ==
38
 
39
  Installation of this plugin is no different from any other plugin:
@@ -44,7 +48,7 @@ Installation of this plugin is no different from any other plugin:
44
  1. Deactivate plugin qTranslate, mqTranslate, qTranslate Plus, or zTranslate, if you running any.
45
  1. Activate qTranslate-X through the 'Plugins' configuration page in WordPress.
46
  1. Open Settings->Languages configuration page and add/delete/disable any languages you need.
47
- 1. Add the qTranslate Widget or Language Switcher menu item to let your visitors switch the language.
48
  1. You may use [Google XML Sitemaps v3 for qTranslate](https://wordpress.org/plugins/google-xml-sitemaps-v3-for-qtranslate/) plugin to rebuild your XML sitemap for better SEO support.
49
  1. Configure theme custom fields to be translatable if needed (Settings -> Languages: "Custom Fields").
50
  1. Upgrading from [qTranslate](https://wordpress.org/plugins/qtranslate/ "qTranslate original plugin") required no additional actions, qTranslate-X will continue to work from the database entries of qTranslate. One may also go back to qTranslate at any time. Upgrading from other qTranslate forks may require re-configuration of the languages and taxonomies names, unless you rename corresponding database entries directly.
@@ -53,11 +57,11 @@ Installation of this plugin is no different from any other plugin:
53
 
54
  = Is it possible to translate theme custom fields? =
55
 
56
- Yes, some themes put additional text fields per page or per post. By default, those fields have no way to respond to language switching buttons in editors. However, you may enter "id" attribute of those fields into "Custom Fields" section of "Languages" configuration page in "Settings", and they will then respond to the language switching buttons allowing you to enter different text for each language. To lookup "id", right-click on the field in the post or the page editor, choose "Inspect Element", and look for an attribute of the field named "id".
57
 
58
- The theme must pass those values through [translation](http://codex.wordpress.org/Function_Reference/_2) function '__()' before displaying on the output. Most themes do this by default, otherwise you may ask theme author to make this little modification for each field you need to be translatable.
59
 
60
- Translatable fields, pre-configured by default:
61
 
62
  - all input fields of class "wp-editor-area", which normally include all TinyMCE visual editors.
63
  - fields with the following id: "title", "attachment_caption", "attachment_alt".
@@ -98,9 +102,9 @@ One can find the original qTranslate FAQ [here](https://wordpress.org/plugins/qt
98
 
99
  == Upgrade Notice ==
100
 
101
- * Upgrading from [qTranslate](https://wordpress.org/plugins/qtranslate/ "qTranslate original plugin") required no additional actions, qTranslate-X will continue to work from the database entries of qTranslate. One may also go back to qTranslate at any time.
102
- * Upgrading from other qTranslate forks may require re-configuration of the languages and taxonomies names.
103
- * Former page and post translations are untouched and preserved.
104
  * Upgrading from other multilingual frameworks will require custom re-configuration. We suggest to search for a plugin, which may be already implemented to transfer the translations to qTranslate or to qTranslate-X. If a plugin works for one, it should work for other too, since qTranslate-X and qTranslate share the same database structures.
105
 
106
  == Screenshots ==
@@ -111,6 +115,29 @@ One can find the original qTranslate FAQ [here](https://wordpress.org/plugins/qt
111
 
112
  == Changelog ==
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  = 2.7.8 =
115
  * user-friendly activation hook to deactivate/import/export other qTranslate forks.
116
  * import/export settings from other forks
@@ -157,6 +184,13 @@ One can find the original qTranslate FAQ [here](https://wordpress.org/plugins/qt
157
  * added 'post_title' filter to translate all titles fetched for display purpose
158
  * fixed problem with comment date display in some themes
159
 
 
 
 
 
 
 
 
160
  == Credentials ==
161
 
162
  * The code of this plugin mostly originally based on [qTranslate](https://wordpress.org/plugins/qtranslate/ "qTranslate original plugin") and [zTranslate](https://wordpress.org/plugins/ztranslate/ "zTranslate fork").
@@ -164,11 +198,7 @@ One can find the original qTranslate FAQ [here](https://wordpress.org/plugins/qt
164
 
165
  == Desirable Unimplemented Features ==
166
 
 
167
  * "Quick Edit" action in category or tag list pages will update the default language only.
168
- * Full screen editor mode does not have language switch buttons
169
- * If a language was switched on a page or post, but no edits were done, browser still complains about page changes, when leaving page.
170
-
171
- == Known Bugs ==
172
-
173
- * Message "The backup of this post in your browser is different from the version below" appears sometimes in the post editor. Clicking on "Restore the backup" may produce unexpected result, since backup has one language only,
174
- the one which was active at the time of the last pressing of button "Update". The code which causes this is in /wp-includes/js/autosave.js.
1
+ === qTranslate X ===
2
  Developed by: qTranslate Team based on original code by Qian Qin
3
  Contributors: johnclause, chineseleper, Vavooon
4
  Tags: multilingual, language, admin, tinymce, bilingual, widget, switcher, i18n, l10n, multilanguage, translation
5
  Requires at least: 3.9
6
  Tested up to: 4.1
7
+ Stable tag: 2.9.2
8
  License: GPLv3 or later
9
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QEXEK3HX8AR6U
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
29
  - One language for each URL - Users and SEO will thank you for not mixing multilingual content.
30
  - qTranslate-X supports unlimited number of languages, which can be easily added/modified/deleted via a comfortable Configuration Page at Settings->Languages.
31
  - You may use [Google XML Sitemaps v3 for qTranslate](https://wordpress.org/plugins/google-xml-sitemaps-v3-for-qtranslate/) plugin to rebuild your XML sitemap for better SEO support.
32
+ - Custom CSS for "qTranslate Language Chooser" widget configurable via its properties.
33
+ - Menu item "Language Switcher" to enable language choosing from a menu.
34
 
35
  You may still find a lot of useful information through reading [qTranslate](https://wordpress.org/plugins/qtranslate/ "Original qTranslate plugin")'s original documentation, which is not duplicated here in full. There are also other plugins, which offer multilingual support, but it seems that Qian Qin has very good original back-end design, and many people have been pleasantly using his plugin ever since. It stores all translations in the same single post, which makes it easy to maintain and to use it with other plugins. However, the user interface of former qTranslate got out of sync with the recent versions of Wordpress, especially after WP went to TinyMCE 4. There is a number of forks of qTranslate, see for example, [mqTranslate](https://wordpress.org/plugins/mqtranslate/ "mqTranslate plugin"), [qTranslate Plus](https://wordpress.org/plugins/qtranslate-xp/ "qTranslate Plus plugin") and [zTranslate](https://wordpress.org/plugins/ztranslate/ "zTranslate plugin"). They all try to fix qTranslate's user interface preserving its original back-end, which is what this plugin does too. This plugin is a hybrid of all of them and fixes a few bugs in each of them. It also has many new features too, like theme custom translatable fields, for example. We hope that this plugin is the most complete working version which combines the best features of [qTranslate](https://wordpress.org/plugins/qtranslate/ "Original qTranslate plugin"), [mqTranslate](https://wordpress.org/plugins/mqtranslate/ "mqTranslate fork"), [qTranslate Plus](https://wordpress.org/plugins/qtranslate-xp/ "qTranslate Plus fork") and [zTranslate](https://wordpress.org/plugins/ztranslate/ "zTranslate fork").
36
 
37
  We suggest all mentioned authors to get together and to continue supporting one single qTranslate-ish plugin in a joint effort.
38
 
39
+ GitHub repository is available: https://github.com/qTranslate-Team/qtranslate-x.git
40
+
41
  == Installation ==
42
 
43
  Installation of this plugin is no different from any other plugin:
48
  1. Deactivate plugin qTranslate, mqTranslate, qTranslate Plus, or zTranslate, if you running any.
49
  1. Activate qTranslate-X through the 'Plugins' configuration page in WordPress.
50
  1. Open Settings->Languages configuration page and add/delete/disable any languages you need.
51
+ 1. Add the "qTranslate Language Chooser" widget or "Language Switcher" menu item to let your visitors switch the language.
52
  1. You may use [Google XML Sitemaps v3 for qTranslate](https://wordpress.org/plugins/google-xml-sitemaps-v3-for-qtranslate/) plugin to rebuild your XML sitemap for better SEO support.
53
  1. Configure theme custom fields to be translatable if needed (Settings -> Languages: "Custom Fields").
54
  1. Upgrading from [qTranslate](https://wordpress.org/plugins/qtranslate/ "qTranslate original plugin") required no additional actions, qTranslate-X will continue to work from the database entries of qTranslate. One may also go back to qTranslate at any time. Upgrading from other qTranslate forks may require re-configuration of the languages and taxonomies names, unless you rename corresponding database entries directly.
57
 
58
  = Is it possible to translate theme custom fields? =
59
 
60
+ Yes, some themes put additional text fields per page or per post. By default, those fields have no way to respond to language switching buttons in editors. However, you may enter "id" or "class" name attribute of those fields into "Custom Fields" section of "Languages" configuration page in "Settings", and they will then respond to the language switching buttons allowing you to enter different text for each language. To lookup "id" or "class", right-click on the field in the post or the page editor, choose "Inspect Element", and look for which attributes are defined for that field. If you cannot uniquely distinct the field neither by if nor by class, report on the forum threads.
61
 
62
+ The theme must pass those values through [translation](http://codex.wordpress.org/Function_Reference/_2) function '__()' before displaying on the front-end output. If this is not done, you will see the text of all languages displayed one after another. Most themes use '__()' translation by default, otherwise you may ask theme author to make this little modification for each field you need to be translatable. However, sometimes, they pass a value through 'apply_filters()' function before displaying the value, and then you may put that filter name into configuration filed "Custom Filters" to get the value translated properly.
63
 
64
+ The following fields are pre-configured to be translatable by default:
65
 
66
  - all input fields of class "wp-editor-area", which normally include all TinyMCE visual editors.
67
  - fields with the following id: "title", "attachment_caption", "attachment_alt".
102
 
103
  == Upgrade Notice ==
104
 
105
+ * Upgrading from [qTranslate](https://wordpress.org/plugins/qtranslate/ "qTranslate original plugin") and [zTranslate](https://wordpress.org/plugins/ztranslate/ "zTranslate plugin") requires no additional actions, qTranslate-X will continue to work from the database entries of qTranslate. One may also go back to qTranslate at any time.
106
+ * Upgrading from other qTranslate forks also painless with an additional step of configuration import. One may also go back at any time using configuration export.
107
+ * Former page and post translations are untouched and preserved in any case.
108
  * Upgrading from other multilingual frameworks will require custom re-configuration. We suggest to search for a plugin, which may be already implemented to transfer the translations to qTranslate or to qTranslate-X. If a plugin works for one, it should work for other too, since qTranslate-X and qTranslate share the same database structures.
109
 
110
  == Screenshots ==
115
 
116
  == Changelog ==
117
 
118
+ = 2.9.2 =
119
+ * Option "Compatibility Functions" to enable former qTranslate function names: qtrans_getLanguage, qtrans_convertURL, qtrans_use, qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage, qtranxf_useTermLib and qtrans_getSortedLanguages
120
+ * "Language Switcher" menu options: flags=[yes|no], type=[LM|AL]. They can be used in a query string in URL field of Language Menu.
121
+
122
+ = 2.9.1 =
123
+ * JS bug fixed, which would not show any field value if no languages are yet configured for that field.
124
+
125
+ = 2.9 =
126
+ * ability to enable "Custom Fields" by either "id" or "class" attribute.
127
+ * ability to specify filters, which other theme or plugins define, to pass relevant data through the translation.
128
+ * support for <!--more--> and <!--nextpage--> tags.
129
+ * language cookie are renamed to minimize possible interference with other sites.
130
+
131
+ = 2.8 =
132
+ * added option "Show displayed language prefix when content is not available for the selected language".
133
+ * compatibility with "BuddyPress" plugin and various improvements.
134
+ * custom CSS for "qTranslate Language Chooser" widget configurable via its properties.
135
+ * now always redirects to a canonical URL, as defined by options, before displaying a page.
136
+ * use of cookies to carry the language chosen from session to session.
137
+
138
+ = 2.7.9 =
139
+ * [this does not work yet] created wrappers to make former qTranslate function names available: qtrans_getLanguage, qtrans_convertURL, qtrans_use, qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage.
140
+
141
  = 2.7.8 =
142
  * user-friendly activation hook to deactivate/import/export other qTranslate forks.
143
  * import/export settings from other forks
184
  * added 'post_title' filter to translate all titles fetched for display purpose
185
  * fixed problem with comment date display in some themes
186
 
187
+ == Known Bugs ==
188
+
189
+ * Incompatibility with plugin [WP Editor](https://wordpress.org/support/plugin/wp-editor). Language switching buttons do not change the content of main editor in pages and posts. For now, you would need to deactivate "WP Editor".
190
+ * Sometimes after a new plugin update is released, the language switching buttons disappear on the first editor page load. Refresh the page to bring them back. Apparently, it has something to do with browse caching mechanism.
191
+ * Message "The backup of this post in your browser is different from the version below" appears sometimes in the post editor. Clicking on "Restore the backup" may produce unexpected result, since backup has one language only,
192
+ the one which was active at the time of the last pressing of button "Update". The code which causes this is in /wp-includes/js/autosave.js.
193
+
194
  == Credentials ==
195
 
196
  * The code of this plugin mostly originally based on [qTranslate](https://wordpress.org/plugins/qtranslate/ "qTranslate original plugin") and [zTranslate](https://wordpress.org/plugins/ztranslate/ "zTranslate fork").
198
 
199
  == Desirable Unimplemented Features ==
200
 
201
+ * Add ability to put Language Switching buttons on other editors besides, post, pages and taxonomies.
202
  * "Quick Edit" action in category or tag list pages will update the default language only.
203
+ * If a language was switched on a page or post, but no edits were done, browser sometimes still complains about page changes, when leaving page.
204
+ * Full screen editor mode does not have language switch buttons (not applicable in WP 4.1 any more).