PluginProbe ʕ •ᴥ•ʔ
Translate WordPress – Google Language Translator / 6.0.5
Translate WordPress – Google Language Translator v6.0.5
trunk 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.7 4.0.8 4.0.9 5.0 5.0.0 5.0.01 5.0.02 5.0.03 5.0.04 5.0.05 5.0.06 5.0.07 5.0.08 5.0.09 5.0.10 5.0.11 5.0.12 5.0.13 5.0.14 5.0.15 5.0.16 5.0.17 5.0.18 5.0.19 5.0.20 5.0.21 5.0.22 5.0.23 5.0.24 5.0.25 5.0.26 5.0.27 5.0.28 5.0.29 5.0.30 5.0.31 5.0.32 5.0.33 5.0.34 5.0.35 5.0.36 5.0.37 5.0.38 5.0.39 5.0.40 5.0.41 5.0.42 5.0.43 5.0.44 5.0.45 5.0.46 5.0.47 5.0.48 5.0.49 6.0.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.14 6.0.15 6.0.16 6.0.19 6.0.2 6.0.20 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9
google-language-translator / google-language-translator.php
google-language-translator Last commit date
css 6 years ago images 6 years ago js 6 years ago url_addon 6 years ago google-language-translator.php 6 years ago readme.txt 6 years ago widget.php 6 years ago
google-language-translator.php
2542 lines
1 <?php
2 /*
3 Plugin Name: Google Language Translator
4 Plugin URI: https://gtranslate.io/?xyz=3167
5 Version: 6.0.5
6 Description: The MOST SIMPLE Google Translator plugin. This plugin adds Google Translator to your website by using a single shortcode, [google-translator]. Settings include: layout style, hide/show specific languages, hide/show Google toolbar, and hide/show Google branding. Add the shortcode to pages, posts, and widgets.
7 Author: Translate AI Multilingual Solutions
8 Author URI: https://gtranslate.io
9 Text Domain: glt
10 */
11
12 //ini_set('display_errors', 1);
13 //ini_set('display_startup_errors', 1);
14 //error_reporting(E_ALL);
15
16 include( plugin_dir_path( __FILE__ ) . 'widget.php');
17
18 class google_language_translator {
19
20 public $languages_array;
21
22 public function __construct() {
23
24 $this->languages_array = array (
25 'af' => 'Afrikaans',
26 'sq' => 'Albanian',
27 'am' => 'Amharic',
28 'ar' => 'Arabic',
29 'hy' => 'Armenian',
30 'az' => 'Azerbaijani',
31 'eu' => 'Basque',
32 'be' => 'Belarusian',
33 'bn' => 'Bengali',
34 'bs' => 'Bosnian',
35 'bg' => 'Bulgarian',
36 'ca' => 'Catalan',
37 'ceb' => 'Cebuano',
38 'ny' => 'Chichewa',
39 'zh-CN' => 'Chinese (Simplified)',
40 'zh-TW' => 'Chinese (Traditional)',
41 'co' => 'Corsican',
42 'hr' => 'Croatian',
43 'cs' => 'Czech',
44 'da' => 'Danish',
45 'nl' => 'Dutch',
46 'en' => 'English',
47 'eo' => 'Esperanto',
48 'et' => 'Estonian',
49 'tl' => 'Filipino',
50 'fi' => 'Finnish',
51 'fr' => 'French',
52 'fy' => 'Frisian',
53 'gl' => 'Galician',
54 'ka' => 'Georgian',
55 'de' => 'German',
56 'el' => 'Greek',
57 'gu' => 'Gujarati',
58 'ht' => 'Haitian',
59 'ha' => 'Hausa',
60 'haw' => 'Hawaiian',
61 'iw' => 'Hebrew',
62 'hi' => 'Hindi',
63 'hmn' => 'Hmong',
64 'hu' => 'Hungarian',
65 'is' => 'Icelandic',
66 'ig' => 'Igbo',
67 'id' => 'Indonesian',
68 'ga' => 'Irish',
69 'it' => 'Italian',
70 'ja' => 'Japanese',
71 'jw' => 'Javanese',
72 'kn' => 'Kannada',
73 'kk' => 'Kazakh',
74 'km' => 'Khmer',
75 'ko' => 'Korean',
76 'ku' => 'Kurdish',
77 'ky' => 'Kyrgyz',
78 'lo' => 'Lao',
79 'la' => 'Latin',
80 'lv' => 'Latvian',
81 'lt' => 'Lithuanian',
82 'lb' => 'Luxembourgish',
83 'mk' => 'Macedonian',
84 'mg' => 'Malagasy',
85 'ml' => 'Malayalam',
86 'ms' => 'Malay',
87 'mt' => 'Maltese',
88 'mi' => 'Maori',
89 'mr' => 'Marathi',
90 'mn' => 'Mongolian',
91 'my' => 'Myanmar (Burmese)',
92 'ne' => 'Nepali',
93 'no' => 'Norwegian',
94 'ps' => 'Pashto',
95 'fa' => 'Persian',
96 'pl' => 'Polish',
97 'pt' => 'Portuguese',
98 'pa' => 'Punjabi',
99 'ro' => 'Romanian',
100 'ru' => 'Russian',
101 'sr' => 'Serbian',
102 'sn' => 'Shona',
103 'st' => 'Sesotho',
104 'sd' => 'Sindhi',
105 'si' => 'Sinhala',
106 'sk' => 'Slovak',
107 'sl' => 'Slovenian',
108 'sm' => 'Samoan',
109 'gd' => 'Scots Gaelic',
110 'so' => 'Somali',
111 'es' => 'Spanish',
112 'su' => 'Sundanese',
113 'sw' => 'Swahili',
114 'sv' => 'Swedish',
115 'tg' => 'Tajik',
116 'ta' => 'Tamil',
117 'te' => 'Telugu',
118 'th' => 'Thai',
119 'tr' => 'Turkish',
120 'uk' => 'Ukrainian',
121 'ur' => 'Urdu',
122 'uz' => 'Uzbek',
123 'vi' => 'Vietnamese',
124 'cy' => 'Welsh',
125 'xh' => 'Xhosa',
126 'yi' => 'Yiddish',
127 'yo' => 'Yoruba',
128 'zu' => 'Zulu',
129 );
130
131 $plugin_data = get_file_data(__FILE__, array('Version' => 'Version'), false);
132 define('PLUGIN_VER', $plugin_data['Version']);
133
134 register_activation_hook( __FILE__, array(&$this,'glt_activate'));
135 register_deactivation_hook( __FILE__, array(&$this,'glt_deactivate'));
136
137 add_action( 'admin_menu', array( &$this, 'add_my_admin_menus'));
138 add_action('admin_init',array(&$this, 'initialize_settings'));
139 add_action('wp_head',array(&$this, 'load_css'));
140 add_action('wp_footer',array(&$this, 'footer_script'));
141 add_shortcode( 'google-translator',array(&$this, 'google_translator_shortcode'));
142 add_shortcode( 'glt', array(&$this, 'google_translator_menu_language'));
143 add_filter('widget_text','do_shortcode');
144 add_filter('walker_nav_menu_start_el', array(&$this,'menu_shortcodes') , 10 , 2);
145 add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'glt_settings_link') );
146
147 if (!is_admin()) {
148 add_action('wp_enqueue_scripts',array(&$this, 'flags'));
149 }
150
151 // make sure main_lang is set correctly in config.php file
152 global $glt_url_structure, $glt_seo_active;
153 if($glt_seo_active == '1' and $glt_url_structure == 'sub_directory') {
154 include dirname(__FILE__) . '/url_addon/config.php';
155
156 $default_language = get_option('googlelanguagetranslator_language');
157 if($main_lang != $default_language) { // update main_lang in config.php
158 $config_file = dirname(__FILE__) . '/url_addon/config.php';
159 if(is_writable($config_file)) {
160 $config = file_get_contents($config_file);
161 $config = preg_replace('/\$main_lang = \'[a-z-]{2,5}\'/i', '$main_lang = \''.$default_language.'\'', $config);
162 file_put_contents($config_file, $config);
163 }
164 }
165 }
166 }
167
168 public function glt_activate() {
169 add_option('googlelanguagetranslator_active', 1);
170 add_option('googlelanguagetranslator_language','en');
171 add_option('googlelanguagetranslator_flags', 1);
172 add_option('language_display_settings',array ('en' => 1));
173 add_option('googlelanguagetranslator_translatebox','yes');
174 add_option('googlelanguagetranslator_display','Vertical');
175 add_option('googlelanguagetranslator_toolbar','Yes');
176 add_option('googlelanguagetranslator_showbranding','Yes');
177 add_option('googlelanguagetranslator_flags_alignment','flags_left');
178 add_option('googlelanguagetranslator_analytics', 0);
179 add_option('googlelanguagetranslator_analytics_id','');
180 add_option('googlelanguagetranslator_css','');
181 add_option('googlelanguagetranslator_multilanguage',0);
182 add_option('googlelanguagetranslator_floating_widget','yes');
183 add_option('googlelanguagetranslator_flag_size','18');
184 add_option('googlelanguagetranslator_flags_order','');
185 add_option('googlelanguagetranslator_english_flag_choice','');
186 add_option('googlelanguagetranslator_spanish_flag_choice','');
187 add_option('googlelanguagetranslator_portuguese_flag_choice','');
188 add_option('googlelanguagetranslator_floating_widget_text', 'Translate &raquo;');
189 add_option('googlelanguagetranslator_floating_widget_text_allow_translation', 0);
190 delete_option('googlelanguagetranslator_manage_translations',0);
191 delete_option('flag_display_settings');
192 }
193
194 public function glt_deactivate() {
195 delete_option('flag_display_settings');
196 delete_option('googlelanguagetranslator_language_option');
197 }
198
199 public function glt_settings_link ( $links ) {
200 $settings_link = array(
201 '<a href="' . admin_url( 'options-general.php?page=google_language_translator' ) . '">Settings</a>',
202 );
203 return array_merge( $links, $settings_link );
204 }
205
206 public function add_my_admin_menus(){
207 $p = add_options_page('Google Language Translator', 'Google Language Translator', 'manage_options', 'google_language_translator', array(&$this, 'page_layout_cb'));
208
209 add_action( 'load-' . $p, array(&$this, 'load_admin_js' ));
210 }
211
212 public function load_admin_js(){
213 add_action( 'admin_enqueue_scripts', array(&$this, 'enqueue_admin_js' ));
214 add_action('admin_footer',array(&$this, 'footer_script'));
215 }
216
217 public function enqueue_admin_js(){
218 wp_enqueue_script( 'jquery-ui-core');
219 wp_enqueue_script( 'jquery-ui-sortable');
220 wp_enqueue_style( 'wp-color-picker' );
221 wp_enqueue_script( 'scripts-admin', plugins_url('js/scripts-admin.js',__FILE__), array('jquery', 'wp-color-picker'), PLUGIN_VER, true);
222 wp_enqueue_script( 'scripts', plugins_url('js/scripts.js',__FILE__), array('jquery', 'wp-color-picker'), PLUGIN_VER, true);
223 wp_enqueue_script( 'scripts-google', '//translate.google.com/translate_a/element.js?cb=GoogleLanguageTranslatorInit', array('jquery'), null, true);
224
225 wp_enqueue_style( 'style.css', plugins_url('css/style.css', __FILE__),'', PLUGIN_VER,'');
226
227 if (get_option ('googlelanguagetranslator_floating_widget') == 'yes') {
228 wp_enqueue_style( 'glt-toolbar-styles', plugins_url('css/toolbar.css', __FILE__),'', PLUGIN_VER,'' );
229 }
230 }
231
232 public function flags() {
233 wp_enqueue_script( 'scripts', plugins_url('js/scripts.js',__FILE__), array('jquery'), PLUGIN_VER, true);
234 wp_enqueue_script( 'scripts-google', '//translate.google.com/translate_a/element.js?cb=GoogleLanguageTranslatorInit', array('jquery'), null, true);
235 wp_enqueue_style( 'google-language-translator', plugins_url('css/style.css', __FILE__), '', PLUGIN_VER, '');
236
237 if (get_option ('googlelanguagetranslator_floating_widget') == 'yes') {
238 wp_enqueue_style( 'glt-toolbar-styles', plugins_url('css/toolbar.css', __FILE__), '', PLUGIN_VER, '');
239 }
240 }
241
242 public function load_css() {
243 include( plugin_dir_path( __FILE__ ) . '/css/style.php');
244 }
245
246 public function google_translator_shortcode() {
247
248 if (get_option('googlelanguagetranslator_display')=='Vertical' || get_option('googlelanguagetranslator_display')=='SIMPLE'){
249 return $this->googlelanguagetranslator_vertical();
250 }
251 elseif(get_option('googlelanguagetranslator_display')=='Horizontal'){
252 return $this->googlelanguagetranslator_horizontal();
253 }
254 }
255
256 public function googlelanguagetranslator_included_languages() {
257 $get_language_choices = get_option ('language_display_settings');
258
259 foreach ($get_language_choices as $key=>$value):
260 if ($value == 1):
261 $items[] = $key;
262 endif;
263 endforeach;
264
265 $comma_separated = implode(",",array_values($items));
266 $lang = ", includedLanguages:'".$comma_separated."'";
267 return $lang;
268 }
269
270 public function analytics() {
271 if ( get_option('googlelanguagetranslator_analytics') == 1 ) {
272 $analytics_id = get_option('googlelanguagetranslator_analytics_id');
273 $analytics = "gaTrack: true, gaId: '".$analytics_id."'";
274
275 if (!empty ($analytics_id) ):
276 return ', '.$analytics;
277 endif;
278 }
279 }
280
281 public function menu_shortcodes( $item_output,$item ) {
282 if ( !empty($item->description)) {
283 $output = do_shortcode($item->description);
284
285 if ( $output != $item->description )
286 $item_output = $output;
287 }
288 return $item_output;
289 }
290
291 public function google_translator_menu_language($atts, $content = '') {
292 extract(shortcode_atts(array(
293 "language" => 'Spanish',
294 "label" => 'Spanish',
295 "image" => 'no',
296 "text" => 'yes',
297 "image_size" => '24',
298 "label" => 'Espa&ntilde;ol'
299 ), $atts));
300
301 $glt_url_structure = get_option('googlelanguagetranslator_url_structure');
302 $glt_seo_active = get_option('googlelanguagetranslator_seo_active');
303 $default_language = get_option('googlelanguagetranslator_language');
304 $english_flag_choice = get_option('googlelanguagetranslator_english_flag_choice');
305 $spanish_flag_choice = get_option('googlelanguagetranslator_spanish_flag_choice');
306 $portuguese_flag_choice = get_option('googlelanguagetranslator_portuguese_flag_choice');
307 $language_code = array_search($language,$this->languages_array);
308 $language_name = $language;
309 $language_name_flag = $language_name;
310
311 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
312 $language_name_flag = 'canada';
313 }
314 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
315 $language_name_flag = 'united-states';
316 }
317 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
318 $language_name_flag = 'mexico';
319 }
320 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
321 $language_name_flag = 'brazil';
322 }
323
324 $href = '#';
325 if($glt_seo_active == '1') {
326 $current_url = network_home_url(add_query_arg(null, null));
327 switch($glt_url_structure) {
328 case 'sub_directory':
329 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
330 break;
331 case 'sub_domain':
332 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
333 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
334 break;
335 default:
336 break;
337 }
338 }
339
340 return "<a href='".$href."' class='nturl notranslate ".$language_code." ".$language_name_flag." single-language flag' title='".$language."'>".($image=='yes' ? "<span class='flag size".$image_size."'></span>" : '') .($text=='yes' ? $label : '')."</a>";
341 }
342
343 public function footer_script() {
344 global $vertical;
345 global $horizontal;
346 global $shortcode_started;
347 $layout = get_option('googlelanguagetranslator_display');
348 $default_language = get_option('googlelanguagetranslator_language');
349 $language_choices = $this->googlelanguagetranslator_included_languages();
350 $new_languages_array_string = get_option('googlelanguagetranslator_flags_order');
351 $new_languages_array = explode(",",$new_languages_array_string);
352 $new_languages_array_codes = array_values($new_languages_array);
353 $new_languages_array_count = count($new_languages_array);
354 $english_flag_choice = get_option('googlelanguagetranslator_english_flag_choice');
355 $spanish_flag_choice = get_option('googlelanguagetranslator_spanish_flag_choice');
356 $portuguese_flag_choice = get_option('googlelanguagetranslator_portuguese_flag_choice');
357 $show_flags = get_option('googlelanguagetranslator_flags');
358 $flag_width = get_option('googlelanguagetranslator_flag_size');
359 $get_language_choices = get_option('language_display_settings');
360 $floating_widget = get_option ('googlelanguagetranslator_floating_widget');
361 $floating_widget_text = get_option ('googlelanguagetranslator_floating_widget_text');
362 $floating_widget_text_translation_allowed = get_option ('googlelanguagetranslator_floating_widget_text_allow_translation');
363 $is_active = get_option ( 'googlelanguagetranslator_active' );
364 $is_multilanguage = get_option('googlelanguagetranslator_multilanguage');
365 $glt_url_structure = get_option('googlelanguagetranslator_url_structure');
366 $glt_seo_active = get_option('googlelanguagetranslator_seo_active');
367 $str = '';
368
369 if( $is_active == 1) {
370 if ($floating_widget=='yes') {
371 $str.='<div id="glt-translate-trigger"><span'.($floating_widget_text_translation_allowed != 1 ? ' class="notranslate"' : ' class="translate"').'>'.(empty($floating_widget_text) ? 'Translate &raquo;' : $floating_widget_text).'</span></div>';
372 $str.='<div id="glt-toolbar"></div>';
373 } //endif $floating_widget
374
375 if ((($layout=='SIMPLE' && !isset($vertical)) || ($layout=='Vertical' && !isset($vertical)) || (isset($vertical) && $show_flags==0)) || (($layout=='Horizontal' && !isset($horizontal)) || (isset($horizontal) && $show_flags==0))):
376
377 $str.='<div id="flags" style="display:none" class="size'.$flag_width.'">';
378 $str.='<ul id="sortable" class="ui-sortable">';
379 if (empty($new_languages_array_string)) {
380 foreach ($this->languages_array as $key=>$value) {
381 $language_code = $key;
382 $language_name = $value;
383 $language_name_flag = $language_name;
384 if (!empty($get_language_choices[$language_code]) && $get_language_choices[$language_code]==1) {
385 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
386 $language_name_flag = 'canada';
387 }
388 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
389 $language_name_flag = 'united-states';
390 }
391 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
392 $language_name_flag = 'mexico';
393 }
394 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
395 $language_name_flag = 'brazil';
396 }
397
398 $href = '#';
399 if($glt_seo_active == '1') {
400 $current_url = network_home_url(add_query_arg(null, null));
401 switch($glt_url_structure) {
402 case 'sub_directory':
403 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
404 break;
405 case 'sub_domain':
406 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
407 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
408 break;
409 default:
410 break;
411 }
412 }
413
414 $str .= '<li id="'.$language_name.'"><a href="'.$href.'" title="'.$language_name.'" class="nturl notranslate '.$language_code.' flag '.$language_name_flag.'"></a></li>';
415 } //empty
416 }//foreach
417 } else {
418 if ($new_languages_array_count != count($get_language_choices)):
419 foreach ($get_language_choices as $key => $value) {
420 $language_code = $key;
421 $language_name = $this->languages_array[$key];
422 $language_name_flag = $language_name;
423
424 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
425 $language_name_flag = 'canada';
426 }
427 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
428 $language_name_flag = 'united-states';
429 }
430 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
431 $language_name_flag = 'mexico';
432 }
433 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
434 $language_name_flag = 'brazil';
435 }
436
437 $href = '#';
438 if($glt_seo_active == '1') {
439 $current_url = network_home_url(add_query_arg(null, null));
440 switch($glt_url_structure) {
441 case 'sub_directory':
442 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
443 break;
444 case 'sub_domain':
445 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
446 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
447 break;
448 default:
449 break;
450 }
451 }
452
453 $str.='<li id="'.$language_name.'"><a href="'.$href.'" title="'.$language_name.'" class="nturl notranslate '.$language_code.' flag '.$language_name_flag.'"></a></li>';
454 } //foreach
455 else:
456 foreach ($new_languages_array_codes as $value) {
457 $language_name = $value;
458 $language_code = array_search ($language_name, $this->languages_array);
459 $language_name_flag = $language_name;
460
461 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
462 $language_name_flag = 'canada';
463 }
464 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
465 $language_name_flag = 'united-states';
466 }
467 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
468 $language_name_flag = 'mexico';
469 }
470 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
471 $language_name_flag = 'brazil';
472 }
473
474 $href = '#';
475 if($glt_seo_active == '1') {
476 $current_url = network_home_url(add_query_arg(null, null));
477 switch($glt_url_structure) {
478 case 'sub_directory':
479 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
480 break;
481 case 'sub_domain':
482 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
483 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
484 break;
485 default:
486 break;
487 }
488 }
489
490 $str.='<li id="'.$language_name.'"><a href="'.$href.'" title="'.$language_name.'" class="nturl notranslate '.$language_code.' flag '.$language_name_flag.'"></a></li>';
491 }//foreach
492 endif;
493 }//endif
494 $str.='</ul>';
495 $str.='</div>';
496
497 endif; //layout
498 }
499
500 $language_choices = $this->googlelanguagetranslator_included_languages();
501 $layout = get_option('googlelanguagetranslator_display');
502 $is_multilanguage = get_option('googlelanguagetranslator_multilanguage');
503 $horizontal_layout = ', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL';
504 $simple_layout = ', layout: google.translate.TranslateElement.InlineLayout.SIMPLE';
505 $auto_display = ', autoDisplay: false';
506 $default_language = get_option('googlelanguagetranslator_language');
507
508 if ($is_multilanguage == 1):
509 $multilanguagePage = ', multilanguagePage:true';
510 if($glt_seo_active != '1')
511 $str.="<div id='glt-footer'>".(!isset($vertical) && !isset($horizontal) ? '<div id="google_language_translator" class="default-language-'.$default_language.'"></div>' : '')."</div><script>function GoogleLanguageTranslatorInit() { new google.translate.TranslateElement({pageLanguage: '".$default_language."'".$language_choices . ($layout=='Horizontal' ? $horizontal_layout : ($layout=='SIMPLE' ? $simple_layout : '')) . $auto_display . $multilanguagePage . $this->analytics()."}, 'google_language_translator');}</script>";
512 echo $str;
513 elseif ($is_multilanguage == 0):
514 if($glt_seo_active != '1')
515 $str.="<div id='glt-footer'>".(!isset($vertical) && !isset($horizontal) ? '<div id="google_language_translator" class="default-language-'.$default_language.'"></div>' : '')."</div><script>function GoogleLanguageTranslatorInit() { new google.translate.TranslateElement({pageLanguage: '".$default_language."'".$language_choices . ($layout=='Horizontal' ? $horizontal_layout : ($layout=='SIMPLE' ? $simple_layout : '')) . $auto_display . $this->analytics()."}, 'google_language_translator');}</script>";
516 echo $str;
517 endif; //is_multilanguage
518 }
519
520 public function googlelanguagetranslator_vertical() {
521 global $started;
522 global $vertical;
523 $vertical = 1;
524 $started = false;
525 $new_languages_array_string = get_option('googlelanguagetranslator_flags_order');
526 $new_languages_array = explode(",",$new_languages_array_string);
527 $new_languages_array_codes = array_values($new_languages_array);
528 $new_languages_array_count = count($new_languages_array);
529 $get_language_choices = get_option ('language_display_settings');
530 $show_flags = get_option('googlelanguagetranslator_flags');
531 $flag_width = get_option('googlelanguagetranslator_flag_size');
532 $default_language_code = get_option('googlelanguagetranslator_language');
533 $english_flag_choice = get_option('googlelanguagetranslator_english_flag_choice');
534 $spanish_flag_choice = get_option('googlelanguagetranslator_spanish_flag_choice');
535 $portuguese_flag_choice = get_option('googlelanguagetranslator_portuguese_flag_choice');
536 $is_active = get_option ( 'googlelanguagetranslator_active' );
537 $language_choices = $this->googlelanguagetranslator_included_languages();
538 $floating_widget = get_option ('googlelanguagetranslator_floating_widget');
539 $glt_url_structure = get_option('googlelanguagetranslator_url_structure');
540 $glt_seo_active = get_option('googlelanguagetranslator_seo_active');
541
542 $default_language = $default_language_code;
543 $str = '';
544
545 if ($is_active==1):
546 if ($show_flags==1):
547 $str.='<div id="flags" class="size'.$flag_width.'">';
548 $str.='<ul id="sortable" class="ui-sortable" style="float:left">';
549
550 if (empty($new_languages_array_string)):
551 foreach ($this->languages_array as $key=>$value) {
552 $language_code = $key;
553 $language_name = $value;
554 $language_name_flag = $language_name;
555
556 if (!empty($get_language_choices[$language_code]) && $get_language_choices[$language_code]==1) {
557 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
558 $language_name_flag = 'canada';
559 }
560 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
561 $language_name_flag = 'united-states';
562 }
563 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
564 $language_name_flag = 'mexico';
565 }
566 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
567 $language_name_flag = 'brazil';
568 }
569
570 $href = '#';
571 if($glt_seo_active == '1') {
572 $current_url = network_home_url(add_query_arg(null, null));
573 switch($glt_url_structure) {
574 case 'sub_directory':
575 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
576 break;
577 case 'sub_domain':
578 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
579 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
580 break;
581 default:
582 break;
583 }
584 }
585
586 $str.="<li id='".$language_name."'><a href='".$href."' title='".$language_name."' class='nturl notranslate ".$language_code." flag ".$language_name_flag."'></a></li>";
587 } //endif
588 }//foreach
589 else:
590 if ($new_languages_array_count != count($get_language_choices)):
591 foreach ($get_language_choices as $key => $value) {
592 $language_code = $key;
593 $language_name = $this->languages_array[$key];
594 $language_name_flag = $language_name;
595
596 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
597 $language_name_flag = 'canada';
598 }
599 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
600 $language_name_flag = 'united-states';
601 }
602 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
603 $language_name_flag = 'mexico';
604 }
605 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
606 $language_name_flag = 'brazil';
607 }
608
609 $href = '#';
610 if($glt_seo_active == '1') {
611 $current_url = network_home_url(add_query_arg(null, null));
612 switch($glt_url_structure) {
613 case 'sub_directory':
614 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
615 break;
616 case 'sub_domain':
617 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
618 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
619 break;
620 default:
621 break;
622 }
623 }
624
625 $str.='<li id="'.$language_name.'"><a href="'.$href.'" title="'.$language_name.'" class="nturl notranslate '.$language_code.' flag '.$language_name_flag.'"></a></li>';
626 } //foreach
627 else:
628 foreach ($new_languages_array_codes as $value) {
629 $language_name = $value;
630 $language_code = array_search ($language_name, $this->languages_array);
631 $language_name_flag = $language_name;
632
633 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
634 $language_name_flag = 'canada';
635 }
636 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
637 $language_name_flag = 'united-states';
638 }
639 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
640 $language_name_flag = 'mexico';
641 }
642 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
643 $language_name_flag = 'brazil';
644 }
645
646 $href = '#';
647 if($glt_seo_active == '1') {
648 $current_url = network_home_url(add_query_arg(null, null));
649 switch($glt_url_structure) {
650 case 'sub_directory':
651 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
652 break;
653 case 'sub_domain':
654 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
655 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
656 break;
657 default:
658 break;
659 }
660 }
661
662 $str.='<li id="'.$language_name.'"><a href="'.$href.'" title="'.$language_name.'" class="nturl notranslate '.$language_code.' flag '.$language_name_flag.'"></a></li>';
663 }//foreach
664 endif;
665 endif;
666
667 $str.='</ul>';
668 $str.='</div>';
669
670 endif; //show_flags
671
672 if($glt_seo_active == '1') {
673 $str .= '<div id="google_language_translator" class="default-language-'.$default_language_code.'">';
674 $str .= '<select aria-label="Website Language Selector" class="notranslate"><option value="">Select Language</option>';
675
676 $get_language_choices = get_option ('language_display_settings');
677 foreach($get_language_choices as $key => $value) {
678 if($value == 1)
679 $str .= '<option value="'.$default_language.'|'.$key.'">'.$this->languages_array[$key].'</option>';
680 }
681 $str .= '</select></div>';
682
683 $str .= '<script>';
684 if($glt_url_structure == 'sub_directory') {
685 $str .= "function doGLTTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.pathname+location.search);}var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='$default_language';if(lang == '$default_language')location.href=location.protocol+'//'+location.host+glt_request_uri;else location.href=location.protocol+'//'+location.host+'/'+lang+glt_request_uri;}";
686 } elseif($glt_url_structure == 'sub_domain') {
687 $str .= "function doGLTTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.hostname+location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.hostname+location.pathname+location.search);}var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='$default_language';location.href=location.protocol+'//'+(lang == '$default_language' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '[.]'), '')+glt_request_uri;}";
688 }
689 $str .= '</script>';
690
691 } else
692 $str.='<div id="google_language_translator" class="default-language-'.$default_language_code.'"></div>';
693
694 return $str;
695
696 endif;
697 } // End glt_vertical
698
699 public function googlelanguagetranslator_horizontal() {
700 global $started;
701 global $horizontal;
702 $horizontal = 1;
703 $started = false;
704 $new_languages_array_string = get_option('googlelanguagetranslator_flags_order');
705 $new_languages_array = explode(",",$new_languages_array_string);
706 $new_languages_array_codes = array_values($new_languages_array);
707 $new_languages_array_count = count($new_languages_array);
708 $get_language_choices = get_option ('language_display_settings');
709 $show_flags = get_option('googlelanguagetranslator_flags');
710 $flag_width = get_option('googlelanguagetranslator_flag_size');
711 $default_language_code = get_option('googlelanguagetranslator_language');
712 $english_flag_choice = get_option('googlelanguagetranslator_english_flag_choice');
713 $spanish_flag_choice = get_option('googlelanguagetranslator_spanish_flag_choice');
714 $portuguese_flag_choice = get_option('googlelanguagetranslator_portuguese_flag_choice');
715 $is_active = get_option ( 'googlelanguagetranslator_active' );
716 $language_choices = $this->googlelanguagetranslator_included_languages();
717 $floating_widget = get_option ('googlelanguagetranslator_floating_widget');
718 $glt_url_structure = get_option('googlelanguagetranslator_url_structure');
719 $glt_seo_active = get_option('googlelanguagetranslator_seo_active');
720
721 $default_language = $default_language_code;
722 $str = '';
723
724 if ($is_active==1):
725 if ($show_flags==1):
726 $str.='<div id="flags" class="size'.$flag_width.'">';
727 $str.='<ul id="sortable" class="ui-sortable" style="float:left">';
728
729 if (empty($new_languages_array_string)):
730 foreach ($this->languages_array as $key=>$value) {
731 $language_code = $key;
732 $language_name = $value;
733 $language_name_flag = $language_name;
734
735 if (!empty($get_language_choices[$language_code]) && $get_language_choices[$language_code]==1) {
736 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
737 $language_name_flag = 'canada';
738 }
739 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
740 $language_name_flag = 'united-states';
741 }
742 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
743 $language_name_flag = 'mexico';
744 }
745 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
746 $language_name_flag = 'brazil';
747 }
748
749 $href = '#';
750 if($glt_seo_active == '1') {
751 $current_url = network_home_url(add_query_arg(null, null));
752 switch($glt_url_structure) {
753 case 'sub_directory':
754 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
755 break;
756 case 'sub_domain':
757 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
758 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
759 break;
760 default:
761 break;
762 }
763 }
764
765 $str.="<li id='".$language_name."'><a href='".$href."' title='".$language_name."' class='nturl notranslate ".$language_code." flag ".$language_name_flag."'></a></li>";
766 } //endif
767 }//foreach
768 else:
769 if ($new_languages_array_count != count($get_language_choices)):
770 foreach ($get_language_choices as $key => $value) {
771 $language_code = $key;
772 $language_name = $this->languages_array[$key];
773 $language_name_flag = $language_name;
774
775 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
776 $language_name_flag = 'canada';
777 }
778 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
779 $language_name_flag = 'united-states';
780 }
781 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
782 $language_name_flag = 'mexico';
783 }
784 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
785 $language_name_flag = 'brazil';
786 }
787
788 $href = '#';
789 if($glt_seo_active == '1') {
790 $current_url = network_home_url(add_query_arg(null, null));
791 switch($glt_url_structure) {
792 case 'sub_directory':
793 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
794 break;
795 case 'sub_domain':
796 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
797 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
798 break;
799 default:
800 break;
801 }
802 }
803
804 $str.='<li id="'.$language_name.'"><a href="'.$href.'" title="'.$language_name.'" class="nturl notranslate '.$language_code.' flag '.$language_name_flag.'"></a></li>';
805 } //foreach
806 else:
807 foreach ($new_languages_array_codes as $value) {
808 $language_name = $value;
809 $language_code = array_search ($language_name, $this->languages_array);
810 $language_name_flag = $language_name;
811
812 if ( $language_name == 'English' && $english_flag_choice == 'canadian_flag') {
813 $language_name_flag = 'canada';
814 }
815 if ( $language_name == "English" && $english_flag_choice == 'us_flag') {
816 $language_name_flag = 'united-states';
817 }
818 if ( $language_name == 'Spanish' && $spanish_flag_choice == 'mexican_flag') {
819 $language_name_flag = 'mexico';
820 }
821 if ( $language_name == 'Portuguese' && $portuguese_flag_choice == 'brazilian_flag') {
822 $language_name_flag = 'brazil';
823 }
824
825 $href = '#';
826 if($glt_seo_active == '1') {
827 $current_url = network_home_url(add_query_arg(null, null));
828 switch($glt_url_structure) {
829 case 'sub_directory':
830 $href = ($language_code == $default_language) ? $current_url : '/' . $language_code . $_SERVER['REQUEST_URI'];
831 break;
832 case 'sub_domain':
833 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
834 $href = ($language_code == $default_language) ? $current_url : str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $language_code . '.' . $domain, $current_url);
835 break;
836 default:
837 break;
838 }
839 }
840
841 $str.='<li id="'.$language_name.'"><a href="'.$href.'" title="'.$language_name.'" class="nturl notranslate '.$language_code.' flag '.$language_name_flag.'"></a></li>';
842 }//foreach
843 endif;
844 endif;
845 $str.='</ul>';
846 $str.='</div>';
847
848 endif; //show_flags
849
850 if($glt_seo_active == '1') {
851 $str .= '<div id="google_language_translator" class="default-language-'.$default_language_code.'">';
852 $str .= '<select aria-label="Website Language Selector" class="notranslate"><option value="">Select Language</option>';
853
854 $get_language_choices = get_option ('language_display_settings');
855 foreach($get_language_choices as $key => $value) {
856 if($value == 1)
857 $str .= '<option value="'.$default_language.'|'.$key.'">'.$this->languages_array[$key].'</option>';
858 }
859 $str .= '</select></div>';
860
861 $str .= '<script>';
862 if($glt_url_structure == 'sub_directory') {
863 $str .= "function doGLTTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.pathname+location.search);}var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='$default_language';if(lang == '$default_language')location.href=location.protocol+'//'+location.host+glt_request_uri;else location.href=location.protocol+'//'+location.host+'/'+lang+glt_request_uri;}";
864 } elseif($glt_url_structure == 'sub_domain') {
865 $str .= "function doGLTTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.hostname+location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.hostname+location.pathname+location.search);}var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='$default_language';location.href=location.protocol+'//'+(lang == '$default_language' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '[.]'), '')+glt_request_uri;}";
866 }
867 $str .= '</script>';
868 } else
869 $str.='<div id="google_language_translator" class="default-language-'.$default_language_code.'"></div>';
870
871 return $str;
872
873 endif;
874 } // End glt_horizontal
875
876 public function initialize_settings() {
877 add_settings_section('glt_settings','Settings','','google_language_translator');
878
879 $settings_name_array = array (
880 'googlelanguagetranslator_active',
881 'googlelanguagetranslator_language',
882 'language_display_settings',
883 'googlelanguagetranslator_flags',
884 'googlelanguagetranslator_translatebox',
885 'googlelanguagetranslator_display',
886 'glt_language_switcher_width',
887 'glt_language_switcher_text_color',
888 'glt_language_switcher_bg_color',
889 'googlelanguagetranslator_toolbar',
890 'googlelanguagetranslator_showbranding',
891 'googlelanguagetranslator_flags_alignment',
892 'googlelanguagetranslator_analytics',
893 'googlelanguagetranslator_analytics_id',
894 'googlelanguagetranslator_css',
895 'googlelanguagetranslator_multilanguage',
896 'googlelanguagetranslator_floating_widget',
897 'googlelanguagetranslator_flag_size',
898 'googlelanguagetranslator_flags_order',
899 'googlelanguagetranslator_english_flag_choice',
900 'googlelanguagetranslator_spanish_flag_choice',
901 'googlelanguagetranslator_portuguese_flag_choice',
902 'googlelanguagetranslator_floating_widget_text',
903 'glt_floating_widget_text_color',
904 'googlelanguagetranslator_floating_widget_text_allow_translation',
905 'glt_floating_widget_position',
906 'glt_floating_widget_bg_color',
907 'googlelanguagetranslator_seo_active',
908 'googlelanguagetranslator_url_structure',
909 'googlelanguagetranslator_url_translation_active',
910 'googlelanguagetranslator_hreflang_tags_active',
911 );
912
913 foreach ($settings_name_array as $setting) {
914 add_settings_field( $setting,'',$setting.'_cb','google_language_translator','glt_settings');
915 register_setting( 'google_language_translator',$setting);
916 }
917 }
918
919 public function googlelanguagetranslator_active_cb() {
920 $option_name = 'googlelanguagetranslator_active' ;
921 $new_value = 1;
922 if ( get_option( $option_name ) === false ) {
923
924 // The option does not exist, so we update it.
925 update_option( $option_name, $new_value );
926 }
927
928 $options = get_option (''.$option_name.'');
929
930 $html = '<input type="checkbox" name="googlelanguagetranslator_active" id="googlelanguagetranslator_active" value="1" '.checked(1,$options,false).'/> &nbsp; Check this box to activate';
931 echo $html;
932 }
933
934 public function googlelanguagetranslator_language_cb() {
935
936 $option_name = 'googlelanguagetranslator_language';
937 $new_value = 'en';
938
939 if ( get_option( $option_name ) === false ) {
940
941 // The option does not exist, so we update it.
942 update_option( $option_name, $new_value );
943 }
944
945 $options = get_option (''.$option_name.''); ?>
946
947 <select name="googlelanguagetranslator_language" id="googlelanguagetranslator_language">
948
949 <?php
950
951 foreach ($this->languages_array as $key => $value) {
952 $language_code = $key;
953 $language_name = $value; ?>
954 <option value="<?php echo $language_code; ?>" <?php if($options==''.$language_code.''){echo "selected";}?>><?php echo $language_name; ?></option>
955 <?php } ?>
956 </select>
957 <?php
958 }
959
960 public function language_display_settings_cb() {
961 $default_language_code = get_option('googlelanguagetranslator_language');
962 $option_name = 'language_display_settings';
963 $new_value = array(''.$default_language_code.'' => 1);
964
965 if ( get_option( $option_name ) == false ) {
966 // The option does not exist, so we update it.
967 update_option( $option_name, $new_value );
968 }
969
970 $get_language_choices = get_option (''.$option_name.''); ?>
971
972 <script>jQuery(document).ready(function($) { $('.select-all-languages').on('click',function(e) { e.preventDefault(); $('.languages').find('input:checkbox').prop('checked', true); }); $('.clear-all-languages').on('click',function(e) { e.preventDefault();
973 $('.languages').find('input:checkbox').prop('checked', false); }); }); </script>
974
975 <?php
976
977 foreach ($this->languages_array as $key => $value) {
978 $language_code = $key;
979 $language_name = $value;
980 $language_code_array[] = $key;
981
982 if (!isset($get_language_choices[''.$language_code.''])) {
983 $get_language_choices[''.$language_code.''] = 0;
984 }
985
986 $items[] = $get_language_choices[''.$language_code.''];
987 $language_codes = $language_code_array;
988 $item_count = count($items);
989
990 if ($item_count == 1 || $item_count == 27 || $item_count == 53 || $item_count == 79) { ?>
991 <div class="languages" style="width:25%; float:left">
992 <?php } ?>
993 <div><input type="checkbox" name="language_display_settings[<?php echo $language_code; ?>]" value="1"<?php checked( 1,$get_language_choices[''.$language_code.'']); ?>/><?php echo $language_name; ?></div>
994 <?php
995 if ($item_count == 26 || $item_count == 52 || $item_count == 78 || $item_count == 104) { ?>
996 </div>
997 <?php }
998 } ?>
999 <div class="clear"></div>
1000 <?php
1001 }
1002
1003 public function googlelanguagetranslator_flags_cb() {
1004
1005 $option_name = 'googlelanguagetranslator_flags' ;
1006 $new_value = 1;
1007
1008 if ( get_option( $option_name ) === false ) {
1009
1010 // The option does not exist, so we update it.
1011 update_option( $option_name, $new_value );
1012 }
1013
1014 $options = get_option (''.$option_name.'');
1015
1016 $html = '<input type="checkbox" name="googlelanguagetranslator_flags" id="googlelanguagetranslator_flags" value="1" '.checked(1,$options,false).'/> &nbsp; Check to show flags';
1017
1018 echo $html;
1019 }
1020
1021 public function googlelanguagetranslator_floating_widget_cb() {
1022
1023 $option_name = 'googlelanguagetranslator_floating_widget' ;
1024 $new_value = 'yes';
1025
1026 if ( get_option( $option_name ) === false ) {
1027
1028 // The option does not exist, so we update it.
1029 update_option( $option_name, $new_value );
1030 }
1031
1032 $options = get_option (''.$option_name.''); ?>
1033
1034 <select name="googlelanguagetranslator_floating_widget" id="googlelanguagetranslator_floating_widget" style="width:170px">
1035 <option value="yes" <?php if($options=='yes'){echo "selected";}?>>Yes, show widget</option>
1036 <option value="no" <?php if($options=='no'){echo "selected";}?>>No, hide widget</option>
1037 </select>
1038 <?php }
1039
1040 public function googlelanguagetranslator_floating_widget_text_cb() {
1041
1042 $option_name = 'googlelanguagetranslator_floating_widget_text' ;
1043 $new_value = 'Translate &raquo;';
1044
1045 if ( get_option( $option_name ) === false ) {
1046 // The option does not exist, so we update it.
1047 update_option( $option_name, $new_value );
1048 }
1049
1050 $options = get_option (''.$option_name.''); ?>
1051
1052 <input type="text" name="googlelanguagetranslator_floating_widget_text" id="googlelanguagetranslator_floating_widget_text" value="<?php echo esc_attr($options); ?>" style="width:170px"/>
1053
1054 <?php }
1055
1056 public function googlelanguagetranslator_floating_widget_text_allow_translation_cb() {
1057 $option_name = 'googlelanguagetranslator_floating_widget_text_allow_translation' ;
1058 $new_value = 0;
1059
1060 if ( get_option( $option_name ) === false ) {
1061 // The option does not exist, so we update it.
1062 update_option( $option_name, $new_value );
1063 }
1064
1065 $options = get_option (''.$option_name.'');
1066
1067 $html = '<input type="checkbox" name="googlelanguagetranslator_floating_widget_text_allow_translation" id="googlelanguagetranslator_floating_widget_text_allow_translation" value="1" '.checked(1,$options,false).'/> &nbsp; Check to allow';
1068 echo $html;
1069 }
1070
1071 public function glt_floating_widget_position_cb() {
1072 $option_name = 'glt_floating_widget_position';
1073 $new_value = '';
1074
1075 if (get_option($option_name) === false):
1076 update_option($option_name, $new_value);
1077 endif;
1078
1079 $options = get_option(''.$option_name.''); ?>
1080
1081 <select name="glt_floating_widget_position" id="glt_floating_widget_position" style="width:170px">
1082 <option value="bottom_left" <?php if($options=='bottom_left'){echo "selected";}?>>Bottom left</option>
1083 <option value="bottom_center" <?php if($options=='bottom_center'){echo "selected";}?>>Bottom center</option>
1084 <option value="bottom_right" <?php if($options=='bottom_right'){echo "selected";}?>>Bottom right</option>
1085 <option value="top_left" <?php if($options=='top_left'){echo "selected";}?>>Top left</option>
1086 <option value="top_center" <?php if($options=='top_center'){echo "selected";}?>>Top center</option>
1087 <option value="top_right" <?php if($options=='top_right'){echo "selected";}?>>Top right</option>
1088 </select>
1089 <?php
1090 }
1091
1092 public function glt_floating_widget_text_color_cb() {
1093 $option_name = 'glt_floating_widget_text_color';
1094 $new_value = '#ffffff';
1095
1096 if (get_option($option_name) === false):
1097 update_option($option_name, $new_value);
1098 endif;
1099
1100 $options = get_option(''.$option_name.''); ?>
1101
1102 <input type="text" name="glt_floating_widget_text_color" id="glt_floating_widget_text_color" class="color-field" value="<?php echo $options; ?>"/>
1103 <?php
1104 }
1105
1106 public function glt_floating_widget_bg_color_cb() {
1107 $option_name = 'glt_floating_widget_bg_color';
1108 $new_value = '#f89406';
1109
1110 if (get_option($option_name) === false):
1111 update_option($option_name, $new_value);
1112 endif;
1113
1114 $options = get_option(''.$option_name.''); ?>
1115
1116 <input type="text" name="glt_floating_widget_bg_color" id="glt_floating_widget_bg_color" class="color-field" value="<?php echo $options; ?>"/>
1117 <?php
1118 }
1119
1120 public function glt_language_switcher_width_cb() {
1121
1122 $option_name = 'glt_language_switcher_width' ;
1123 $new_value = '';
1124
1125 if ( get_option( $option_name ) === false ) {
1126 update_option( $option_name, $new_value );
1127 }
1128
1129 $options = get_option (''.$option_name.''); ?>
1130
1131 <select name="glt_language_switcher_width" id="glt_language_switcher_width" style="width:110px;">
1132 <option value="100%" <?php if($options=='100%'){echo "selected";}?>>100%</option>
1133 <option value="">-------</option>
1134 <option value="150px" <?php if($options=='150px'){echo "selected";}?>>150px</option>
1135 <option value="160px" <?php if($options=='160px'){echo "selected";}?>>160px</option>
1136 <option value="170px" <?php if($options=='170px'){echo "selected";}?>>170px</option>
1137 <option value="180px" <?php if($options=='180px'){echo "selected";}?>>180px</option>
1138 <option value="190px" <?php if($options=='190px'){echo "selected";}?>>190px</option>
1139 <option value="200px" <?php if($options=='200px'){echo "selected";}?>>200px</option>
1140 <option value="210px" <?php if($options=='210px'){echo "selected";}?>>210px</option>
1141 <option value="220px" <?php if($options=='220px'){echo "selected";}?>>220px</option>
1142 <option value="230px" <?php if($options=='230px'){echo "selected";}?>>230px</option>
1143 <option value="240px" <?php if($options=='240px'){echo "selected";}?>>240px</option>
1144 <option value="250px" <?php if($options=='250px'){echo "selected";}?>>250px</option>
1145 <option value="260px" <?php if($options=='260px'){echo "selected";}?>>260px</option>
1146 <option value="270px" <?php if($options=='270px'){echo "selected";}?>>270px</option>
1147 <option value="280px" <?php if($options=='280px'){echo "selected";}?>>280px</option>
1148 <option value="290px" <?php if($options=='290px'){echo "selected";}?>>290px</option>
1149 <option value="300px" <?php if($options=='300px'){echo "selected";}?>>300px</option>
1150 </select>
1151 <?php }
1152
1153 public function glt_language_switcher_text_color_cb() {
1154 $option_name = 'glt_language_switcher_text_color';
1155 $new_value = '#32373c';
1156
1157 if (get_option($option_name) === false):
1158 update_option($option_name, $new_value);
1159 endif;
1160
1161 $options = get_option(''.$option_name.''); ?>
1162
1163 <input type="text" name="glt_language_switcher_text_color" id="glt_language_switcher_text_color" class="color-field" value="<?php echo $options; ?>"/>
1164 <?php
1165 }
1166
1167 public function glt_language_switcher_bg_color_cb() {
1168 $option_name = 'glt_language_switcher_bg_color';
1169 $new_value = '';
1170
1171 if (get_option($option_name) === false):
1172 update_option($option_name, $new_value);
1173 endif;
1174
1175 $options = get_option(''.$option_name.''); ?>
1176
1177 <input type="text" name="glt_language_switcher_bg_color" id="glt_language_switcher_bg_color" class="color-field" value="<?php echo $options; ?>"/>
1178 <?php
1179 }
1180
1181 public function googlelanguagetranslator_translatebox_cb() {
1182
1183 $option_name = 'googlelanguagetranslator_translatebox' ;
1184 $new_value = 'yes';
1185
1186 if ( get_option( $option_name ) === false ) {
1187
1188 // The option does not exist, so we update it.
1189 update_option( $option_name, $new_value );
1190 }
1191
1192 $options = get_option (''.$option_name.''); ?>
1193
1194 <select name="googlelanguagetranslator_translatebox" id="googlelanguagetranslator_translatebox" style="width:190px">
1195 <option value="yes" <?php if($options=='yes'){echo "selected";}?>>Show language switcher</option>
1196 <option value="no" <?php if($options=='no'){echo "selected";}?>>Hide language switcher</option>
1197 </select>
1198 <?php }
1199
1200 public function googlelanguagetranslator_display_cb() {
1201
1202 $option_name = 'googlelanguagetranslator_display' ;
1203 $new_value = 'Vertical';
1204
1205 if ( get_option( $option_name ) === false ) {
1206
1207 // The option does not exist, so we update it.
1208 update_option( $option_name, $new_value );
1209 }
1210
1211 $options = get_option (''.$option_name.''); ?>
1212
1213 <select name="googlelanguagetranslator_display" id="googlelanguagetranslator_display" style="width:170px;">
1214 <option value="Vertical" <?php if(get_option('googlelanguagetranslator_display')=='Vertical'){echo "selected";}?>>Vertical</option>
1215 <option value="Horizontal" <?php if(get_option('googlelanguagetranslator_display')=='Horizontal'){echo "selected";}?>>Horizontal</option>
1216 <?php
1217 $browser_lang = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? strtok(strip_tags($_SERVER['HTTP_ACCEPT_LANGUAGE']), ',') : '';
1218 if (!empty($get_http_accept_language)):
1219 $get_http_accept_language = explode(",",$browser_lang);
1220 else:
1221 $get_http_accept_language = explode(",",$browser_lang);
1222 endif;
1223 $bestlang = $get_http_accept_language[0];
1224 $bestlang_prefix = substr($get_http_accept_language[0],0,2);
1225
1226 if ($bestlang_prefix == 'en'): ?>
1227 <option value="SIMPLE" <?php if (get_option('googlelanguagetranslator_display')=='SIMPLE'){echo "selected";}?>>SIMPLE</option>
1228 <?php endif; ?>
1229 </select>
1230 <?php }
1231
1232 public function googlelanguagetranslator_toolbar_cb() {
1233
1234 $option_name = 'googlelanguagetranslator_toolbar' ;
1235 $new_value = 'Yes';
1236
1237 if ( get_option( $option_name ) === false ) {
1238
1239 // The option does not exist, so we update it.
1240 update_option( $option_name, $new_value );
1241 }
1242
1243 $options = get_option (''.$option_name.''); ?>
1244
1245 <select name="googlelanguagetranslator_toolbar" id="googlelanguagetranslator_toolbar" style="width:170px;">
1246 <option value="Yes" <?php if(get_option('googlelanguagetranslator_toolbar')=='Yes'){echo "selected";}?>>Yes</option>
1247 <option value="No" <?php if(get_option('googlelanguagetranslator_toolbar')=='No'){echo "selected";}?>>No</option>
1248 </select>
1249 <?php }
1250
1251 public function googlelanguagetranslator_showbranding_cb() {
1252
1253 $option_name = 'googlelanguagetranslator_showbranding' ;
1254 $new_value = 'Yes';
1255
1256 if ( get_option( $option_name ) === false ) {
1257
1258 // The option does not exist, so we update it.
1259 update_option( $option_name, $new_value );
1260 }
1261
1262 $options = get_option (''.$option_name.''); ?>
1263
1264 <select name="googlelanguagetranslator_showbranding" id="googlelanguagetranslator_showbranding" style="width:170px;">
1265 <option value="Yes" <?php if(get_option('googlelanguagetranslator_showbranding')=='Yes'){echo "selected";}?>>Yes</option>
1266 <option value="No" <?php if(get_option('googlelanguagetranslator_showbranding')=='No'){echo "selected";}?>>No</option>
1267 </select>
1268 <?php }
1269
1270 public function googlelanguagetranslator_flags_alignment_cb() {
1271
1272 $option_name = 'googlelanguagetranslator_flags_alignment' ;
1273 $new_value = 'flags_left';
1274
1275 if ( get_option( $option_name ) === false ) {
1276
1277 // The option does not exist, so we update it.
1278 update_option( $option_name, 'flags_left' );
1279 }
1280
1281 $options = get_option (''.$option_name.''); ?>
1282
1283 <input type="radio" name="googlelanguagetranslator_flags_alignment" id="flags_left" value="flags_left" <?php if($options=='flags_left'){echo "checked";}?>/> <label for="flags_left">Align Left</label><br/>
1284 <input type="radio" name="googlelanguagetranslator_flags_alignment" id="flags_right" value="flags_right" <?php if($options=='flags_right'){echo "checked";}?>/> <label for="flags_right">Align Right</label>
1285 <?php }
1286
1287 public function googlelanguagetranslator_analytics_cb() {
1288
1289 $option_name = 'googlelanguagetranslator_analytics' ;
1290 $new_value = 0;
1291
1292 if ( get_option( $option_name ) === false ) {
1293
1294 // The option does not exist, so we update it.
1295 update_option( $option_name, $new_value );
1296 }
1297
1298 $options = get_option (''.$option_name.'');
1299
1300 $html = '<input type="checkbox" name="googlelanguagetranslator_analytics" id="googlelanguagetranslator_analytics" value="1" '.checked(1,$options,false).'/> &nbsp; Activate Google Analytics tracking?';
1301 echo $html;
1302 }
1303
1304 public function googlelanguagetranslator_analytics_id_cb() {
1305
1306 $option_name = 'googlelanguagetranslator_analytics_id' ;
1307 $new_value = '';
1308
1309 if ( get_option( $option_name ) === false ) {
1310
1311 // The option does not exist, so we update it.
1312 update_option( $option_name, $new_value );
1313 }
1314
1315 $options = get_option (''.$option_name.'');
1316
1317 $html = '<input type="text" name="googlelanguagetranslator_analytics_id" id="googlelanguagetranslator_analytics_id" value="'.$options.'" />';
1318 echo $html;
1319 }
1320
1321 public function googlelanguagetranslator_flag_size_cb() {
1322
1323 $option_name = 'googlelanguagetranslator_flag_size' ;
1324 $new_value = '18';
1325
1326 if ( get_option( $option_name ) === false ) {
1327
1328 // The option does not exist, so we update it.
1329 update_option( $option_name, $new_value );
1330 }
1331
1332 $options = get_option (''.$option_name.''); ?>
1333
1334 <select name="googlelanguagetranslator_flag_size" id="googlelanguagetranslator_flag_size" style="width:110px;">
1335 <option value="16" <?php if($options=='16'){echo "selected";}?>>16px</option>
1336 <option value="18" <?php if($options=='18'){echo "selected";}?>>18px</option>
1337 <option value="20" <?php if($options=='20'){echo "selected";}?>>20px</option>
1338 <option value="22" <?php if($options=='22'){echo "selected";}?>>22px</option>
1339 <option value="24" <?php if($options=='24'){echo "selected";}?>>24px</option>
1340 </select>
1341 <?php }
1342
1343 public function googlelanguagetranslator_flags_order_cb() {
1344 $option_name = 'googlelanguagetranslator_flags_order';
1345 $new_value = '';
1346
1347 if ( get_option ( $option_name ) === false ) {
1348
1349 // The option does not exist, so we update it.
1350 update_option( $option_name, $new_value );
1351 }
1352
1353 $options = get_option ( ''.$option_name.'' ); ?>
1354
1355 <input type="hidden" id="order" name="googlelanguagetranslator_flags_order" value="<?php print_r(get_option('googlelanguagetranslator_flags_order')); ?>" />
1356 <?php
1357 }
1358
1359 public function googlelanguagetranslator_english_flag_choice_cb() {
1360 $option_name = 'googlelanguagetranslator_english_flag_choice';
1361 $new_value = 'us_flag';
1362
1363 if ( get_option ( $option_name ) === false ) {
1364
1365 // The option does not exist, so we update it.
1366 update_option( $option_name, $new_value );
1367 }
1368
1369 $options = get_option ( ''.$option_name.'' ); ?>
1370
1371 <select name="googlelanguagetranslator_english_flag_choice" id="googlelanguagetranslator_english_flag_choice">
1372 <option value="us_flag" <?php if($options=='us_flag'){echo "selected";}?>>U.S. Flag</option>
1373 <option value="uk_flag" <?php if ($options=='uk_flag'){echo "selected";}?>>U.K Flag</option>
1374 <option value="canadian_flag" <?php if ($options=='canadian_flag'){echo "selected";}?>>Canadian Flag</option>
1375 </select>
1376 <?php
1377 }
1378
1379 public function googlelanguagetranslator_spanish_flag_choice_cb() {
1380 $option_name = 'googlelanguagetranslator_spanish_flag_choice';
1381 $new_value = 'spanish_flag';
1382
1383 if ( get_option ( $option_name ) === false ) {
1384
1385 // The option does not exist, so we update it.
1386 update_option( $option_name, $new_value );
1387 }
1388
1389 $options = get_option ( ''.$option_name.'' ); ?>
1390
1391 <select name="googlelanguagetranslator_spanish_flag_choice" id="googlelanguagetranslator_spanish_flag_choice">
1392 <option value="spanish_flag" <?php if($options=='spanish_flag'){echo "selected";}?>>Spanish Flag</option>
1393 <option value="mexican_flag" <?php if ($options=='mexican_flag'){echo "selected";}?>>Mexican Flag</option>
1394 </select>
1395 <?php
1396 }
1397
1398 public function googlelanguagetranslator_portuguese_flag_choice_cb() {
1399 $option_name = 'googlelanguagetranslator_portuguese_flag_choice';
1400 $new_value = 'portuguese_flag';
1401
1402 if ( get_option ( $option_name ) === false ) {
1403
1404 // The option does not exist, so we update it.
1405 update_option( $option_name, $new_value );
1406 }
1407
1408 $options = get_option ( ''.$option_name.'' ); ?>
1409
1410 <select name="googlelanguagetranslator_portuguese_flag_choice" id="googlelanguagetranslator_spanish_flag_choice">
1411 <option value="portuguese_flag" <?php if($options=='portuguese_flag'){echo "selected";}?>>Portuguese Flag</option>
1412 <option value="brazilian_flag" <?php if ($options=='brazilian_flag'){echo "selected";}?>>Brazilian Flag</option>
1413 </select>
1414 <?php
1415 }
1416
1417 public function googlelanguagetranslator_seo_active_cb() {
1418 $option_name = 'googlelanguagetranslator_seo_active' ;
1419 $new_value = 0;
1420 if ( get_option( $option_name ) === false ) {
1421
1422 // The option does not exist, so we update it.
1423 update_option( $option_name, $new_value );
1424 }
1425
1426 $options = get_option (''.$option_name.'');
1427
1428 $html = '<input type="checkbox" name="googlelanguagetranslator_seo_active" id="googlelanguagetranslator_seo_active" value="1" '.checked(1,$options,false).'/>';
1429 echo $html;
1430 }
1431
1432 public function googlelanguagetranslator_url_structure_choice_cb() {
1433 $option_name = 'googlelanguagetranslator_url_structure' ;
1434
1435 if ( get_option( $option_name ) === false ) {
1436 // The option does not exist, so we update it.
1437 update_option( $option_name, 'sub_domain' );
1438 }
1439
1440 $options = get_option (''.$option_name.''); ?>
1441
1442 <input type="radio" name="googlelanguagetranslator_url_structure" id="sub_domain" value="sub_domain" <?php if($options=='sub_domain'){echo "checked";}?>/> <label for="sub_domain">Sub-domain (http://<b>es</b>.example.com/)</label><br/><br/>
1443 <input type="radio" name="googlelanguagetranslator_url_structure" id="sub_directory" value="sub_directory" <?php if($options=='sub_directory'){echo "checked";}?>/> <label for="sub_directory">Sub-directory (http://example.com/<b>de</b>/)</label>
1444 <?php }
1445
1446 public function googlelanguagetranslator_url_translation_active_cb() {
1447 $option_name = 'googlelanguagetranslator_url_translation_active' ;
1448 $new_value = 0;
1449 if ( get_option( $option_name ) === false ) {
1450
1451 // The option does not exist, so we update it.
1452 update_option( $option_name, $new_value );
1453 }
1454
1455 $options = get_option (''.$option_name.'');
1456
1457 $html = '<input type="checkbox" name="googlelanguagetranslator_url_translation_active" id="googlelanguagetranslator_url_translation_active" value="1" '.checked(1,$options,false).'/>';
1458 echo $html;
1459 }
1460
1461 public function googlelanguagetranslator_hreflang_tags_active_cb() {
1462 $option_name = 'googlelanguagetranslator_hreflang_tags_active' ;
1463 $new_value = 0;
1464 if ( get_option( $option_name ) === false ) {
1465
1466 // The option does not exist, so we update it.
1467 update_option( $option_name, $new_value );
1468 }
1469
1470 $options = get_option (''.$option_name.'');
1471
1472 $html = '<input type="checkbox" name="googlelanguagetranslator_hreflang_tags_active" id="googlelanguagetranslator_hreflang_tags_active" value="1" '.checked(1,$options,false).'/>';
1473 echo $html;
1474 }
1475
1476 public function googlelanguagetranslator_css_cb() {
1477
1478 $option_name = 'googlelanguagetranslator_css' ;
1479 $new_value = '';
1480
1481 if ( get_option( $option_name ) === false ) {
1482
1483 // The option does not exist, so we update it.
1484 update_option( $option_name, $new_value );
1485 }
1486
1487 $options = get_option (''.$option_name.'');
1488
1489 $html = '<textarea style="width:100%;" rows="5" name="googlelanguagetranslator_css" id="googlelanguagetranslator_css">'.$options.'</textarea>';
1490 echo $html;
1491 }
1492
1493 public function googlelanguagetranslator_multilanguage_cb() {
1494
1495 $option_name = 'googlelanguagetranslator_multilanguage' ;
1496 $new_value = 0;
1497
1498 if ( get_option( $option_name ) === false ) {
1499
1500 // The option does not exist, so we update it.
1501 update_option( $option_name, $new_value );
1502 }
1503
1504 $options = get_option (''.$option_name.'');
1505
1506 $html = '<input type="checkbox" name="googlelanguagetranslator_multilanguage" id="googlelanguagetranslator_multilanguage" value="1" '.checked(1,$options,false).'/> &nbsp; Turn on multilanguage mode?';
1507 echo $html;
1508 }
1509
1510 public function googlelanguagetranslator_exclude_translation_cb() {
1511
1512 $option_name = 'googlelanguagetranslator_exclude_translation';
1513 $new_value = '';
1514
1515 if (get_option($option_name) === false ) {
1516 // The option does not exist, so we update it.
1517 update_option( $option_name, $new_value );
1518 }
1519
1520 $options = get_option (''.$option_name.'');
1521
1522 $html = '<input type="text" name="'.$option_name.'" id="'.$option_name.'" value="'.$options.'" />';
1523
1524 echo $html;
1525 }
1526
1527 public function page_layout_cb() {
1528 include( plugin_dir_path( __FILE__ ) . '/css/style.php'); add_thickbox(); ?>
1529 <div id="glt-settings" class="wrap">
1530 <div id="icon-options-general" class="icon32"></div>
1531 <h2><span class="notranslate">Google Language Translator</span></h2>
1532 <form action="<?php echo admin_url( '/options.php'); ?>" method="post">
1533 <div class="metabox-holder has-right-sidebar" style="float:left; width:65%">
1534 <div class="postbox glt-main-settings" style="width: 100%">
1535 <h3 class="notranslate">Main Settings</h3>
1536 <?php settings_fields('google_language_translator'); ?>
1537 <table style="border-collapse:separate" width="100%" border="0" cellspacing="8" cellpadding="0" class="form-table">
1538 <tr>
1539 <td style="width:60%" class="notranslate">Plugin Status:</td>
1540 <td class="notranslate"><?php $this->googlelanguagetranslator_active_cb(); ?></td>
1541 </tr>
1542
1543 <tr class="notranslate">
1544 <td>Choose the original language of your website</td>
1545 <td><?php $this->googlelanguagetranslator_language_cb(); ?></td>
1546 </tr>
1547
1548 <tr class="notranslate">
1549 <td colspan="2">What languages will be active? (<a class="select-all-languages" href="#">Select All</a> | <a class="clear-all-languages" href="#">Clear</a>)</td>
1550 </tr>
1551
1552 <tr class="notranslate languages">
1553 <td colspan="2"><?php $this->language_display_settings_cb(); ?></td>
1554 </tr>
1555 </table>
1556 </div> <!-- .postbox -->
1557
1558 <div class="postbox glt-seo-settings">
1559 <h3>SEO Settings (paid) <strong style="color:red">NEW!</strong></h3>
1560 <div class="inside">
1561 <table style="border-collapse:separate" width="100%" border="0" cellspacing="8" cellpadding="0" class="form-table">
1562 <tr class="notranslate">
1563 <td class="advanced">Enable search engine indexing: &nbsp;<a href="#TB_inline?width=200&height=150&inlineId=search-engine-indexing-description" title="What is search engine indexing?" class="thickbox">Learn more</a><div id="search-engine-indexing-description" style="display:none"><p>When turned on search engines will crawl your translated pages and index them, so that your website's translated pages can appear in search engines results pages. This will increase your international traffic. Search engine indexing is an essential feature for multilingual SEO.<br><br><i>Please Note:</i> You must have <a href="https://gtranslate.io/?xyz=3167#pricing" target="_blank">GTranslate paid plan</a> to be able to use this option.</p></div></td>
1564 <td class="advanced"><?php $this->googlelanguagetranslator_seo_active_cb(); ?></td>
1565 </tr>
1566
1567 <tr class="notranslate">
1568 <td class="advanced">URL Structure:</td>
1569 <td class="advanced"><?php $this->googlelanguagetranslator_url_structure_choice_cb(); ?></td>
1570 </tr>
1571
1572 <tr class="notranslate">
1573 <td class="advanced">URL Translation: &nbsp;<a href="#TB_inline?width=200&height=150&inlineId=url-translation-description" title="What is URL translation?" class="thickbox">Learn more</a><div id="url-translation-description" style="display:none"><p>When turned on your URL slugs will be translated which will create additional keywords in other languages and increase your ranking on search engine results pages. For example http://example.com/<b>about-us</b> will become http://de.example.com/<b>uber-uns</b> for German version.<br><br><i>Please Note:</i> This feature will work only if you have GTranslate plan with URL translation option included.</p></div></td>
1574 <td class="advanced"><?php $this->googlelanguagetranslator_url_translation_active_cb(); ?></td>
1575 </tr>
1576
1577 <tr class="notranslate">
1578 <td class="advanced">Add hreflang meta tags: &nbsp;<a href="#TB_inline?width=200&height=150&inlineId=hreflang-tags-description" title="What are hreflang tags?" class="thickbox">Learn more</a><div id="hreflang-tags-description" style="display:none"><p>Hreflang tags are a technical solution for sites that have similar content in multiple languages. The owner of a multilingual site wants search engines to send people to the content in their own language. Say a user is Dutch and the page that ranks is English, but there's also a Dutch version. You would want Google to show the Dutch page in the search results for that Dutch user. This is the kind of problem hreflang was designed to solve.</p></div></td>
1579 <td class="advanced"><?php $this->googlelanguagetranslator_hreflang_tags_active_cb(); ?></td>
1580 </tr>
1581 </table>
1582 </div> <!-- .inside -->
1583 </div> <!-- .postbox -->
1584
1585 <div class="postbox glt-layout-settings" style="width: 100%">
1586 <h3 class="notranslate">Language Switcher Settings</h3>
1587 <table style="border-collapse:separate" width="100%" border="0" cellspacing="8" cellpadding="0" class="form-table">
1588
1589 <tr class="notranslate">
1590 <td class="choose_flags_intro">Language switcher width:</td>
1591 <td class="choose_flags_intro"><?php $this->glt_language_switcher_width_cb(); ?></td>
1592 </tr>
1593
1594 <tr class="notranslate">
1595 <td class="choose_flags_intro">Language switcher text color:</td>
1596 <td class="choose_flags_intro"><?php $this->glt_language_switcher_text_color_cb(); ?></td>
1597 </tr>
1598
1599 <tr class="notranslate">
1600 <td class="choose_flags_intro">Language switcher background color:</td>
1601 <td class="choose_flags_intro"><?php $this->glt_language_switcher_bg_color_cb(); ?></td>
1602 </tr>
1603
1604 <tr class="notranslate">
1605 <td class="choose_flags_intro">Show flag images?<br/>(Display up to 104 flags above the language switcher)</td>
1606 <td class="choose_flags_intro"><?php $this->googlelanguagetranslator_flags_cb(); ?></td>
1607 </tr>
1608
1609 <tr class="notranslate">
1610 <td>Show or hide the langauge switcher?</td>
1611 <td><?php $this->googlelanguagetranslator_translatebox_cb(); ?></td>
1612 </tr>
1613
1614 <tr class="notranslate">
1615 <td>Layout option:</td>
1616 <td><?php $this->googlelanguagetranslator_display_cb(); ?></td>
1617 </tr>
1618
1619 <tr class="notranslate">
1620 <td>Show Google Toolbar?</td>
1621 <td><?php $this->googlelanguagetranslator_toolbar_cb(); ?></td>
1622 </tr>
1623
1624 <tr class="notranslate">
1625 <td>Show Google Branding? &nbsp;<a href="https://developers.google.com/translate/v2/attribution" target="_blank">Learn more</a></td>
1626 <td><?php $this->googlelanguagetranslator_showbranding_cb(); ?></td>
1627 </tr>
1628
1629 <tr class="alignment notranslate">
1630 <td class="flagdisplay">Align the translator left or right?</td>
1631 <td class="flagdisplay"><?php $this->googlelanguagetranslator_flags_alignment_cb(); ?></td>
1632 </tr>
1633 </table>
1634 </div> <!-- .postbox -->
1635
1636 <div class="postbox glt-floating-widget-settings" style="width: 100%">
1637 <h3 class="notranslate">Floating Widget Settings</h3>
1638 <table style="border-collapse:separate" width="100%" border="0" cellspacing="8" cellpadding="0" class="form-table">
1639 <tr class="floating_widget_show notranslate">
1640 <td>Show floating translation widget?</td>
1641 <td><?php $this->googlelanguagetranslator_floating_widget_cb(); ?></td>
1642 </tr>
1643
1644 <tr class="floating-widget floating-widget-custom-text notranslate hidden">
1645 <td>Custom text for the floating widget:</td>
1646 <td><?php $this->googlelanguagetranslator_floating_widget_text_cb(); ?></td>
1647 </tr>
1648
1649 <tr class="floating-widget floating-widget-text-translate notranslate hidden">
1650 <td>Allow floating widget text to translate?:</td>
1651 <td><?php $this->googlelanguagetranslator_floating_widget_text_allow_translation_cb(); ?></td>
1652 </tr>
1653
1654 <tr class="floating-widget floating-widget-position notranslate hidden">
1655 <td>Floating Widget Position:</td>
1656 <td><?php $this->glt_floating_widget_position_cb(); ?></td>
1657 </tr>
1658
1659 <tr class="floating-widget floating-widget-text-color notranslate hidden">
1660 <td>Floating Widget Text Color:</td>
1661 <td><?php $this->glt_floating_widget_text_color_cb(); ?></td>
1662 </tr>
1663
1664 <tr class="floating-widget floating-widget-color notranslate hidden">
1665 <td>Floating Widget Background Color</td>
1666 <td><?php $this->glt_floating_widget_bg_color_cb(); ?></td>
1667 </tr>
1668 </table>
1669 </div> <!-- .postbox -->
1670
1671 <div class="postbox glt-behavior-settings" style="width: 100%;display:none;">
1672 <h3 class="notranslate">Behavior Settings</h3>
1673 <table style="border-collapse:separate" width="100%" border="0" cellspacing="8" cellpadding="0" class="form-table">
1674 <tr class="multilanguage notranslate">
1675 <td>Multilanguage Page option? &nbsp;<a href="#TB_inline?width=200&height=150&inlineId=multilanguage-page-description" title="What is the Multi-Language Page Option?" class="thickbox">Learn more</a><div id="multilanguage-page-description" style="display:none"><p>If you activate this setting, Google will translate all text into a single language when requested by your user, even if text is written in multiple languages. In most cases, this setting is not recommended, although for certain websites it might be necessary.</p></div></td>
1676 <td><?php $this->googlelanguagetranslator_multilanguage_cb(); ?></td>
1677 </tr>
1678
1679 <tr class="notranslate">
1680 <td>Google Analytics:</td>
1681 <td><?php $this->googlelanguagetranslator_analytics_cb(); ?></td>
1682 </tr>
1683
1684 <tr class="analytics notranslate">
1685 <td>Google Analytics ID (Ex. 'UA-11117410-2')</td>
1686 <td><?php $this->googlelanguagetranslator_analytics_id_cb(); ?></td>
1687 </tr>
1688 </table>
1689 </div> <!-- .postbox -->
1690
1691 <div class="postbox glt-usage-settings" style="width: 100%">
1692 <h3 class="notranslate">Usage</h3>
1693 <table style="border-collapse:separate" width="100%" border="0" cellspacing="8" cellpadding="0" class="form-table">
1694 <tr class="notranslate">
1695 <td>For usage in pages/posts/sidebar:</td>
1696 <td><code>[google-translator]</code></td>
1697 </tr>
1698
1699 <tr class="notranslate">
1700 <td style="width:40%">For usage in header/footer/page templates:</td>
1701 <td style="width:60%"><code>&lt;?php echo do_shortcode('[google-translator]'); ?&gt;</code></td>
1702 </tr>
1703
1704 <tr class="notranslate">
1705 <td colspan="2">Single language usage in menus/pages/posts</td>
1706 </tr>
1707
1708 <tr class="notranslate">
1709 <td colspan="2"><code>[glt language="Spanish" label="Espa&ntilde;ol" image="yes" text="yes" image_size="24"]</code></td>
1710 </tr>
1711
1712 <tr class="notranslate">
1713 <td colspan="2">
1714 <a href="#TB_inline?width=200&height=450&inlineId=single-language-shortcode-description" title="How to place a single language in your Wordpress menu" class="thickbox">How to place a single language in your Wordpress menu</a>
1715 <div id="single-language-shortcode-description" style="display:none">
1716 <p>For menu usage, you need to create a new menu, or use an existing menu, by navigating to "Appearance > Menus".</p>
1717 <p>First you will need to enable "descriptions" for your menu items, which can be found in a tab labeled "Screen Options" in the upper-right area of the page.</p>
1718 <p>Once descriptions are enabled, follow these steps:<br/>
1719 <ol>
1720 <li>Create a new menu item using "Link" as the menu item type.</li>
1721 <li>Use <code style="border:none">#</code> for the URL</li>
1722 <li>Enter a navigation label of your choice. This label does not appear on your website - it is meant only to help you identify the menu item.</li>
1723 <li>Place the following shortcode into the "description" field, and modify it to display the language and navigation label of your choice:</li>
1724 </ol>
1725 <p><code>[glt language="Spanish" label="Espa&ntilde;ol"]</code></p>
1726 </div> <!-- .single-language-shortcode-description -->
1727 </td>
1728 </tr>
1729 </table>
1730 </div> <!-- .postbox -->
1731
1732 <?php
1733 if (isset($_POST['submit'])) {
1734 if (empty($_POST['submit']) && !check_admin_referer( 'glt-save-settings', 'glt-save-settings-nonce' )) {
1735 wp_die();
1736 }
1737 }
1738 wp_nonce_field('glt-save-settings, glt-save-settings-nonce', false);
1739 submit_button();
1740 ?>
1741
1742 <p><a target="_blank" href="https://wordpress.org/support/plugin/google-language-translator/reviews/?filter=5"><?php _e('Love Google Language Translator? Give us 5 stars on WordPress.org :)', 'glt'); ?></a></p>
1743
1744 </div> <!-- .metbox-holder -->
1745
1746 <div class="metabox-holder" style="float:right; clear:right; width:33%">
1747 <div class="postbox glt-preview-settings">
1748 <h3 class="notranslate">Preview</h3>
1749 <table style="width:100%">
1750 <tr>
1751 <td style="box-sizing:border-box; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; padding:15px 15px; margin:0px"><span class="notranslate"> Drag &amp; drop flags to change their position.<br/><br/>(Note: flag order resets when flags are added/removed)</span><br/><br/><?php echo do_shortcode('[google-translator]'); ?><p class="hello"><span class="notranslate">Translated text:</span> &nbsp; <span>Hello</span></p>
1752 </td>
1753 </tr>
1754 </table>
1755 </div> <!-- .postbox -->
1756 </div> <!-- .metabox-holder -->
1757
1758 <div class="metabox-holder box-right notranslate" style="float: right; width: 33%; clear:right">
1759 <div class="postbox glt-flag-settings">
1760 <h3>Flag Settings</h3>
1761 <div class="inside">
1762 <table style="border-collapse:separate" width="100%" border="0" cellspacing="8" cellpadding="0" class="form-table">
1763 <tr class="notranslate">
1764 <td class="advanced">Select flag size:</td>
1765 <td class="advanced"><?php $this->googlelanguagetranslator_flag_size_cb(); ?></td>
1766 </tr>
1767
1768 <tr class="notranslate">
1769 <td class="advanced">Flag for English:</td>
1770 <td class="advanced"><?php $this->googlelanguagetranslator_english_flag_choice_cb(); ?></td>
1771 </tr>
1772
1773 <tr class="notranslate">
1774 <td class="advanced">Flag for Spanish:</td>
1775 <td class="advanced"><?php $this->googlelanguagetranslator_spanish_flag_choice_cb(); ?></td>
1776 </tr>
1777
1778 <tr class="notranslate">
1779 <td class="advanced">Flag for Portuguese:</td>
1780 <td class="advanced"><?php $this->googlelanguagetranslator_portuguese_flag_choice_cb(); ?></td>
1781 </tr>
1782 </table>
1783 </div> <!-- .inside -->
1784 </div> <!-- .postbox -->
1785 </div> <!-- .metabox-holder -->
1786
1787 <div class="metabox-holder box-right notranslate" style="float: right; width: 33%;">
1788 <div class="postbox glt-gtranslate-ad">
1789 <h3>Enable SEO features with GTranslate</h3>
1790 <div class="inside">
1791 <a class="wp-studio-logo" href="https://gtranslate.io/?xyz=3167#pricing" target="_blank"><img style="width:177px;" src="<?php echo plugins_url( 'images/gt_logo.svg' , __FILE__ ); ?>"></a><br />
1792 <ul id="features" style="margin-left:15px">
1793 <li style="list-style:square outside"><?php _e('Search engine indexing', 'glt'); ?></li>
1794 <li style="list-style:square outside"><?php _e('Search engine friendly (SEF) URLs', 'glt'); ?></li>
1795 <li style="list-style:square outside"><?php _e('Human level neural translations', 'glt'); ?></li>
1796 <li style="list-style:square outside"><?php _e('Edit translations manually', 'glt'); ?></li>
1797 <li style="list-style:square outside"><a href="https://gtranslate.io/website-translation-quote" title="Website Translation Price Calculator" target="_blank"><?php _e('Automatic translation post-editing service and professional translations', 'glt'); ?></a></li>
1798 <li style="list-style:square outside"><?php _e('Meta data translation (keywords, page description, etc...)', 'glt'); ?></li>
1799 <li style="list-style:square outside"><?php _e('URL/slug translation', 'glt'); ?></li>
1800 <li style="list-style:square outside"><?php _e('Language hosting (custom domain like example.fr, example.es)', 'glt'); ?></li>
1801 <li style="list-style:square outside"><?php _e('Seamless updates', 'glt'); ?></li>
1802 <li style="list-style:square outside"><?php _e('Increased international traffic and AdSense revenue', 'glt'); ?></li>
1803 <li style="list-style:square outside"><?php _e('Works in China', 'glt'); ?></li>
1804 <li style="list-style:square outside"><?php _e('Priority Live Chat support', 'glt'); ?></li>
1805 </ul>
1806
1807 <p><?php _e('Prices starting from <b>$7.99/month</b>!', 'glt'); ?></p>
1808
1809 <a href="https://gtranslate.io/?xyz=3167#pricing" target="_blank" class="button-primary"><?php _e('Try Now (15 days free)', 'glt'); ?></a> <a href="https://gtranslate.io/?xyz=3167#faq" target="_blank" class="button-primary"><?php _e('FAQ', 'glt'); ?></a> <a href="https://gtranslate.io/?xyz=3167#contact" target="_blank" class="button-primary"><?php _e('Live Chat', 'glt'); ?></a>
1810 </div> <!-- .inside -->
1811 </div> <!-- .postbox -->
1812 </div> <!-- .metabox-holder -->
1813
1814
1815 <div class="metabox-holder box-right notranslate" style="float: right; width: 33%;">
1816 <div class="postbox glt-css-settings">
1817 <h3>Add CSS Styles</h3>
1818 <div class="inside">
1819 <p>You can apply any necessary CSS styles below:</p>
1820 <?php $this->googlelanguagetranslator_css_cb(); ?>
1821 </div> <!-- .inside -->
1822 </div> <!-- .postbox -->
1823 </div> <!-- .metabox-holder -->
1824 <?php $this->googlelanguagetranslator_flags_order_cb(); ?>
1825 </form>
1826 </div> <!-- .wrap -->
1827
1828 <?php
1829 $default_language = get_option('googlelanguagetranslator_language');
1830 $glt_url_structure = get_option('googlelanguagetranslator_url_structure');
1831 $glt_seo_active = get_option('googlelanguagetranslator_seo_active');
1832
1833 $pro_version = $enterprise_version = null;
1834 if($glt_seo_active == '1' and $glt_url_structure == 'sub_domain')
1835 $pro_version = '1';
1836 if($glt_seo_active == '1' and $glt_url_structure == 'sub_directory')
1837 $enterprise_version = '1';
1838 ?>
1839 <script>window.intercomSettings = {app_id: "r70azrgx", 'platform': 'wordpress-glt', 'translate_from': '<?php echo $default_language; ?>', 'is_sub_directory': <?php echo (empty($pro_version) ? '0' : '1'); ?>, 'is_sub_domain': <?php echo (empty($enterprise_version) ? '0' : '1'); ?>};(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/r70azrgx';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>
1840 <?php
1841 }
1842 }
1843
1844 class GLT_Notices {
1845 protected $prefix = 'glt';
1846 public $notice_spam = 0;
1847 public $notice_spam_max = 3;
1848
1849 // Basic actions to run
1850 public function __construct() {
1851 // Runs the admin notice ignore function incase a dismiss button has been clicked
1852 add_action('admin_init', array($this, 'admin_notice_ignore'));
1853 // Runs the admin notice temp ignore function incase a temp dismiss link has been clicked
1854 add_action('admin_init', array($this, 'admin_notice_temp_ignore'));
1855
1856 // Adding notices
1857 add_action('admin_notices', array($this, 'glt_admin_notices'));
1858 }
1859
1860 // Checks to ensure notices aren't disabled and the user has the correct permissions.
1861 public function glt_admin_notice() {
1862
1863 $gt_settings = get_option($this->prefix . '_admin_notice');
1864 if (!isset($gt_settings['disable_admin_notices']) || (isset($gt_settings['disable_admin_notices']) && $gt_settings['disable_admin_notices'] == 0)) {
1865 if (current_user_can('manage_options')) {
1866 return true;
1867 }
1868 }
1869 return false;
1870 }
1871
1872 // Primary notice function that can be called from an outside function sending necessary variables
1873 public function admin_notice($admin_notices) {
1874
1875 // Check options
1876 if (!$this->glt_admin_notice()) {
1877 return false;
1878 }
1879
1880 foreach ($admin_notices as $slug => $admin_notice) {
1881 // Call for spam protection
1882
1883 if ($this->anti_notice_spam()) {
1884 return false;
1885 }
1886
1887 // Check for proper page to display on
1888 if (isset( $admin_notices[$slug]['pages']) and is_array( $admin_notices[$slug]['pages'])) {
1889
1890 if (!$this->admin_notice_pages($admin_notices[$slug]['pages'])) {
1891 return false;
1892 }
1893
1894 }
1895
1896 // Check for required fields
1897 if (!$this->required_fields($admin_notices[$slug])) {
1898
1899 // Get the current date then set start date to either passed value or current date value and add interval
1900 $current_date = current_time("n/j/Y");
1901 $start = (isset($admin_notices[$slug]['start']) ? $admin_notices[$slug]['start'] : $current_date);
1902 $start = date("n/j/Y", strtotime($start));
1903 $end = ( isset( $admin_notices[ $slug ]['end'] ) ? $admin_notices[ $slug ]['end'] : $start );
1904 $end = date( "n/j/Y", strtotime( $end ) );
1905 $date_array = explode('/', $start);
1906 $interval = (isset($admin_notices[$slug]['int']) ? $admin_notices[$slug]['int'] : 0);
1907 $date_array[1] += $interval;
1908 $start = date("n/j/Y", mktime(0, 0, 0, $date_array[0], $date_array[1], $date_array[2]));
1909 // This is the main notices storage option
1910 $admin_notices_option = get_option($this->prefix . '_admin_notice', array());
1911 // Check if the message is already stored and if so just grab the key otherwise store the message and its associated date information
1912 if (!array_key_exists( $slug, $admin_notices_option)) {
1913 $admin_notices_option[$slug]['start'] = $start;
1914 $admin_notices_option[$slug]['int'] = $interval;
1915 update_option($this->prefix . '_admin_notice', $admin_notices_option);
1916 }
1917
1918 // Sanity check to ensure we have accurate information
1919 // New date information will not overwrite old date information
1920 $admin_display_check = (isset($admin_notices_option[$slug]['dismissed']) ? $admin_notices_option[$slug]['dismissed'] : 0);
1921 $admin_display_start = (isset($admin_notices_option[$slug]['start']) ? $admin_notices_option[$slug]['start'] : $start);
1922 $admin_display_interval = (isset($admin_notices_option[$slug]['int']) ? $admin_notices_option[$slug]['int'] : $interval);
1923 $admin_display_msg = (isset($admin_notices[$slug]['msg']) ? $admin_notices[$slug]['msg'] : '');
1924 $admin_display_title = (isset($admin_notices[$slug]['title']) ? $admin_notices[$slug]['title'] : '');
1925 $admin_display_link = (isset($admin_notices[$slug]['link']) ? $admin_notices[$slug]['link'] : '');
1926 $admin_display_dismissible= (isset($admin_notices[$slug]['dismissible']) ? $admin_notices[$slug]['dismissible'] : true);
1927 $output_css = false;
1928
1929 // Ensure the notice hasn't been hidden and that the current date is after the start date
1930 if ($admin_display_check == 0 and strtotime($admin_display_start) <= strtotime($current_date)) {
1931 // Get remaining query string
1932 $query_str = esc_url(add_query_arg($this->prefix . '_admin_notice_ignore', $slug));
1933
1934 // Admin notice display output
1935 echo '<div class="update-nag glt-admin-notice">';
1936 echo '<div class="glt-notice-logo"></div>';
1937 echo ' <p class="glt-notice-title">';
1938 echo $admin_display_title;
1939 echo ' </p>';
1940 echo ' <p class="glt-notice-body">';
1941 echo $admin_display_msg;
1942 echo ' </p>';
1943 echo '<ul class="glt-notice-body glt-red">
1944 ' . $admin_display_link . '
1945 </ul>';
1946 if($admin_display_dismissible)
1947 echo '<a href="' . $query_str . '" class="dashicons dashicons-dismiss"></a>';
1948 echo '</div>';
1949
1950 $this->notice_spam += 1;
1951 $output_css = true;
1952 }
1953
1954 if ($output_css) {
1955 wp_enqueue_style($this->prefix . '-admin-notices', plugins_url(plugin_basename(dirname(__FILE__))) . '/css/glt-notices.css', array());
1956 }
1957 }
1958
1959 }
1960 }
1961
1962 // Spam protection check
1963 public function anti_notice_spam() {
1964 if ($this->notice_spam >= $this->notice_spam_max) {
1965 return true;
1966 }
1967 return false;
1968 }
1969
1970 // Ignore function that gets ran at admin init to ensure any messages that were dismissed get marked
1971 public function admin_notice_ignore() {
1972 // If user clicks to ignore the notice, update the option to not show it again
1973 if (isset($_GET[$this->prefix . '_admin_notice_ignore'])) {
1974 $admin_notices_option = get_option($this->prefix . '_admin_notice', array());
1975
1976 $key = $_GET[$this->prefix . '_admin_notice_ignore'];
1977 if(!preg_match('/^[a-z_0-9]+$/i', $key))
1978 return;
1979
1980 $admin_notices_option[$key]['dismissed'] = 1;
1981 update_option($this->prefix . '_admin_notice', $admin_notices_option);
1982 $query_str = remove_query_arg($this->prefix . '_admin_notice_ignore');
1983 wp_redirect($query_str);
1984 exit;
1985 }
1986 }
1987
1988 // Temp Ignore function that gets ran at admin init to ensure any messages that were temp dismissed get their start date changed
1989 public function admin_notice_temp_ignore() {
1990 // If user clicks to temp ignore the notice, update the option to change the start date - default interval of 14 days
1991 if (isset($_GET[$this->prefix . '_admin_notice_temp_ignore'])) {
1992 $admin_notices_option = get_option($this->prefix . '_admin_notice', array());
1993 $current_date = current_time("n/j/Y");
1994 $date_array = explode('/', $current_date);
1995 $interval = (isset($_GET['gt_int']) ? intval($_GET['gt_int']) : 14);
1996 $date_array[1] += $interval;
1997 $new_start = date("n/j/Y", mktime(0, 0, 0, $date_array[0], $date_array[1], $date_array[2]));
1998
1999 $key = $_GET[$this->prefix . '_admin_notice_temp_ignore'];
2000 if(!preg_match('/^[a-z_0-9]+$/i', $key))
2001 return;
2002
2003 $admin_notices_option[$key]['start'] = $new_start;
2004 $admin_notices_option[$key]['dismissed'] = 0;
2005 update_option($this->prefix . '_admin_notice', $admin_notices_option);
2006 $query_str = remove_query_arg(array($this->prefix . '_admin_notice_temp_ignore', 'gt_int'));
2007 wp_redirect( $query_str );
2008 exit;
2009 }
2010 }
2011
2012 public function admin_notice_pages($pages) {
2013 foreach ($pages as $key => $page) {
2014 if (is_array($page)) {
2015 if (isset($_GET['page']) and $_GET['page'] == $page[0] and isset($_GET['tab']) and $_GET['tab'] == $page[1]) {
2016 return true;
2017 }
2018 } else {
2019 if ($page == 'all') {
2020 return true;
2021 }
2022 if (get_current_screen()->id === $page) {
2023 return true;
2024 }
2025
2026 if (isset($_GET['page']) and $_GET['page'] == $page) {
2027 return true;
2028 }
2029 }
2030 }
2031
2032 return false;
2033 }
2034
2035 // Required fields check
2036 public function required_fields( $fields ) {
2037 if (!isset( $fields['msg']) or (isset($fields['msg']) and empty($fields['msg']))) {
2038 return true;
2039 }
2040 if (!isset( $fields['title']) or (isset($fields['title']) and empty($fields['title']))) {
2041 return true;
2042 }
2043 return false;
2044 }
2045
2046 // Special parameters function that is to be used in any extension of this class
2047 public function special_parameters($admin_notices) {
2048 // Intentionally left blank
2049 }
2050
2051 public function glt_admin_notices() {
2052
2053 $deactivate_plugins= array('WP Translator' => 'wptranslator/WPTranslator.php', 'TranslatePress' => 'translatepress-multilingual/index.php', 'Google Website Translator' => 'google-website-translator/google-website-translator.php', 'Weglot' => 'weglot/weglot.php', 'TransPosh' => 'transposh-translation-filter-for-wordpress/transposh.php');
2054 foreach($deactivate_plugins as $name => $plugin_file) {
2055 if(is_plugin_active($plugin_file)) {
2056 $deactivate_link = wp_nonce_url('plugins.php?action=deactivate&amp;plugin='.urlencode($plugin_file ).'&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $plugin_file);
2057 $notices['deactivate_plugin_'.strtolower(str_replace(' ', '', $name))] = array(
2058 'title' => sprintf(__('Please deactivate %s plugin', 'glt'), $name),
2059 'msg' => sprintf(__('%s plugin causes conflicts with Google Language Translator.', 'glt'), $name),
2060 'link' => '<li><span class="dashicons dashicons-dismiss"></span><a href="'.$deactivate_link.'">' . sprintf(__('Deactivate %s plugin', 'glt'), $name) . '</a></li>',
2061 'dismissible' => false,
2062 'int' => 0
2063 );
2064 }
2065 }
2066
2067 $glt_announcement_ignore = esc_url(add_query_arg(array($this->prefix . '_admin_notice_ignore' => 'glt_announcement')));
2068 $glt_announcement_temp = esc_url(add_query_arg(array($this->prefix . '_admin_notice_temp_ignore' => 'glt_announcement', 'gt_int' => 2)));
2069
2070 $notices['glt_announcement'] = array(
2071 'title' => __('Announcement - Google Language Translator', 'glt'),
2072 'msg' => __("<p><b>Google Language Translator</b> plugin is now a part of <b>GTranslate</b> family!</p> <p>GTranslate is a leader in website translation technology. You can continue using this plugin and enjoy <b>new SEO features</b> and free <b>Live chat support</b> brought to you by GTranslate.</p>", 'glt'),
2073 'link' => '<li><span class="dashicons dashicons-megaphone"></span><a href="https://gtranslate.io/blog/google-language-translator-becomes-part-of-gtranslate-family" target="_blank">' . __('Read More', 'glt') . '</a></li>' .
2074 '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=3167" target="_blank">' . __('Visit GTranslate', 'glt') . '</a></li>' .
2075 '<li><span class="dashicons dashicons-admin-settings"></span><a href="' . admin_url('options-general.php?page=google_language_translator') . '">' . __('Open Settings Page', 'glt') . '</a></li>' .
2076 '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $glt_announcement_temp . '">' . __('Remind me later', 'glt') . '</a></li>' .
2077 '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $glt_announcement_ignore . '">' . __('Dismiss', 'glt') . '</a></li>',
2078 'later_link' => $glt_announcement_temp,
2079 'int' => 0
2080 );
2081
2082 $two_week_review_ignore = esc_url(add_query_arg(array($this->prefix . '_admin_notice_ignore' => 'two_week_review')));
2083 $two_week_review_temp = esc_url(add_query_arg(array($this->prefix . '_admin_notice_temp_ignore' => 'two_week_review', 'gt_int' => 6)));
2084
2085 $notices['two_week_review'] = array(
2086 'title' => __('Please Leave a Review', 'glt'),
2087 'msg' => __("We hope you have enjoyed using Google Language Translator! Would you mind taking a few minutes to write a review on WordPress.org? <br>Just writing a simple <b>'thank you'</b> will make us happy!", 'glt'),
2088 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://wordpress.org/support/plugin/google-language-translator/reviews/?filter=5" target="_blank">' . __('Sure! I would love to!', 'glt') . '</a></li>' .
2089 '<li><span class="dashicons dashicons-smiley"></span><a href="' . $two_week_review_ignore . '">' . __('I have already left a review', 'glt') . '</a></li>' .
2090 '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $two_week_review_temp . '">' . __('Maybe later', 'glt') . '</a></li>' .
2091 '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $two_week_review_ignore . '">' . __('Never show again', 'glt') . '</a></li>',
2092 'later_link' => $two_week_review_temp,
2093 'int' => 5
2094 );
2095
2096 $upgrade_tips_ignore = esc_url(add_query_arg(array($this->prefix . '_admin_notice_ignore' => 'upgrade_tips')));
2097 $upgrade_tips_temp = esc_url(add_query_arg(array($this->prefix . '_admin_notice_temp_ignore' => 'upgrade_tips', 'gt_int' => 7)));
2098
2099 if(get_option('googlelanguagetranslator_seo_active') != '1') {
2100 $notices['upgrade_tips'][] = array(
2101 'title' => __('Did you know?', 'glt'),
2102 'msg' => __('You can have <b>neural machine translations</b> which are human level with GTranslate paid version.', 'glt'),
2103 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=3167#pricing" target="_blank">' . __('Learn more', 'glt') . '</a></li>' .
2104 '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'glt') . '</a></li>' .
2105 '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'glt') . '</a></li>',
2106 'later_link' => $upgrade_tips_temp,
2107 'int' => 2
2108 );
2109
2110 $notices['upgrade_tips'][] = array(
2111 'title' => __('Did you know?', 'glt'),
2112 'msg' => __('You can <b>increase</b> your international <b>traffic</b> with GTranslate paid version.', 'glt'),
2113 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=3167#pricing" target="_blank">' . __('Learn more', 'glt') . '</a></li>' .
2114 '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'glt') . '</a></li>' .
2115 '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'glt') . '</a></li>',
2116 'later_link' => $upgrade_tips_temp,
2117 'int' => 2
2118 );
2119
2120 $notices['upgrade_tips'][] = array(
2121 'title' => __('Did you know?', 'glt'),
2122 'msg' => __('You can have your <b>translated pages indexed</b> in search engines with GTranslate paid version.', 'glt'),
2123 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=3167#pricing" target="_blank">' . __('Learn more', 'glt') . '</a></li>' .
2124 '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'glt') . '</a></li>' .
2125 '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'glt') . '</a></li>',
2126 'later_link' => $upgrade_tips_temp,
2127 'int' => 2
2128 );
2129
2130 $notices['upgrade_tips'][] = array(
2131 'title' => __('Did you know?', 'glt'),
2132 'msg' => __('You can <b>increase</b> your <b>AdSense revenue</b> with GTranslate paid version.', 'glt'),
2133 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=3167#pricing" target="_blank">' . __('Learn more', 'glt') . '</a></li>' .
2134 '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'glt') . '</a></li>' .
2135 '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'glt') . '</a></li>',
2136 'later_link' => $upgrade_tips_temp,
2137 'int' => 2
2138 );
2139
2140 $notices['upgrade_tips'][] = array(
2141 'title' => __('Did you know?', 'glt'),
2142 'msg' => __('You can <b>edit translations</b> with GTranslate paid version.', 'glt'),
2143 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=3167#pricing" target="_blank">' . __('Learn more', 'glt') . '</a></li>' .
2144 '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'glt') . '</a></li>' .
2145 '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'glt') . '</a></li>',
2146 'later_link' => $upgrade_tips_temp,
2147 'int' => 2
2148 );
2149
2150 shuffle($notices['upgrade_tips']);
2151 $notices['upgrade_tips'] = $notices['upgrade_tips'][0];
2152 }
2153
2154 $this->admin_notice($notices);
2155 }
2156 }
2157
2158 if(is_admin()) {
2159 global $pagenow;
2160
2161 if(!defined('DOING_AJAX') or !DOING_AJAX)
2162 new GLT_Notices();
2163 }
2164
2165 global $glt_url_structure, $glt_seo_active;
2166
2167 $glt_url_structure = get_option('googlelanguagetranslator_url_structure');
2168 $glt_seo_active = get_option('googlelanguagetranslator_seo_active');
2169
2170 if($glt_seo_active == '1' and $glt_url_structure == 'sub_directory') { // gtranslate redirect rules with PHP (for environments with no .htaccess support (pantheon, flywheel, etc.), usually .htaccess rules override this)
2171
2172 @list($request_uri, $query_params) = explode('?', $_SERVER['REQUEST_URI']);
2173
2174 if(preg_match('/^\/(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)\/(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)\/(.*)$/', $request_uri, $matches)) {
2175 header('Location: ' . '/' . $matches[1] . '/' . $matches[3] . (empty($query_params) ? '' : '?'.$query_params), true, 301);
2176 exit;
2177 } // #1 redirect double language codes /es/en/...
2178
2179 if(preg_match('/^\/(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)$/', $request_uri)) {
2180 header('Location: ' . $request_uri . '/' . (empty($query_params) ? '' : '?'.$query_params), true, 301);
2181 exit;
2182 } // #2 add trailing slash
2183
2184 $get_language_choices = get_option ('language_display_settings');
2185 $items = array();
2186 foreach($get_language_choices as $key => $value) {
2187 if($value == 1)
2188 $items[] = $key;
2189 }
2190 $allowed_languages = implode('|', $items); // ex: en|ru|it|de
2191
2192 if(preg_match('/^\/('.$allowed_languages.')\/(.*)/', $request_uri, $matches)) {
2193 $_GET['glang'] = $matches[1];
2194 $_GET['gurl'] = rawurldecode($matches[2]);
2195
2196 require_once dirname(__FILE__) . '/url_addon/gtranslate.php';
2197 exit;
2198 } // #3 proxy translation
2199 }
2200
2201 if($glt_seo_active == '1' and ($glt_url_structure == 'sub_directory' or $glt_url_structure == 'sub_domain')) {
2202 add_action('wp_head', 'glt_request_uri_var');
2203 if(isset($_GET['page']) and $_GET['page'] == 'google_language_translator')
2204 add_action('admin_head', 'glt_request_uri_var');
2205
2206 function glt_request_uri_var() {
2207 global $glt_url_structure;
2208
2209 echo '<script>';
2210 echo "var glt_request_uri = '".addslashes($_SERVER['REQUEST_URI'])."';";
2211 echo "var glt_url_structure = '".addslashes($glt_url_structure)."';";
2212 echo "var glt_default_lang = '".addslashes(get_option('googlelanguagetranslator_language'))."';";
2213 echo '</script>';
2214 }
2215
2216 if(get_option('googlelanguagetranslator_url_translation_active') == '1') {
2217 add_action('wp_head', 'glt_url_translation_meta', 1);
2218 function glt_url_translation_meta() {
2219 echo '<meta name="uri-translation" content="on" />';
2220 }
2221 }
2222
2223 if(get_option('googlelanguagetranslator_hreflang_tags_active') == '1') {
2224 add_action('wp_head', 'glt_add_hreflang_tags', 1);
2225
2226 function glt_add_hreflang_tags() {
2227 global $glt_url_structure;
2228
2229 $default_language = get_option('googlelanguagetranslator_language');
2230 $enabled_languages = array();
2231 $get_language_choices = get_option ('language_display_settings');
2232 foreach($get_language_choices as $key => $value) {
2233 if($value == 1)
2234 $enabled_languages[] = $key;
2235 }
2236
2237 //$current_url = wp_get_canonical_url();
2238 $current_url = network_home_url(add_query_arg(null, null));
2239
2240 if($current_url !== false) {
2241 // adding default language
2242 if($default_language === 'iw')
2243 echo '<link rel="alternate" hreflang="he" href="'.esc_url($current_url).'" />'."\n";
2244 elseif($default_language === 'jw')
2245 echo '<link rel="alternate" hreflang="jv" href="'.esc_url($current_url).'" />'."\n";
2246 else
2247 echo '<link rel="alternate" hreflang="'.$default_language.'" href="'.esc_url($current_url).'" />'."\n";
2248
2249 // adding enabled languages
2250 foreach($enabled_languages as $lang) {
2251 $href = '';
2252 $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
2253
2254 if($glt_url_structure == 'sub_domain')
2255 $href = str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $lang . '.' . $domain, $current_url);
2256 elseif($glt_url_structure == 'sub_directory')
2257 $href = str_ireplace('://' . $_SERVER['HTTP_HOST'], '://' . $_SERVER['HTTP_HOST'] . '/' . $lang, $current_url);
2258
2259 if(!empty($href) and $lang != $default_language) {
2260 if($lang === 'iw')
2261 echo '<link rel="alternate" hreflang="he" href="'.esc_url($href).'" />'."\n";
2262 elseif($lang === 'jw')
2263 echo '<link rel="alternate" hreflang="jv" href="'.esc_url($href).'" />'."\n";
2264 else
2265 echo '<link rel="alternate" hreflang="'.$lang.'" href="'.esc_url($href).'" />'."\n";
2266 }
2267 }
2268 }
2269 }
2270 }
2271 }
2272
2273
2274 // translate WP REST API posts and categories data in JSON response
2275 if($glt_seo_active == '1') {
2276 function glt_rest_post($response, $post, $request) {
2277 if(isset($response->data['content']) and is_array($response->data['content']))
2278 $response->data['content']['gt_translate_keys'] = array(array('key' => 'rendered', 'format' => 'html'));
2279
2280 if(isset($response->data['excerpt']) and is_array($response->data['excerpt']))
2281 $response->data['excerpt']['gt_translate_keys'] = array(array('key' => 'rendered', 'format' => 'html'));
2282
2283 if(isset($response->data['title']) and is_array($response->data['title']))
2284 $response->data['title']['gt_translate_keys'] = array(array('key' => 'rendered', 'format' => 'text'));
2285
2286 if(isset($response->data['link']))
2287 $response->data['gt_translate_keys'] = array(array('key' => 'link', 'format' => 'url'));
2288
2289 // more fields can be added here
2290
2291 return $response;
2292 }
2293
2294 function glt_rest_category($response, $category, $request) {
2295 if(isset($response->data['description']))
2296 $response->data['gt_translate_keys'][] = array('key' => 'description', 'format' => 'html');
2297
2298 if(isset($response->data['name']))
2299 $response->data['gt_translate_keys'][] = array('key' => 'name', 'format' => 'text');
2300
2301 if(isset($response->data['link']))
2302 $response->data['gt_translate_keys'][] = array('key' => 'link', 'format' => 'url');
2303
2304 // more fields can be added here
2305
2306 return $response;
2307 }
2308
2309 add_filter('rest_prepare_post', 'glt_rest_post', 10, 3);
2310 add_filter('rest_prepare_category', 'glt_rest_category', 10, 3);
2311 }
2312
2313 // convert wp_localize_script format into JSON + JS parser
2314 if($glt_seo_active == '1') {
2315 function glt_filter_l10n_scripts() {
2316 global $wp_scripts;
2317
2318 $translate_handles = array(
2319 'agile-store-locator-script',
2320 'wmc-wizard',
2321 'wc-address-i18n',
2322 'wc-checkout',
2323 'wc-country-select',
2324 'wc-add-to-cart',
2325 'wc-password-strength-meter',
2326 'googlecode_regular',
2327 'googlecode_property',
2328 'googlecode_contact',
2329 'mapfunctions',
2330 'myhome-min',
2331
2332 );
2333
2334 //echo '<!--' . print_r($wp_scripts, true). '-->';
2335 //return;
2336
2337 foreach($wp_scripts->registered as $handle => $script) {
2338 if(isset($script->extra['data']) and in_array($handle, $translate_handles)) {
2339 $l10n = $script->extra['data'];
2340 preg_match_all('/var (.+) = ({(.*)});/', $l10n, $matches);
2341 //echo '<!--' . print_r($matches, true). '-->';
2342
2343 if(isset($matches[1]) and isset($matches[2])) {
2344 $vars = $matches[1];
2345 $scripts = $matches[2];
2346 } else
2347 continue;
2348
2349 foreach($vars as $i => $var_name) {
2350 $attribute_ids = $wp_scripts->get_data($handle, 'attribute-ids');
2351 $attribute_ids[] = $var_name . '-glt-l10n-'.$i;
2352 $jsons = $wp_scripts->get_data($handle, 'jsons');
2353 $jsons[] = $scripts[$i];
2354 $jss = $wp_scripts->get_data($handle, 'jss');
2355 $jss[] = "var $var_name = JSON.parse(document.getElementById('$var_name-glt-l10n-$i').innerHTML);";
2356
2357 $wp_scripts->add_data($handle, 'attribute-ids', $attribute_ids);
2358 $wp_scripts->add_data($handle, 'jsons', $jsons);
2359 $wp_scripts->add_data($handle, 'jss', $jss);
2360 }
2361
2362 unset($wp_scripts->registered[$handle]->extra['data']);
2363 }
2364 }
2365
2366 //echo '<!--' . print_r($wp_scripts, true). '-->';
2367
2368 }
2369
2370 function glt_add_script_attributes($tag, $handle) {
2371 global $wp_scripts;
2372
2373 glt_filter_l10n_scripts();
2374
2375 if(isset($wp_scripts->registered[$handle]->extra['attribute-ids'])) {
2376 $attribute_ids = $wp_scripts->get_data($handle, 'attribute-ids');
2377 $jsons = $wp_scripts->get_data($handle, 'jsons');
2378 $jss = $wp_scripts->get_data($handle, 'jss');
2379
2380 $return = '';
2381 foreach($attribute_ids as $i => $attribute_id) {
2382 $json = $jsons[$i];
2383 $js = $jss[$i];
2384
2385 $return .= "<script id='$attribute_id' type='application/json'>$json</script>\n<script type='text/javascript'>$js</script>\n";
2386 }
2387
2388 return $return . $tag;
2389 }
2390
2391 return $tag;
2392 }
2393
2394 // filter for woocommerce script params
2395 function glt_filter_woocommerce_scripts_data($data, $handle) {
2396 switch($handle) {
2397 case 'wc-address-i18n': {
2398 $data['gt_translate_keys'] = array(
2399 array('key' => 'locale', 'format' => 'json'),
2400 'i18n_required_text',
2401 'i18n_optional_text',
2402 );
2403
2404 $locale = json_decode($data['locale']);
2405
2406 if(isset($locale->default->address_1))
2407 $locale->default->address_1->gt_translate_keys = array('label', 'placeholder');
2408 if(isset($locale->default->address_2))
2409 $locale->default->address_2->gt_translate_keys = array('label', 'placeholder');
2410 if(isset($locale->default->city))
2411 $locale->default->city->gt_translate_keys = array('label', 'placeholder');
2412 if(isset($locale->default->postcode))
2413 $locale->default->postcode->gt_translate_keys = array('label', 'placeholder');
2414 if(isset($locale->default->state))
2415 $locale->default->state->gt_translate_keys = array('label', 'placeholder');
2416
2417 if(isset($locale->default->shipping->address_1))
2418 $locale->default->shipping->address_1->gt_translate_keys = array('label', 'placeholder');
2419 if(isset($locale->default->shipping->address_2))
2420 $locale->default->shipping->address_2->gt_translate_keys = array('label', 'placeholder');
2421 if(isset($locale->default->shipping->city))
2422 $locale->default->shipping->city->gt_translate_keys = array('label', 'placeholder');
2423 if(isset($locale->default->shipping->postcode))
2424 $locale->default->shipping->postcode->gt_translate_keys = array('label', 'placeholder');
2425 if(isset($locale->default->shipping->state))
2426 $locale->default->shipping->state->gt_translate_keys = array('label', 'placeholder');
2427
2428 if(isset($locale->default->billing->address_1))
2429 $locale->default->billing->address_1->gt_translate_keys = array('label', 'placeholder');
2430 if(isset($locale->default->billing->address_2))
2431 $locale->default->billing->address_2->gt_translate_keys = array('label', 'placeholder');
2432 if(isset($locale->default->billing->city))
2433 $locale->default->billing->city->gt_translate_keys = array('label', 'placeholder');
2434 if(isset($locale->default->billing->postcode))
2435 $locale->default->billing->postcode->gt_translate_keys = array('label', 'placeholder');
2436 if(isset($locale->default->billing->state))
2437 $locale->default->billing->state->gt_translate_keys = array('label', 'placeholder');
2438
2439 $data['locale'] = json_encode($locale);
2440 } break;
2441
2442 case 'wc-checkout': {
2443 $data['gt_translate_keys'] = array('i18n_checkout_error');
2444 } break;
2445
2446 case 'wc-country-select': {
2447 $data['gt_translate_keys'] = array('i18n_ajax_error', 'i18n_input_too_long_1', 'i18n_input_too_long_n', 'i18n_input_too_short_1', 'i18n_input_too_short_n', 'i18n_load_more', 'i18n_no_matches', 'i18n_searching', 'i18n_select_state_text', 'i18n_selection_too_long_1', 'i18n_selection_too_long_n');
2448 } break;
2449
2450 case 'wc-add-to-cart': {
2451 $data['gt_translate_keys'] = array('i18n_view_cart', array('key' => 'cart_url', 'format' => 'url'));
2452 } break;
2453
2454 case 'wc-password-strength-meter': {
2455 $data['gt_translate_keys'] = array('i18n_password_error', 'i18n_password_hint', '');
2456 } break;
2457
2458 default: break;
2459 }
2460
2461 return $data;
2462 }
2463
2464 function glt_woocommerce_geolocate_ip($false) {
2465 if(isset($_SERVER['HTTP_X_GT_VIEWER_IP']))
2466 $_SERVER['HTTP_X_REAL_IP'] = $_SERVER['HTTP_X_GT_VIEWER_IP'];
2467 elseif(isset($_SERVER['HTTP_X_GT_CLIENTIP']))
2468 $_SERVER['HTTP_X_REAL_IP'] = $_SERVER['HTTP_X_GT_CLIENTIP'];
2469
2470 return $false;
2471 }
2472
2473 //add_action('wp_print_scripts', 'glt_filter_l10n_scripts', 1);
2474 //add_action('wp_print_header_scripts', 'glt_filter_l10n_scripts', 1);
2475 //add_action('wp_print_footer_scripts', 'glt_filter_l10n_scripts', 1);
2476
2477 add_filter('script_loader_tag', 'glt_add_script_attributes', 100, 2);
2478
2479 add_filter('woocommerce_get_script_data', 'glt_filter_woocommerce_scripts_data', 10, 2 );
2480
2481 add_filter('woocommerce_geolocate_ip', 'glt_woocommerce_geolocate_ip', 10, 4);
2482 }
2483
2484 $google_language_translator = new google_language_translator();
2485
2486 function glt_update_option($old_value, $value, $option_name) {
2487 if(get_option('googlelanguagetranslator_seo_active') == '1' and get_option('googlelanguagetranslator_url_structure') == 'sub_directory') { // check if rewrite rules are in place
2488 $htaccess_file = get_home_path() . '.htaccess';
2489 // todo: use insert_with_markers functions instead
2490 if(is_writeable($htaccess_file)) {
2491 $htaccess = file_get_contents($htaccess_file);
2492 if(strpos($htaccess, 'gtranslate.php') === false) { // no config rules
2493 $rewrite_rules = file_get_contents(dirname(__FILE__) . '/url_addon/rewrite.txt');
2494 $rewrite_rules = str_replace('GLT_PLUGIN_PATH', str_replace(str_replace(array('https:', 'http:'), array(':', ':'), home_url()), '', str_replace(array('https:', 'http:'), array(':', ':'), plugins_url())) . '/google-language-translator', $rewrite_rules);
2495
2496 $htaccess = $rewrite_rules . "\r\n\r\n" . $htaccess;
2497 if(!empty($htaccess)) { // going to update .htaccess
2498 file_put_contents($htaccess_file, $htaccess);
2499
2500 add_settings_error(
2501 'glt_settings_notices',
2502 esc_attr( 'settings_updated' ),
2503 '<p style="color:red;">' . __('.htaccess file updated', 'glt') . '</p>',
2504 'updated'
2505 );
2506 }
2507 }
2508 } else {
2509 $rewrite_rules = file_get_contents(dirname(__FILE__) . '/url_addon/rewrite.txt');
2510 $rewrite_rules = str_replace('GLT_PLUGIN_PATH', str_replace(home_url(), '', plugins_url()) . '/google-language-translator', $rewrite_rules);
2511
2512 add_settings_error(
2513 'glt_settings_notices',
2514 esc_attr( 'settings_updated' ),
2515 '<p style="color:red;">' . __('Please add the following rules to the top of your .htaccess file', 'glt') . '</p><pre style="background-color:#eaeaea;">' . $rewrite_rules . '</pre>',
2516 'error'
2517 );
2518 }
2519
2520 // update main_lang in config.php
2521 $config_file = dirname(__FILE__) . '/url_addon/config.php';
2522 if(is_writable($config_file)) {
2523 $config = file_get_contents($config_file);
2524 $config = preg_replace('/\$main_lang = \'[a-z-]{2,5}\'/i', '$main_lang = \''.get_option('googlelanguagetranslator_language').'\'', $config);
2525 file_put_contents($config_file, $config);
2526 } else {
2527 add_settings_error(
2528 'glt_settings_notices',
2529 esc_attr( 'settings_updated' ),
2530 '<p style="color:red;">' . __('Cannot update google-language-translator/url_addon/config.php file. Make sure to update it manually and set correct $main_lang.', 'glt') . '</p>',
2531 'error'
2532 );
2533 }
2534
2535 } else { // todo: remove rewrite rules
2536 // do nothing
2537 }
2538 }
2539
2540 add_action('update_option_googlelanguagetranslator_seo_active', 'glt_update_option', 10, 3);
2541 add_action('update_option_googlelanguagetranslator_url_structure', 'glt_update_option', 10, 3);
2542 add_action('update_option_googlelanguagetranslator_language', 'glt_update_option', 10, 3);