0); private $current_translator = array('ID'=>0); public $messages = array(); public $dashboard_select = array(); public $settings; public $admin_texts_to_translate = array(); function __construct(){ add_action('init', array($this, 'init'), 15); if(isset($_GET['icl_tm_message'])){ $this->messages[] = array( 'type' => isset($_GET['icl_tm_message_type']) ? $_GET['icl_tm_message_type'] : 'updated', 'text' => $_GET['icl_tm_message'] ); } add_action('save_post', array($this, 'save_post_actions'), 11, 2); // calling *after* the Sitepress actions add_action('delete_post', array($this, 'delete_post_actions'), 1, 1); // calling *before* the Sitepress actions add_action('icl_ajx_custom_call', array($this, 'ajax_calls'), 10, 2); add_action('wp_ajax_show_post_content', array($this, '_show_post_content')); if(isset($_GET['sm']) && ($_GET['sm'] == 'dashboard' || $_GET['sm'] == 'jobs')){@session_start();} elseif(isset($_GET['page']) && preg_match('@/menu/translations-queue\.php$@', $_GET['page'])){@session_start();} add_filter('icl_additional_translators', array($this, 'icl_additional_translators'), 99, 3); add_filter('icl_translators_list', array($this, 'icanlocalize_translators_list')); add_action('user_register', array($this, 'clear_cache')); add_action('profile_update', array($this, 'clear_cache')); add_action('delete_user', array($this, 'clear_cache')); add_action('added_existing_user', array($this, 'clear_cache')); add_action('remove_user_from_blog', array($this, 'clear_cache')); add_action('admin_print_scripts', array($this, '_inline_js_scripts')); add_action('wp_ajax_icl_tm_user_search', array($this, '_user_search')); } function save_settings(){ global $sitepress; $iclsettings['translation-management'] = $this->settings; $sitepress->save_settings($iclsettings); } function init(){ global $wpdb, $current_user, $sitepress_settings, $sitepress, $pagenow; $this->settings =& $sitepress_settings['translation-management']; //logic for syncing comments if($sitepress->get_option('sync_comments_on_duplicates')){ add_action('delete_comment', array($this, 'duplication_delete_comment')); add_action('edit_comment', array($this, 'duplication_edit_comment')); add_action('wp_set_comment_status', array($this, 'duplication_status_comment'), 10, 2); add_action('wp_insert_comment', array($this, 'duplication_insert_comment'), 100); } $this->initial_custom_field_translate_states(); // defaults if(!isset($this->settings['notification']['new-job'])) $this->settings['notification']['new-job'] = ICL_TM_NOTIFICATION_IMMEDIATELY; if(!isset($this->settings['notification']['completed'])) $this->settings['notification']['completed'] = ICL_TM_NOTIFICATION_IMMEDIATELY; if(!isset($this->settings['notification']['resigned'])) $this->settings['notification']['resigned'] = ICL_TM_NOTIFICATION_IMMEDIATELY; if(!isset($this->settings['notification']['dashboard'])) $this->settings['notification']['dashboard'] = true; if(!isset($this->settings['notification']['purge-old'])) $this->settings['notification']['purge-old'] = 7; if(!isset($this->settings['custom_fields_translation'])) $this->settings['custom_fields_translation'] = array(); if(!isset($this->settings['doc_translation_method'])) $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; get_currentuserinfo(); if(isset($current_user->ID)){ $user = new WP_User($current_user->ID); } if(empty($user->data)) return; $ct['translator_id'] = $current_user->ID; $ct['display_name'] = isset($user->data->display_name) ? $user->data->display_name : $user->data->user_login; $ct['user_login'] = $user->data->user_login; $ct['language_pairs'] = get_user_meta($current_user->ID, $wpdb->prefix.'language_pairs', true); if(empty($ct['language_pairs'])) $ct['language_pairs'] = array(); $this->current_translator = (object)$ct; $this->load_config_pre_process(); $this->load_plugins_wpml_config(); $this->load_theme_wpml_config(); $this->load_config_post_process(); if(isset($_POST['icl_tm_action'])){ $this->process_request($_POST['icl_tm_action'], $_POST); }elseif(isset($_GET['icl_tm_action'])){ $this->process_request($_GET['icl_tm_action'], $_GET); } //$this->load_plugins_wpml_config(); //$this->load_theme_wpml_config(); if($GLOBALS['pagenow']=='edit.php'){ // use standard WP admin notices add_action('admin_notices', array($this, 'show_messages')); }else{ // use custom WP admin notices add_action('icl_tm_messages', array($this, 'show_messages')); } if(isset($_GET['page']) && basename($_GET['page']) == 'translations-queue.php' && isset($_GET['job_id'])){ add_filter('admin_head',array($this, '_show_tinyMCE')); } //if(!isset($this->settings['doc_translation_method'])){ if(isset($this->settings['doc_translation_method']) && $this->settings['doc_translation_method'] < 0 ){ if(isset($_GET['sm']) && $_GET['sm']=='mcsetup' && isset($_GET['src']) && $_GET['src']=='notice'){ $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; $this->save_settings(); }else{ add_action('admin_notices', array($this, '_translation_method_notice')); } } if(defined('WPML_TM_VERSION') && isset($_GET['page']) && $_GET['page'] == WPML_TM_FOLDER. '/menu/main.php' && isset($_GET['sm']) && $_GET['sm'] == 'translators'){ $iclsettings =& $sitepress_settings; $sitepress->get_icl_translator_status($iclsettings); $sitepress->save_settings($iclsettings); } // default settings if(empty($this->settings['doc_translation_method']) || !defined('WPML_TM_VERSION')){ $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; } } function initial_custom_field_translate_states() { global $wpdb; $cf_keys_limit = 1000; // jic $custom_keys = $wpdb->get_col( " SELECT meta_key FROM $wpdb->postmeta GROUP BY meta_key ORDER BY meta_key LIMIT $cf_keys_limit" ); $changed = false; foreach($custom_keys as $cfield) { if(empty($this->settings['custom_fields_translation'][$cfield]) || $this->settings['custom_fields_translation'][$cfield] == 0) { // see if a plugin handles this field $override = apply_filters('icl_cf_translate_state', 'nothing', $cfield); switch($override) { case 'nothing': break; case 'ignore': $changed = true; $this->settings['custom_fields_translation'][$cfield] = 3; break; case 'translate': $changed = true; $this->settings['custom_fields_translation'][$cfield] = 2; break; case 'copy': $changed = true; $this->settings['custom_fields_translation'][$cfield] = 1; break; } } } if ($changed) { $this->save_settings(); } } function _translation_method_notice(){ echo '
'; } function _show_tinyMCE() { wp_print_scripts('editor'); //add_filter('the_editor', array($this, 'editor_directionality'), 9999); add_filter('tiny_mce_before_init', array($this, '_mce_set_direction'), 9999); add_filter('mce_buttons', array($this, '_mce_remove_fullscreen'), 9999); if (version_compare($GLOBALS['wp_version'], '3.1.4', '<=') && function_exists('wp_tiny_mce')) try{ @wp_tiny_mce(); } catch(Exception $e) { /*don't do anything with this */ } } function _mce_remove_fullscreen($options){ foreach($options as $k=>$v) if($v == 'fullscreen') unset($options[$k]); return $options; } function _inline_js_scripts(){ // remove fullscreen mode if(defined('WPML_TM_FOLDER') && isset($_GET['page']) && $_GET['page'] == WPML_TM_FOLDER . '/menu/translations-queue.php' && isset($_GET['job_id'])){ ?> get_translation_job((int)$_GET['job_id'], false, true); if (!empty($job)) { $rtl_translation = in_array($job->language_code, array('ar','he','fa')); if ($rtl_translation) { $settings['directionality'] = 'rtl'; } else { $settings['directionality'] = 'ltr'; } } return $settings; } /* function editor_directionality($tag) { $job = $this->get_translation_job((int)$_GET['job_id'], false, true); $rtl_translation = in_array($job->language_code, array('ar','he','fa')); if ($rtl_translation) { $dir = 'dir="rtl"'; } else { $dir = 'dir="ltr"'; } return str_replace('