multilingual and available to the world using Google Translate. For support visit GTranslate Support.
Version: 2.8.58
Author: Translate AI Multilingual Solutions
Author URI: https://gtranslate.io
Text Domain: gtranslate
*/
/* Copyright 2010 - 2020 Edvard Ananyan (email : edo888@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
add_action('widgets_init', array('GTranslate', 'register'));
register_activation_hook(__FILE__, array('GTranslate', 'activate'));
register_deactivation_hook(__FILE__, array('GTranslate', 'deactivate'));
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array('GTranslate', 'settings_link'));
add_action('admin_menu', array('GTranslate', 'admin_menu'));
add_action('init', array('GTranslate', 'enqueue_scripts'));
add_action('plugins_loaded', array('GTranslate', 'load_textdomain'));
add_shortcode('GTranslate', array('GTranslate', 'get_widget_code'));
add_shortcode('gtranslate', array('GTranslate', 'get_widget_code'));
class GTranslate extends WP_Widget {
public static function activate() {
$data = array(
'gtranslate_title' => __('Website Translator', 'gtranslate'),
);
$data = get_option('GTranslate');
GTranslate::load_defaults($data);
add_option('GTranslate', $data);
}
public static function deactivate() {
// delete_option('GTranslate');
}
public static function settings_link($links) {
$settings_link = array(''.__('Settings', 'gtranslate').'');
return array_merge($links, $settings_link);
}
public static function control() {
$data = get_option('GTranslate');
?>
'.__('GTranslate Settings', 'gtranslate').' for configuration.', 'gtranslate'); ?>
Notice: Please configure GTranslate from WP-Admin -> Settings -> GTranslate to see it in action.', 'gtranslate');
else
echo $data['widget_code'];
// avoid caching issues
if($data['widget_look'] == 'dropdown_with_flags' and ($data['pro_version'] or $data['enterprise_version'])) {
echo '';
} elseif($data['widget_look'] == 'popup' and ($data['pro_version'] or $data['enterprise_version'])) {
echo '';
}
// detect browser language
if(!($data['pro_version'] or $data['enterprise_version']) and $data['detect_browser_language']) {
if($data['widget_look'] == 'flags' or $data['widget_look'] == 'dropdown_with_flags' or $data['widget_look'] == 'flags_name' or $data['widget_look'] == 'flags_code' or $data['widget_look'] == 'popup')
$allowed_languages = $data['fincl_langs'];
elseif($data['widget_look'] == 'flags_dropdown')
$allowed_languages = array_values(array_unique(array_merge($data['fincl_langs'], $data['incl_langs'])));
else
$allowed_languages = $data['incl_langs'];
$allowed_languages = json_encode($allowed_languages);
echo "";
}
echo $args['after_widget'];
}
public static function widget2($args) {
$data = get_option('GTranslate');
GTranslate::load_defaults($data);
echo $args['before_widget'];
echo $args['before_title'] . $data['gtranslate_title'] . $args['after_title'];
if(empty($data['widget_code']))
_e('Notice: Please configure GTranslate from WP-Admin -> Settings -> GTranslate to see it in action.', 'gtranslate');
else
echo $data['widget_code'];
// avoid caching issues
if($data['widget_look'] == 'dropdown_with_flags' and ($data['pro_version'] or $data['enterprise_version'])) {
echo '';
} elseif($data['widget_look'] == 'popup' and ($data['pro_version'] or $data['enterprise_version'])) {
echo '';
}
// detect browser language
if(!($data['pro_version'] or $data['enterprise_version']) and $data['detect_browser_language']) {
if($data['widget_look'] == 'flags' or $data['widget_look'] == 'dropdown_with_flags' or $data['widget_look'] == 'flags_name' or $data['widget_look'] == 'flags_code' or $data['widget_look'] == 'popup')
$allowed_languages = $data['fincl_langs'];
elseif($data['widget_look'] == 'flags_dropdown')
$allowed_languages = array_values(array_unique(array_merge($data['fincl_langs'], $data['incl_langs'])));
else
$allowed_languages = $data['incl_langs'];
$allowed_languages = json_encode($allowed_languages);
echo "";
}
echo $args['after_widget'];
}
public static function get_widget_code($atts) {
$data = get_option('GTranslate');
GTranslate::load_defaults($data);
if(empty($data['widget_code']))
return __('Notice: Please configure GTranslate from WP-Admin -> Settings -> GTranslate to see it in action.', 'gtranslate');
else {
// avoid caching issues
if($data['widget_look'] == 'dropdown_with_flags' and ($data['pro_version'] or $data['enterprise_version'])) {
$data['widget_code'] .= '';
} elseif($data['widget_look'] == 'popup' and ($data['pro_version'] or $data['enterprise_version'])) {
$data['widget_code'] .= '';
}
//$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'ru-Ru'; // debug
// detect browser language
if(!($data['pro_version'] or $data['enterprise_version']) and $data['detect_browser_language']) {
if($data['widget_look'] == 'flags' or $data['widget_look'] == 'dropdown_with_flags' or $data['widget_look'] == 'flags_name' or $data['widget_look'] == 'flags_code' or $data['widget_look'] == 'popup')
$allowed_languages = $data['fincl_langs'];
elseif($data['widget_look'] == 'flags_dropdown')
$allowed_languages = array_values(array_unique(array_merge($data['fincl_langs'], $data['incl_langs'])));
else
$allowed_languages = $data['incl_langs'];
$allowed_languages = json_encode($allowed_languages);
$data['widget_code'] .= "";
}
return $data['widget_code'];
}
}
public static function register() {
register_widget('GTranslateWidget');
}
public static function admin_menu() {
add_options_page(__('GTranslate Options', 'gtranslate'), 'GTranslate', 'administrator', 'gtranslate_options', array('GTranslate', 'options'));
}
public static function options() {
?>
prefix . '_admin_notice');
if (!isset($gt_settings['disable_admin_notices']) || (isset($gt_settings['disable_admin_notices']) && $gt_settings['disable_admin_notices'] == 0)) {
if (current_user_can('manage_options')) {
return true;
}
}
return false;
}
// Primary notice function that can be called from an outside function sending necessary variables
public function admin_notice($admin_notices) {
// Check options
if (!$this->gt_admin_notice()) {
return false;
}
foreach ($admin_notices as $slug => $admin_notice) {
// Call for spam protection
if ($this->anti_notice_spam()) {
return false;
}
// Check for proper page to display on
if (isset( $admin_notices[$slug]['pages']) and is_array( $admin_notices[$slug]['pages'])) {
if (!$this->admin_notice_pages($admin_notices[$slug]['pages'])) {
return false;
}
}
// Check for required fields
if (!$this->required_fields($admin_notices[$slug])) {
// Get the current date then set start date to either passed value or current date value and add interval
$current_date = current_time("n/j/Y");
$start = (isset($admin_notices[$slug]['start']) ? $admin_notices[$slug]['start'] : $current_date);
$start = date("n/j/Y", strtotime($start));
$end = ( isset( $admin_notices[ $slug ]['end'] ) ? $admin_notices[ $slug ]['end'] : $start );
$end = date( "n/j/Y", strtotime( $end ) );
$date_array = explode('/', $start);
$interval = (isset($admin_notices[$slug]['int']) ? $admin_notices[$slug]['int'] : 0);
$date_array[1] += $interval;
$start = date("n/j/Y", mktime(0, 0, 0, $date_array[0], $date_array[1], $date_array[2]));
// This is the main notices storage option
$admin_notices_option = get_option($this->prefix . '_admin_notice', array());
// Check if the message is already stored and if so just grab the key otherwise store the message and its associated date information
if (!array_key_exists( $slug, $admin_notices_option)) {
$admin_notices_option[$slug]['start'] = $start;
$admin_notices_option[$slug]['int'] = $interval;
update_option($this->prefix . '_admin_notice', $admin_notices_option);
}
// Sanity check to ensure we have accurate information
// New date information will not overwrite old date information
$admin_display_check = (isset($admin_notices_option[$slug]['dismissed']) ? $admin_notices_option[$slug]['dismissed'] : 0);
$admin_display_start = (isset($admin_notices_option[$slug]['start']) ? $admin_notices_option[$slug]['start'] : $start);
$admin_display_interval = (isset($admin_notices_option[$slug]['int']) ? $admin_notices_option[$slug]['int'] : $interval);
$admin_display_msg = (isset($admin_notices[$slug]['msg']) ? $admin_notices[$slug]['msg'] : '');
$admin_display_title = (isset($admin_notices[$slug]['title']) ? $admin_notices[$slug]['title'] : '');
$admin_display_link = (isset($admin_notices[$slug]['link']) ? $admin_notices[$slug]['link'] : '');
$admin_display_dismissible= (isset($admin_notices[$slug]['dismissible']) ? $admin_notices[$slug]['dismissible'] : true);
$output_css = false;
// Ensure the notice hasn't been hidden and that the current date is after the start date
if ($admin_display_check == 0 and strtotime($admin_display_start) <= strtotime($current_date)) {
// Get remaining query string
$query_str = esc_url(add_query_arg($this->prefix . '_admin_notice_ignore', $slug));
// Admin notice display output
echo '
';
echo '';
echo '
';
echo $admin_display_title;
echo '
';
echo '
';
echo $admin_display_msg;
echo '
';
echo '
' . $admin_display_link . '
';
if($admin_display_dismissible)
echo '';
echo '
';
$this->notice_spam += 1;
$output_css = true;
}
if ($output_css) {
wp_enqueue_style($this->prefix . '-admin-notices', plugins_url(plugin_basename(dirname(__FILE__))) . '/gtranslate-notices.css', array());
}
}
}
}
// Spam protection check
public function anti_notice_spam() {
if ($this->notice_spam >= $this->notice_spam_max) {
return true;
}
return false;
}
// Ignore function that gets ran at admin init to ensure any messages that were dismissed get marked
public function admin_notice_ignore() {
// If user clicks to ignore the notice, update the option to not show it again
if (isset($_GET[$this->prefix . '_admin_notice_ignore'])) {
$admin_notices_option = get_option($this->prefix . '_admin_notice', array());
$key = $_GET[$this->prefix . '_admin_notice_ignore'];
if(!preg_match('/^[a-z_0-9]+$/i', $key))
return;
$admin_notices_option[$key]['dismissed'] = 1;
update_option($this->prefix . '_admin_notice', $admin_notices_option);
$query_str = remove_query_arg($this->prefix . '_admin_notice_ignore');
wp_redirect($query_str);
exit;
}
}
// Temp Ignore function that gets ran at admin init to ensure any messages that were temp dismissed get their start date changed
public function admin_notice_temp_ignore() {
// If user clicks to temp ignore the notice, update the option to change the start date - default interval of 14 days
if (isset($_GET[$this->prefix . '_admin_notice_temp_ignore'])) {
$admin_notices_option = get_option($this->prefix . '_admin_notice', array());
$current_date = current_time("n/j/Y");
$date_array = explode('/', $current_date);
$interval = (isset($_GET['gt_int']) ? intval($_GET['gt_int']) : 14);
$date_array[1] += $interval;
$new_start = date("n/j/Y", mktime(0, 0, 0, $date_array[0], $date_array[1], $date_array[2]));
$key = $_GET[$this->prefix . '_admin_notice_temp_ignore'];
if(!preg_match('/^[a-z_0-9]+$/i', $key))
return;
$admin_notices_option[$key]['start'] = $new_start;
$admin_notices_option[$key]['dismissed'] = 0;
update_option($this->prefix . '_admin_notice', $admin_notices_option);
$query_str = remove_query_arg(array($this->prefix . '_admin_notice_temp_ignore', 'gt_int'));
wp_redirect( $query_str );
exit;
}
}
public function admin_notice_pages($pages) {
foreach ($pages as $key => $page) {
if (is_array($page)) {
if (isset($_GET['page']) and $_GET['page'] == $page[0] and isset($_GET['tab']) and $_GET['tab'] == $page[1]) {
return true;
}
} else {
if ($page == 'all') {
return true;
}
if (get_current_screen()->id === $page) {
return true;
}
if (isset($_GET['page']) and $_GET['page'] == $page) {
return true;
}
}
}
return false;
}
// Required fields check
public function required_fields( $fields ) {
if (!isset( $fields['msg']) or (isset($fields['msg']) and empty($fields['msg']))) {
return true;
}
if (!isset( $fields['title']) or (isset($fields['title']) and empty($fields['title']))) {
return true;
}
return false;
}
// Special parameters function that is to be used in any extension of this class
public function special_parameters($admin_notices) {
// Intentionally left blank
}
public function gt_admin_notices() {
$deactivate_plugins= array('WP Translator' => 'wptranslator/WPTranslator.php', 'TranslatePress' => 'translatepress-multilingual/index.php', 'Google Language Translator' => 'google-language-translator/google-language-translator.php', 'Google Website Translator' => 'google-website-translator/google-website-translator.php', 'Weglot' => 'weglot/weglot.php', 'TransPosh' => 'transposh-translation-filter-for-wordpress/transposh.php');
foreach($deactivate_plugins as $name => $plugin_file) {
if(is_plugin_active($plugin_file)) {
$deactivate_link = wp_nonce_url('plugins.php?action=deactivate&plugin='.urlencode($plugin_file ).'&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $plugin_file);
$notices['deactivate_plugin_'.strtolower(str_replace(' ', '', $name))] = array(
'title' => sprintf(__('Please deactivate %s plugin', 'gtranslate'), $name),
'msg' => sprintf(__('%s plugin causes conflicts with GTranslate.', 'gtranslate'), $name),
'link' => '
',
'dismissible' => false,
'int' => 0
);
}
}
/*
$one_week_support = esc_url(add_query_arg(array($this->prefix . '_admin_notice_ignore' => 'one_week_support')));
$notices['one_week_support'] = array(
'title' => __('Hey! How is it going?', 'gtranslate'),
'msg' => __('Thank you for using GTranslate! We hope that you have found everything you need, but if you have any questions you can use our Live Chat or Forum:', 'gtranslate'),
'link' => '
',
'int' => 1
);
*/
$two_week_review_ignore = esc_url(add_query_arg(array($this->prefix . '_admin_notice_ignore' => 'two_week_review')));
$two_week_review_temp = esc_url(add_query_arg(array($this->prefix . '_admin_notice_temp_ignore' => 'two_week_review', 'gt_int' => 6)));
$notices['two_week_review'] = array(
'title' => __('Please Leave a Review', 'gtranslate'),
'msg' => __("We hope you have enjoyed using GTranslate! Would you mind taking a few minutes to write a review on WordPress.org? Just writing a simple 'thank you' will make us happy!", 'gtranslate'),
'link' => '
',
'later_link' => $upgrade_tips_temp,
'int' => 2
);
$notices['upgrade_tips'][] = array(
'title' => __('Did you know?', 'gtranslate'),
'msg' => __('You can increase your international traffic by upgrading your GTranslate.', 'gtranslate'),
'link' => '
',
'later_link' => $upgrade_tips_temp,
'int' => 2
);
$notices['upgrade_tips'][] = array(
'title' => __('Did you know?', 'gtranslate'),
'msg' => __('You can have your translated pages indexed in search engines by upgrading your GTranslate.', 'gtranslate'),
'link' => '