Translate WordPress with GTranslate - Version 2.0.13

Version Description

  • Notifications added
Download this release

Release Info

Developer edo888
Plugin Icon 128x128 Translate WordPress with GTranslate
Version 2.0.13
Comparing to
See all releases

Code changes from version 2.0.12 to 2.0.13

Files changed (3) hide show
  1. gtranslate-notices.css +55 -0
  2. gtranslate.php +283 -5
  3. readme.txt +4 -1
gtranslate-notices.css ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .gt-admin-notice {
2
+ background: #fff;
3
+ border-color: #ED494D;
4
+ border-top: 4px;
5
+ display: block;
6
+ min-height: 68px;
7
+ padding: 10px 40px 10px 145px;
8
+ position: relative;
9
+ }
10
+ .gt-admin-notice a {
11
+ color: #ED494D;
12
+ }
13
+ .gt-notice-logo {
14
+ clear: both;
15
+ content: "";
16
+ display: block;
17
+ background-image: url(//gtranslate.net/wp-logo.png);
18
+ background-size: 125px auto;
19
+ background-repeat: no-repeat;
20
+ background-position: 0 45%;
21
+ width: 125px;
22
+ position: absolute;
23
+ top: 0;
24
+ bottom: 0;
25
+ left: 5px;
26
+ }
27
+ .gt-admin-notice > .dashicons {
28
+ color: #424242;
29
+ position: absolute;
30
+ right: 20px;
31
+ top: 40%;
32
+ }
33
+ .gt-notice-title {
34
+ font-size: 24px;
35
+ margin: 0;
36
+ }
37
+ .gt-notice-body {
38
+ font-weight: normal;
39
+ margin: 5px 0;
40
+ }
41
+ .gt-notice-body:after {
42
+ clear: both;
43
+ content: "";
44
+ display: block;
45
+ }
46
+ .gt-notice-body li {
47
+ float: left;
48
+ margin-right: 20px;
49
+ }
50
+ .gt-notice-body .dashicons {
51
+ font-size: 17px;
52
+ }
53
+ .gt-red {
54
+ color: #ED494D;
55
+ }
gtranslate.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: GTranslate
4
  Plugin URI: https://gtranslate.io/?xyz=998
5
  Description: Makes your website <strong>multilingual</strong> and available to the world using Google Translate. For support visit <a href="https://gtranslate.io/forum/">GTranslate Forum</a>.
6
- Version: 2.0.12
7
  Author: Edvard Ananyan
8
  Author URI: https://gtranslate.io
9
 
@@ -36,9 +36,11 @@ add_shortcode('gtranslate', array('GTranslate', 'get_widget_code'));
36
 
37
  if(is_admin()) {
38
  global $pagenow;
39
- if('plugins.php' === $pagenow) {
40
  add_action('in_plugin_update_message-' . basename(dirname( __FILE__ )) . '/' . basename(__FILE__), array('GTranslate', 'update_message'), 20, 2);
41
- }
 
 
42
  }
43
 
44
  class GTranslate extends WP_Widget {
@@ -424,8 +426,6 @@ function ShowWidgetPreview(widget_preview) {
424
 
425
  jQuery('head').append( jQuery('<link rel="stylesheet" type="text/css" />').attr('href', '$wp_plugin_url/gtranslate-style'+jQuery('#flag_size').val()+'.css') );
426
  jQuery('#widget_preview').html(widget_preview);
427
- if(jQuery('#widget_look').val() == 'dropdown_with_flags')
428
- jQuery('#widget_preview').prepend('<p style="color:#f44;margin-top:5px;">This look is new, if you are having issues, please post on <a href="https://gtranslate.io/forum/" target="_blank">GTranslate Forum</a></p>');
429
  }
430
 
431
  jQuery('#pro_version').attr('checked', '$pro_version'.length > 0);
@@ -1013,3 +1013,281 @@ foreach($fincl_langs as $lang)
1013
  $data['fincl_langs'] = isset($data['fincl_langs']) ? $data['fincl_langs'] : array();
1014
  }
1015
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  Plugin Name: GTranslate
4
  Plugin URI: https://gtranslate.io/?xyz=998
5
  Description: Makes your website <strong>multilingual</strong> and available to the world using Google Translate. For support visit <a href="https://gtranslate.io/forum/">GTranslate Forum</a>.
6
+ Version: 2.0.13
7
  Author: Edvard Ananyan
8
  Author URI: https://gtranslate.io
9
 
36
 
37
  if(is_admin()) {
38
  global $pagenow;
39
+ if('plugins.php' === $pagenow)
40
  add_action('in_plugin_update_message-' . basename(dirname( __FILE__ )) . '/' . basename(__FILE__), array('GTranslate', 'update_message'), 20, 2);
41
+
42
+ if(!defined('DOING_AJAX') or !DOING_AJAX)
43
+ new GTranslate_Notices();
44
  }
45
 
46
  class GTranslate extends WP_Widget {
426
 
427
  jQuery('head').append( jQuery('<link rel="stylesheet" type="text/css" />').attr('href', '$wp_plugin_url/gtranslate-style'+jQuery('#flag_size').val()+'.css') );
428
  jQuery('#widget_preview').html(widget_preview);
 
 
429
  }
430
 
431
  jQuery('#pro_version').attr('checked', '$pro_version'.length > 0);
1013
  $data['fincl_langs'] = isset($data['fincl_langs']) ? $data['fincl_langs'] : array();
1014
  }
1015
  }
1016
+
1017
+ class GTranslate_Notices {
1018
+ protected $prefix = 'gtranslate';
1019
+ public $notice_spam = 0;
1020
+ public $notice_spam_max = 1;
1021
+
1022
+ // Basic actions to run
1023
+ public function __construct() {
1024
+ // Runs the admin notice ignore function incase a dismiss button has been clicked
1025
+ add_action('admin_init', array($this, 'admin_notice_ignore'));
1026
+ // Runs the admin notice temp ignore function incase a temp dismiss link has been clicked
1027
+ add_action('admin_init', array($this, 'admin_notice_temp_ignore'));
1028
+
1029
+ // Adding notices
1030
+ add_action('admin_notices', array($this, 'gt_admin_notices'));
1031
+ }
1032
+
1033
+ // Checks to ensure notices aren't disabled and the user has the correct permissions.
1034
+ public function gt_admin_notice() {
1035
+
1036
+ $gt_settings = get_option($this->prefix . '_admin_notice');
1037
+ if (!isset($gt_settings['disable_admin_notices']) || (isset($gt_settings['disable_admin_notices']) && $gt_settings['disable_admin_notices'] == 0)) {
1038
+ if (current_user_can('manage_options')) {
1039
+ return true;
1040
+ }
1041
+ }
1042
+ return false;
1043
+ }
1044
+
1045
+ // Primary notice function that can be called from an outside function sending necessary variables
1046
+ public function admin_notice($admin_notices) {
1047
+
1048
+ // Check options
1049
+ if (!$this->gt_admin_notice()) {
1050
+ return false;
1051
+ }
1052
+
1053
+ foreach ($admin_notices as $slug => $admin_notice) {
1054
+ // Call for spam protection
1055
+
1056
+ if ($this->anti_notice_spam()) {
1057
+ return false;
1058
+ }
1059
+
1060
+ // Check for proper page to display on
1061
+ if (isset( $admin_notices[$slug]['pages']) and is_array( $admin_notices[$slug]['pages'])) {
1062
+
1063
+ if (!$this->admin_notice_pages($admin_notices[$slug]['pages'])) {
1064
+ return false;
1065
+ }
1066
+
1067
+ }
1068
+
1069
+ // Check for required fields
1070
+ if (!$this->required_fields($admin_notices[$slug])) {
1071
+
1072
+ // Get the current date then set start date to either passed value or current date value and add interval
1073
+ $current_date = current_time("n/j/Y");
1074
+ $start = (isset($admin_notices[$slug]['start']) ? $admin_notices[$slug]['start'] : $current_date);
1075
+ $start = date("n/j/Y", strtotime($start));
1076
+ $end = ( isset( $admin_notices[ $slug ]['end'] ) ? $admin_notices[ $slug ]['end'] : $start );
1077
+ $end = date( "n/j/Y", strtotime( $end ) );
1078
+ $date_array = explode('/', $start);
1079
+ $interval = (isset($admin_notices[$slug]['int']) ? $admin_notices[$slug]['int'] : 0);
1080
+ $date_array[1] += $interval;
1081
+ $start = date("n/j/Y", mktime(0, 0, 0, $date_array[0], $date_array[1], $date_array[2]));
1082
+ // This is the main notices storage option
1083
+ $admin_notices_option = get_option($this->prefix . '_admin_notice', array());
1084
+ // Check if the message is already stored and if so just grab the key otherwise store the message and its associated date information
1085
+ if (!array_key_exists( $slug, $admin_notices_option)) {
1086
+ $admin_notices_option[$slug]['start'] = $start;
1087
+ $admin_notices_option[$slug]['int'] = $interval;
1088
+ update_option($this->prefix . '_admin_notice', $admin_notices_option);
1089
+ }
1090
+
1091
+ // Sanity check to ensure we have accurate information
1092
+ // New date information will not overwrite old date information
1093
+ $admin_display_check = (isset($admin_notices_option[$slug]['dismissed']) ? $admin_notices_option[$slug]['dismissed'] : 0);
1094
+ $admin_display_start = (isset($admin_notices_option[$slug]['start']) ? $admin_notices_option[$slug]['start'] : $start);
1095
+ $admin_display_interval = (isset($admin_notices_option[$slug]['int']) ? $admin_notices_option[$slug]['int'] : $interval);
1096
+ $admin_display_msg = (isset($admin_notices[$slug]['msg']) ? $admin_notices[$slug]['msg'] : '');
1097
+ $admin_display_title = (isset($admin_notices[$slug]['title']) ? $admin_notices[$slug]['title'] : '');
1098
+ $admin_display_link = (isset($admin_notices[$slug]['link']) ? $admin_notices[$slug]['link'] : '');
1099
+ $output_css = false;
1100
+
1101
+ // Ensure the notice hasn't been hidden and that the current date is after the start date
1102
+ if ($admin_display_check == 0 and strtotime($admin_display_start) <= strtotime($current_date)) {
1103
+ // Get remaining query string
1104
+ $query_str = esc_url(add_query_arg($this->prefix . '_admin_notice_ignore', $slug));
1105
+
1106
+ // Admin notice display output
1107
+ echo '<div class="update-nag gt-admin-notice">';
1108
+ echo '<div class="gt-notice-logo"></div>';
1109
+ echo ' <p class="gt-notice-title">';
1110
+ echo $admin_display_title;
1111
+ echo ' </p>';
1112
+ echo ' <p class="gt-notice-body">';
1113
+ echo $admin_display_msg;
1114
+ echo ' </p>';
1115
+ echo '<ul class="gt-notice-body gt-red">
1116
+ ' . $admin_display_link . '
1117
+ </ul>';
1118
+ echo '<a href="' . $query_str . '" class="dashicons dashicons-dismiss"></a>';
1119
+ echo '</div>';
1120
+
1121
+ $this->notice_spam += 1;
1122
+ $output_css = true;
1123
+ }
1124
+
1125
+ if ($output_css) {
1126
+ wp_enqueue_style($this->prefix . '-admin-notices', plugins_url(plugin_basename(dirname(__FILE__))) . '/gtranslate-notices.css', array());
1127
+ }
1128
+ }
1129
+
1130
+ }
1131
+ }
1132
+
1133
+ // Spam protection check
1134
+ public function anti_notice_spam() {
1135
+ if ($this->notice_spam >= $this->notice_spam_max) {
1136
+ return true;
1137
+ }
1138
+ return false;
1139
+ }
1140
+
1141
+ // Ignore function that gets ran at admin init to ensure any messages that were dismissed get marked
1142
+ public function admin_notice_ignore() {
1143
+ // If user clicks to ignore the notice, update the option to not show it again
1144
+ if (isset($_GET[$this->prefix . '_admin_notice_ignore'])) {
1145
+ $admin_notices_option = get_option($this->prefix . '_admin_notice', array());
1146
+ $admin_notices_option[$_GET[$this->prefix . '_admin_notice_ignore']]['dismissed'] = 1;
1147
+ update_option($this->prefix . '_admin_notice', $admin_notices_option);
1148
+ $query_str = remove_query_arg($this->prefix . '_admin_notice_ignore');
1149
+ wp_redirect($query_str);
1150
+ exit;
1151
+ }
1152
+ }
1153
+
1154
+ // Temp Ignore function that gets ran at admin init to ensure any messages that were temp dismissed get their start date changed
1155
+ public function admin_notice_temp_ignore() {
1156
+ // If user clicks to temp ignore the notice, update the option to change the start date - default interval of 14 days
1157
+ if (isset($_GET[$this->prefix . '_admin_notice_temp_ignore'])) {
1158
+ $admin_notices_option = get_option($this->prefix . '_admin_notice', array());
1159
+ $current_date = current_time("n/j/Y");
1160
+ $date_array = explode('/', $current_date);
1161
+ $interval = (isset($_GET['gt_int']) ? $_GET['gt_int'] : 14);
1162
+ $date_array[1] += $interval;
1163
+ $new_start = date("n/j/Y", mktime(0, 0, 0, $date_array[0], $date_array[1], $date_array[2]));
1164
+
1165
+ $admin_notices_option[$_GET[$this->prefix . '_admin_notice_temp_ignore']]['start'] = $new_start;
1166
+ $admin_notices_option[$_GET[$this->prefix . '_admin_notice_temp_ignore']]['dismissed'] = 0;
1167
+ update_option($this->prefix . '_admin_notice', $admin_notices_option);
1168
+ $query_str = remove_query_arg(array($this->prefix . '_admin_notice_temp_ignore', 'gt_int'));
1169
+ wp_redirect( $query_str );
1170
+ exit;
1171
+ }
1172
+ }
1173
+
1174
+ public function admin_notice_pages($pages) {
1175
+ foreach ($pages as $key => $page) {
1176
+ if (is_array($page)) {
1177
+ if (isset($_GET['page']) and $_GET['page'] == $page[0] and isset($_GET['tab']) and $_GET['tab'] == $page[1]) {
1178
+ return true;
1179
+ }
1180
+ } else {
1181
+ if ($page == 'all') {
1182
+ return true;
1183
+ }
1184
+ if (get_current_screen()->id === $page) {
1185
+ return true;
1186
+ }
1187
+
1188
+ if (isset($_GET['page']) and $_GET['page'] == $page) {
1189
+ return true;
1190
+ }
1191
+ }
1192
+ }
1193
+
1194
+ return false;
1195
+ }
1196
+
1197
+ // Required fields check
1198
+ public function required_fields( $fields ) {
1199
+ if (!isset( $fields['msg']) or (isset($fields['msg']) and empty($fields['msg']))) {
1200
+ return true;
1201
+ }
1202
+ if (!isset( $fields['title']) or (isset($fields['title']) and empty($fields['title']))) {
1203
+ return true;
1204
+ }
1205
+ return false;
1206
+ }
1207
+
1208
+ // Special parameters function that is to be used in any extension of this class
1209
+ public function special_parameters($admin_notices) {
1210
+ // Intentionally left blank
1211
+ }
1212
+
1213
+ public function gt_admin_notices() {
1214
+ $two_week_review_ignore = esc_url(add_query_arg(array($this->prefix . '_admin_notice_ignore' => 'two_week_review')));
1215
+ $two_week_review_temp = esc_url(add_query_arg(array($this->prefix . '_admin_notice_temp_ignore' => 'two_week_review', 'gt_int' => 14)));
1216
+
1217
+ $notices['two_week_review'] = array(
1218
+ 'title' => 'Leave a review?',
1219
+ 'msg' => 'We hope you have enjoyed using GTranslate! Would you consider leaving us a review on WordPress.org?',
1220
+ 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://wordpress.org/support/view/plugin-reviews/gtranslate?filter=5" target="_blank">Sure! I would love to!</a></li>' .
1221
+ '<li><span class="dashicons dashicons-smiley"></span><a href="' . $two_week_review_ignore . '">I have already left a review</a></li>' .
1222
+ '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $two_week_review_temp . '">Maybe later</a></li>' .
1223
+ '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $two_week_review_ignore . '">Never show again</a></li>',
1224
+ 'later_link' => $two_week_review_temp,
1225
+ 'int' => 3
1226
+ );
1227
+
1228
+ $data = get_option('GTranslate');
1229
+ GTranslate::load_defaults($data);
1230
+
1231
+ $upgrade_tips_ignore = esc_url(add_query_arg(array($this->prefix . '_admin_notice_ignore' => 'upgrade_tips')));
1232
+ $upgrade_tips_temp = esc_url(add_query_arg(array($this->prefix . '_admin_notice_temp_ignore' => 'upgrade_tips', 'gt_int' => 5)));
1233
+
1234
+ if($data['pro_version'] != '1' and $data['enterprise_version'] != '1') {
1235
+ $notices['upgrade_tips'][] = array(
1236
+ 'title' => 'Did you know?',
1237
+ 'msg' => 'You can <b>increase</b> your international <b>traffic</b> by upgrading your GTranslate.',
1238
+ 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=998#pricing" target="_blank">Learn more</a></li>' .
1239
+ '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">Maybe later</a></li>' .
1240
+ '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">Never show again</a></li>',
1241
+ 'later_link' => $upgrade_tips_temp,
1242
+ 'int' => 1
1243
+ );
1244
+
1245
+ $notices['upgrade_tips'][] = array(
1246
+ 'title' => 'Did you know?',
1247
+ 'msg' => 'You can have your <b>translated pages indexed</b> in search engines by upgrading your GTranslate.',
1248
+ 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=998#pricing" target="_blank">Learn more</a></li>' .
1249
+ '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">Maybe later</a></li>' .
1250
+ '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">Never show again</a></li>',
1251
+ 'later_link' => $upgrade_tips_temp,
1252
+ 'int' => 1
1253
+ );
1254
+
1255
+ $notices['upgrade_tips'][] = array(
1256
+ 'title' => 'Did you know?',
1257
+ 'msg' => 'You can <b>increase</b> your <b>AdSense revenue</b> by upgrading your GTranslate.',
1258
+ 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=998#pricing" target="_blank">Learn more</a></li>' .
1259
+ '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">Maybe later</a></li>' .
1260
+ '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">Never show again</a></li>',
1261
+ 'later_link' => $upgrade_tips_temp,
1262
+ 'int' => 1
1263
+ );
1264
+
1265
+ $notices['upgrade_tips'][] = array(
1266
+ 'title' => 'Did you know?',
1267
+ 'msg' => 'You can <b>edit translations</b> by upgrading your GTranslate.',
1268
+ 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=998#pricing" target="_blank">Learn more</a></li>' .
1269
+ '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">Maybe later</a></li>' .
1270
+ '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">Never show again</a></li>',
1271
+ 'later_link' => $upgrade_tips_temp,
1272
+ 'int' => 1
1273
+ );
1274
+
1275
+ $notices['upgrade_tips'][] = array(
1276
+ 'title' => 'Did you know?',
1277
+ 'msg' => 'You can use our <b>Live Chat</b> or <b>Support Forum</b> if you have any questions.',
1278
+ 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/?xyz=998#contact" target="_blank">Live Chat</a></li>' .
1279
+ '<li><span class="dashicons dashicons-external"></span><a href="https://gtranslate.io/forum/" target="_blank">Support Forum</a></li>' .
1280
+ '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">Maybe later</a></li>' .
1281
+ '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">Never show again</a></li>',
1282
+ 'later_link' => $upgrade_tips_temp,
1283
+ 'int' => 1
1284
+ );
1285
+
1286
+ shuffle($notices['upgrade_tips']);
1287
+ $notices['upgrade_tips'] = $notices['upgrade_tips'][0];
1288
+ }
1289
+
1290
+ $this->admin_notice($notices);
1291
+ }
1292
+
1293
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Author: Edvard Ananyan
4
  Tags: widget, plugin, sidebar, google, translate, translation, localization, google translate, multilingual, multilanguage
5
  Requires at least: 2.8
6
  Tested up to: 4.5
7
- Stable tag: 2.0.12
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Donate link: https://gtranslate.io/?xyz=998#pricing
@@ -392,6 +392,9 @@ You need to go to the language you want to edit, for instance, French: http://do
392
 
393
  == Changelog ==
394
 
 
 
 
395
  = 2.0.12 =
396
  * Readme updated, demo videos added
397
  * Fixed issue in Nice dropdown look
4
  Tags: widget, plugin, sidebar, google, translate, translation, localization, google translate, multilingual, multilanguage
5
  Requires at least: 2.8
6
  Tested up to: 4.5
7
+ Stable tag: 2.0.13
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Donate link: https://gtranslate.io/?xyz=998#pricing
392
 
393
  == Changelog ==
394
 
395
+ = 2.0.13 =
396
+ * Notifications added
397
+
398
  = 2.0.12 =
399
  * Readme updated, demo videos added
400
  * Fixed issue in Nice dropdown look