/htdocs/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php
PHP | 7536 lines | 6118 code | 977 blank | 441 comment | 1579 complexity | 2e8344fa7eabc35e73b9aac072ac0559 MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- class SitePress{
- private $settings;
- private $active_languages = array();
- private $this_lang;
- private $wp_query;
- private $admin_language = null;
- private $user_preferences = array();
- public $queries = array();
- function __construct(){
- global $wpdb, $pagenow;
-
- $this->settings = get_option('icl_sitepress_settings');
-
- if(is_null($pagenow) && is_multisite()){
- include ICL_PLUGIN_PATH . '/inc/hacks/vars-php-multisite.php';
- }
- if(false != $this->settings){
- $this->verify_settings();
- }
- if(isset($_GET['icl_action'])){
- require_once ABSPATH . WPINC . '/pluggable.php';
- if($_GET['icl_action']=='reminder_popup'){
- add_action('init', array($this, 'reminders_popup'));
- }
- elseif($_GET['icl_action']=='dismiss_help'){
- $this->settings['dont_show_help_admin_notice'] = true;
- $this->save_settings();
- }elseif($_GET['icl_action']=='dbdump' ){
- include_once ICL_PLUGIN_PATH . '/inc/functions-troubleshooting.php';
- add_action('init', 'icl_troubleshooting_dumpdb');
- }
- }
- if(isset($_GET['page']) && $_GET['page']== ICL_PLUGIN_FOLDER . '/menu/troubleshooting.php' && isset($_GET['debug_action'])){
- ob_start();
- }
- if(isset($_REQUEST['icl_ajx_action'])){
- add_action('init', array($this, 'ajax_setup'));
- }
- add_action('admin_footer', array($this, 'icl_nonces'));
-
- // Process post requests
- if(!empty($_POST)){
- add_action('init', array($this,'process_forms'));
- }
- add_action('plugins_loaded', array($this,'init'), 1);
- add_action('plugins_loaded', array($this,'initialize_cache'), 0);
- add_action('admin_print_scripts', array($this,'js_scripts_setup'));
- add_action('admin_print_styles', array($this,'css_setup'));
-
- // Administration menus
- add_action('admin_menu', array($this, 'administration_menu'));
- add_action('init', array($this,'plugin_localization'));
-
- if($this->settings['existing_content_language_verified']){
- // Post/page language box
- if($pagenow == 'post.php' || $pagenow == 'post-new.php'){
- add_action('admin_head', array($this,'post_edit_language_options'));
- }
-
- // Post/page save actions
- add_action('save_post', array($this,'save_post_actions'), 10, 2);
- //add_action('update_post_metadata', array($this,'pre_update_post_meta'), 10, 5);
- add_action('updated_post_meta', array($this,'update_post_meta'), 100, 4);
- add_action('added_post_meta', array($this,'update_post_meta'), 100, 4);
- add_action('updated_postmeta', array($this,'update_post_meta'), 100, 4); // ajax
- add_action('added_postmeta', array($this,'update_post_meta'), 100, 4); // ajax
- add_action('delete_postmeta', array($this,'delete_post_meta')); // ajax
-
- //add_filter('get_post_metadata', array($this,'get_post_metadata_filter'), 10, 4);
-
- // filter user taxonomy input
- add_filter('pre_post_tax_input', array($this, 'validate_taxonomy_input'));
-
- // Post/page delete actions
- add_action('delete_post', array($this,'delete_post_actions'));
- add_action('wp_trash_post', array($this,'trash_post_actions'));
- add_action('untrashed_post', array($this,'untrashed_post_actions'));
- add_filter('posts_join', array($this,'posts_join_filter'));
- add_filter('posts_where', array($this,'posts_where_filter'));
- add_filter('comment_feed_join', array($this,'comment_feed_join'));
-
- add_filter('comments_clauses', array($this, 'comments_clauses'), 10, 2);
- // Allow us to filter the Query before vars before the posts query is being built and executed
- add_filter('pre_get_posts', array($this, 'pre_get_posts'));
- // show untranslated posts
- if(!is_admin() && isset($this->settings['show_untranslated_blog_posts']) &&
- $this->settings['show_untranslated_blog_posts'] && $this->get_current_language() != $this->get_default_language()){
- add_filter('the_posts', array($this, 'the_posts'));
- }
- if($pagenow == 'edit.php'){
- add_action('admin_footer', array($this,'language_filter'));
- }
- add_filter('get_pages', array($this, 'exclude_other_language_pages2'));
- add_filter('wp_dropdown_pages', array($this, 'wp_dropdown_pages'));
- // posts and pages links filters
- add_filter('post_link', array($this, 'permalink_filter'),1,2);
- add_filter('post_type_link', array($this, 'permalink_filter'),1,2);
- add_filter('page_link', array($this, 'permalink_filter'),1,2);
- if(version_compare(preg_replace('#-RC[0-9]+(-[0-9]+)?$#', '', $GLOBALS['wp_version']), '3.1', '<')){
- add_filter('category_link', array($this, 'category_permalink_filter'),1,2);
- add_filter('tag_link', array($this, 'tax_permalink_filter'),1,2);
- }
- add_filter('term_link', array($this, 'tax_permalink_filter'),1,2);
- add_filter('get_comment_link', array($this, 'get_comment_link_filter'));
- add_action('create_term', array($this, 'create_term'),1, 2);
- add_action('edit_term', array($this, 'create_term'),1, 2);
- add_action('delete_term', array($this, 'delete_term'),1,3);
-
- add_action('get_term', array($this, 'get_term_filter'),1,2);
-
- add_filter('get_terms_args', array($this, 'get_terms_args_filter'));
-
- // filters terms by language
- if(version_compare($GLOBALS['wp_version'], '3.1', '>=')){
- add_filter('terms_clauses', array($this, 'terms_clauses'));
- }else{
- add_filter('list_terms_exclusions', array($this, 'exclude_other_terms'),1,2);
- }
- // allow adding terms with the same name in different languages
- add_filter("pre_term_name", array($this, 'pre_term_name'), 1, 2);
- // allow adding categories with the same name in different languages
- add_action('admin_init', array($this, 'pre_save_category'));
- // custom hook for adding the language selector to the template
- add_action('icl_language_selector', array($this, 'language_selector'));
- // front end js
- add_action('wp_head', array($this, 'front_end_js'));
- add_action('wp_head', array($this,'rtl_fix'));
- add_action('admin_print_styles', array($this,'rtl_fix'));
- add_action('restrict_manage_posts', array($this, 'restrict_manage_posts'));
- add_filter('get_edit_post_link', array($this, 'get_edit_post_link'), 1, 3);
- add_filter('get_edit_term_link', array($this, 'get_edit_term_link'), 1, 4);
- // short circuit get default category
- add_filter('pre_option_default_category', array($this, 'pre_option_default_category'));
- add_filter('update_option_default_category', array($this, 'update_option_default_category'), 1, 2);
- add_filter('the_category', array($this,'the_category_name_filter'));
- add_filter('get_terms', array($this,'get_terms_filter'));
- add_filter('get_the_terms', array($this, 'get_the_terms_filter'), 10, 3);
-
- add_filter('single_cat_title', array($this,'the_category_name_filter'));
- add_filter('term_links-category', array($this,'the_category_name_filter'));
- add_filter('term_links-post_tag', array($this,'the_category_name_filter'));
- add_filter('tags_to_edit', array($this,'the_category_name_filter'));
- add_filter('single_tag_title', array($this,'the_category_name_filter'));
- // adjacent posts links
- add_filter('get_previous_post_join', array($this,'get_adjacent_post_join'));
- add_filter('get_next_post_join', array($this,'get_adjacent_post_join'));
- add_filter('get_previous_post_where', array($this,'get_adjacent_post_where'));
- add_filter('get_next_post_where', array($this,'get_adjacent_post_where'));
- // feeds links
- add_filter('feed_link', array($this,'feed_link'));
- // commenting links
- add_filter('post_comments_feed_link', array($this,'post_comments_feed_link'));
- add_filter('trackback_url', array($this,'trackback_url'));
- add_filter('user_trailingslashit', array($this,'user_trailingslashit'),1, 2);
- // date based archives
- add_filter('year_link', array($this,'archives_link'));
- add_filter('month_link', array($this,'archives_link'));
- add_filter('day_link', array($this,'archives_link'));
- add_filter('getarchives_join', array($this,'getarchives_join'));
- add_filter('getarchives_where', array($this,'getarchives_where'));
- add_filter('pre_option_home', array($this,'pre_option_home'));
- if (!is_admin()) {
- add_filter('attachment_link', array($this, 'attachment_link_filter'), 10, 2);
- }
-
- // Filter custom type archive link (since WP 3.1)
- add_filter('post_type_archive_link', array($this,'post_type_archive_link_filter'), 10, 2);
-
- add_filter('author_link', array($this,'author_link'));
-
- add_filter('wp_unique_post_slug', array($this, 'wp_unique_post_slug'), 100, 5);
-
- add_filter('home_url', array($this, 'home_url'), 1, 4) ;
- // language negotiation
- add_action('query_vars', array($this,'query_vars'));
- //
- add_filter('language_attributes', array($this, 'language_attributes'));
- add_action('locale', array($this, 'locale'));
- if(isset($_GET['____icl_validate_domain'])){ echo '<!--'.get_option('home').'-->'; exit; }
- add_filter('pre_option_page_on_front', array($this,'pre_option_page_on_front'));
- add_filter('pre_option_page_for_posts', array($this,'pre_option_page_for_posts'));
- add_filter('option_sticky_posts', array($this,'option_sticky_posts'));
- add_filter('request', array($this,'request_filter'));
- add_action('wp_head', array($this,'set_wp_query'));
- add_action('show_user_profile', array($this, 'show_user_options'));
- add_action('personal_options_update', array($this, 'save_user_options'));
- // column with links to translations (or add translation) - low priority
- add_action('init', array($this,'configure_custom_column'), 1010); // accommodate Types init@999
-
- // adjust queried categories and tags ids according to the language
- if($this->settings['auto_adjust_ids']){
- add_action('parse_query', array($this, 'parse_query'));
- add_action('wp_list_pages_excludes', array($this, 'adjust_wp_list_pages_excludes'));
- if(!is_admin()){
- add_filter('get_term', array($this,'get_term_adjust_id'), 1, 1);
- add_filter('category_link', array($this,'category_link_adjust_id'), 1, 2);
- add_filter('get_terms', array($this,'get_terms_adjust_ids'), 1, 3);
- add_filter('get_pages', array($this,'get_pages_adjust_ids'), 1, 2);
- }
- }
- if(!is_admin()){
- add_action('wp_head', array($this, 'meta_generator_tag'));
- }
- require_once ICL_PLUGIN_PATH . '/inc/wp-nav-menus/iclNavMenu.class.php';
- $iclNavMenu = new iclNavMenu;
- if(is_admin() || defined('XMLRPC_REQUEST') || preg_match('#wp-comments-post\.php$#', $_SERVER['REQUEST_URI'])){
- global $iclTranslationManagement, $ICL_Pro_Translation;
- $iclTranslationManagement = new TranslationManagement;
- $ICL_Pro_Translation = new ICL_Pro_Translation();
- }
-
- add_action('wp_login', array($this, 'reset_admin_language_cookie'));
-
- add_action('template_redirect', array($this, 'setup_canonical_urls'), 100);
-
- add_action('init', array($this, '_taxonomy_languages_menu'), 99); //allow hooking in
-
- if($this->settings['seo']['head_langs']){
- add_action('wp_head', array($this, 'head_langs'));
- }
-
- } //end if the initial language is set - existing_content_language_verified
- add_action('wp_dashboard_setup', array($this, 'dashboard_widget_setup'));
- if(is_admin() && $pagenow == 'index.php'){
- add_action('icl_dashboard_widget_notices', array($this, 'print_translatable_custom_content_status'));
- }
-
- add_filter('core_version_check_locale', array($this, 'wp_upgrade_locale'));
-
- if($pagenow == 'post.php' && isset($_REQUEST['action']) && $_REQUEST['action']=='edit' && isset($_GET['post'])){
- add_action('init', '_icl_trash_restore_prompt');
- }
-
- add_action('init', array($this, 'js_load'), 2); // enqueue scripts - higher priority
-
- }
- function init(){
- global $wpdb;
-
- $this->get_user_preferences();
-
- // // default value for theme_localization_type OR
- // reset theme_localization_type if string translation was on (theme_localization_type was set to 2) and then it was deactivated
- /*
- if(
- !isset($this->settings['theme_localization_type']) ||
- isset($this->settings['theme_localization_type']) && $this->settings['theme_localization_type'] == 1 && !defined('WPML_ST_VERSION')
- ){
- if(!defined('WPML_DOING_UPGRADE')){
- $this->settings['theme_localization_type'] = 2;
- }
-
- }
- */
-
- $this->set_admin_language();
- //configure callbacks for plugin menu pages
- if(defined('WP_ADMIN') && isset($_GET['page']) && 0 === strpos($_GET['page'],basename(ICL_PLUGIN_PATH).'/')){
- add_action('icl_menu_footer', array($this, 'menu_footer'));
- }
- if($this->settings['existing_content_language_verified']){
- if(defined('WP_ADMIN')){
- if(isset($_GET['lang'])){
- $this->this_lang = rtrim(strip_tags($_GET['lang']),'/');
- $al = $this->get_active_languages();
- $al['all'] = true;
- if(empty($al[$this->this_lang])){
- $this->this_lang = $this->get_default_language();
- }
- // force default language for string translation
- // we also make sure it's not saved in the cookie
- }elseif(isset($_GET['page']) &&
- ((defined('WPML_ST_FOLDER') && $_GET['page'] == WPML_ST_FOLDER . '/menu/string-translation.php') ||
- (defined('WPML_TM_FOLDER') && $_GET['page'] == WPML_TM_FOLDER . '/menu/translations-queue.php'))
- ){
- $this->this_lang = $this->get_default_language();
- }elseif(defined('DOING_AJAX')) {
- $al = $this->get_active_languages();
- if(isset($_POST['lang']) && isset($al[$_POST['lang']])){
- $this->this_lang = $_POST['lang'];
- }else{
- $this->this_lang = $this->get_language_cookie();
- }
- }elseif($lang = $this->get_admin_language_cookie()){
- $this->this_lang = $lang;
- }else{
- $this->this_lang = $this->get_default_language();
- }
- if((isset($_GET['admin_bar']) && $_GET['admin_bar']==1) && (!isset($_GET['page']) || !defined('WPML_ST_FOLDER') || $_GET['page'] != WPML_ST_FOLDER . '/menu/string-translation.php')){
- $this->set_admin_language_cookie();
- }
- }else{
- $al = $this->get_active_languages();
- foreach($al as $l){
- $active_languages[] = $l['code'];
- }
- $active_languages[] = 'all';
- $s = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on'?'s':'';
- $request = 'http' . $s . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
- $home = get_option('home');
- if($s){
- $home = preg_replace('#^http://#', 'https://', $home);
- }
- $url_parts = parse_url($home);
- $blog_path = !empty($url_parts['path'])?$url_parts['path']:'';
- switch($this->settings['language_negotiation_type']){
- case 1:
- $path = str_replace($home,'',$request);
- $parts = explode('?', $path);
- $path = $parts[0];
- $exp = explode('/',trim($path,'/'));
- if(in_array($exp[0], $active_languages)){
- $this->this_lang = $exp[0];
- // before hijiking the SERVER[REQUEST_URI]
- // override the canonical_redirect action
- // keep a copy of the original request uri
- remove_action('template_redirect', 'redirect_canonical');
- global $_icl_server_request_uri;
- $_icl_server_request_uri = $_SERVER['REQUEST_URI'];
- add_action('template_redirect', 'icl_redirect_canonical_wrapper', 11);
- function icl_redirect_canonical_wrapper(){
- global $_icl_server_request_uri, $wp_query;
- $requested_url = ( !empty($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
- $requested_url .= $_SERVER['HTTP_HOST'];
- $requested_url .= $_icl_server_request_uri;
- redirect_canonical($requested_url);
- /*
- if($wp_query->query_vars['error'] == '404'){
- $wp_query->is_404 = true;
- $template = get_404_template();
- include($template);
- exit;
- }
- */
- }
- //
- //deal with situations when template files need to be called directly
- add_action('template_redirect', array($this, '_allow_calling_template_file_directly'));
- //$_SERVER['REQUEST_URI'] = preg_replace('@^'. $blog_path . '/' . $this->this_lang.'@i', $blog_path ,$_SERVER['REQUEST_URI']);
- // Check for special case of www.example.com/fr where the / is missing on the end
- $parts = parse_url($_SERVER['REQUEST_URI']);
- if(strlen($parts['path']) == 0){
- $_SERVER['REQUEST_URI'] = '/' . $_SERVER['REQUEST_URI'];
- }
- }else{
- $this->this_lang = $this->get_default_language();
- }
- break;
- case 2:
- $exp = explode('.', $_SERVER['HTTP_HOST']);
- $__l = array_search('http' . $s . '://' . $_SERVER['HTTP_HOST'] . $blog_path, $this->settings['language_domains']);
- $this->this_lang = $__l?$__l:$this->get_default_language();
- if(defined('ICL_USE_MULTIPLE_DOMAIN_LOGIN') && ICL_USE_MULTIPLE_DOMAIN_LOGIN){
- include ICL_PLUGIN_PATH . '/modules/multiple-domains-login.php';
- }
- add_filter('allowed_redirect_hosts', array($this, 'allowed_redirect_hosts'));
- break;
- case 3:
- default:
- if(isset($_GET['lang'])){
- $this->this_lang = preg_replace("/[^0-9a-zA-Z-]/i", '',strip_tags($_GET['lang']));
- // set the language based on the content id - for short links
- }elseif(isset($_GET['page_id'])){
- $this->this_lang = $wpdb->get_var($wpdb->prepare("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type='post_page' AND element_id=%d", $_GET['page_id']));
- }elseif(isset($_GET['p'])){
- $post_type = $wpdb->get_var($wpdb->prepare("SELECT post_type FROM {$wpdb->posts} WHERE ID=%d", $_GET['p']));
- $this->this_lang = $wpdb->get_var($wpdb->prepare("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type=%s AND element_id=%d",
- 'post_' . $post_type, $_GET['p']));
- }elseif(isset($_GET['cat_ID'])){
- $cat_tax_id = $wpdb->get_var($wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s",
- $_GET['cat_ID'], 'category'));
- $this->this_lang = $wpdb->get_var($wpdb->prepare("SELECT language_code FROM {$wpdb->prefix}icl_translations
- WHERE element_type='tax_category' AND element_id=%d", $cat_tax_id));
- }elseif(isset($_GET['tag'])){
- $tag_tax_id = $wpdb->get_var($wpdb->prepare("
- SELECT x.term_taxonomy_id FROM {$wpdb->term_taxonomy} x JOIN {$wpdb->terms} t ON t.term_id = x.term_id
- WHERE t.slug=%s AND x.taxonomy='post_tag'",
- $_GET['tag']));
- $this->this_lang = $wpdb->get_var($wpdb->prepare("SELECT language_code FROM {$wpdb->prefix}icl_translations
- WHERE element_type='tax_post_tag' AND element_id=%d", $tag_tax_id));
- }
- //
- if(!isset($_GET['lang']) && ($this->this_lang && $this->this_lang != $this->get_default_language())){
- if(!isset($GLOBALS['wp_rewrite'])){
- require_once ABSPATH . WPINC . '/rewrite.php';
- $GLOBALS['wp_rewrite'] = new WP_Rewrite();
- }
- define('ICL_DOING_REDIRECT', true);
- if(isset($_GET['page_id'])){
- wp_redirect(get_page_link($_GET['page_id']), '301');
- exit;
- }elseif(isset($_GET['p'])){
- wp_redirect(get_permalink($_GET['p']), '301');
- exit;
- }elseif(isset($_GET['cat_ID'])){
- wp_redirect(get_term_link( intval($_GET['cat_ID']), 'category' ));
- exit;
- }elseif(isset($_GET['tag'])){
- wp_redirect(get_term_link( $_GET['tag'], 'post_tag' ));
- exit;
- }else{
- global $wp_taxonomies;
- if(isset($this->settings['taxonomies_sync_option'])){
- $taxs = array_keys((array)$this->settings['taxonomies_sync_option']);
- foreach($taxs as $t){
- if(isset($_GET[$t])){
- $term_obj = $wpdb->get_row($wpdb->prepare(
- "SELECT * FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON t.term_id = x.term_id
- WHERE t.slug=%s AND x.taxonomy=%s"
- , $_GET[$t], $t));
- $term_link = get_term_link( $term_obj, $t );
- $term_link = str_replace('&', '&', $term_link); // fix
- if($term_link && !is_wp_error($term_link)){
- wp_redirect($term_link);
- exit;
- }
- }
- }
- }
- }
- }
- if(empty($this->this_lang)){
- $this->this_lang = $this->get_default_language();
- }
- }
- // allow forcing the current language when it can't be decoded from the URL
- $this->this_lang = apply_filters('icl_set_current_language', $this->this_lang);
- }
-
- //reorder active language to put 'this_lang' in front
- foreach($this->active_languages as $k=>$al){
- if($al['code']==$this->this_lang){
- unset($this->active_languages[$k]);
- $this->active_languages = array_merge(array($k=>$al), $this->active_languages);
- }
- }
- //if($this->settings['language_negotiation_type']==3){
- // fix pagenum links for when using the language as a parameter
- // add_filter('get_pagenum_link', array($this,'get_pagenum_link_filter'));
- //}
- // filter some queries
- add_filter('query', array($this, 'filter_queries'));
- if( $this->settings['language_negotiation_type']==1 && $this->get_current_language()!=$this->get_default_language()){
- add_filter('option_rewrite_rules', array($this, 'rewrite_rules_filter'));
- }
-
- $this->set_language_cookie();
-
- if(is_admin() &&
- (!isset($_GET['page']) || !defined('WPML_ST_FOLDER') || $_GET['page'] != WPML_ST_FOLDER . '/menu/string-translation.php') &&
- (!isset($_GET['page']) || !defined('WPML_TM_FOLDER') || $_GET['page'] != WPML_TM_FOLDER . '/menu/translations-queue.php')
- ){
- if(!$this->is_rtl() && version_compare($GLOBALS['wp_version'], '3.3', '>')){
- add_action('admin_notices', 'wpml_set_admin_language_switcher_place', 100);
- function wpml_set_admin_language_switcher_place(){
- echo '<br clear="all" />';
- }
- }
- add_action('in_admin_header', array($this, 'admin_language_switcher'));
- }
-
- if(!is_admin() && defined('DISQUS_VERSION')) include ICL_PLUGIN_PATH . '/modules/disqus.php';
-
- }
- if($this->is_rtl()){
- $GLOBALS['text_direction'] = 'rtl';
- }
-
- // Automatic redirect
- if(!is_admin() && !empty($this->settings['automatic_redirect'])){
- add_action('template_redirect', array($this, 'automatic_redirect'));
- }
- if(is_admin() && empty($this->settings['dont_show_help_admin_notice'])){
- if(count($this->get_active_languages()) < 2){
- add_action('admin_notices', array($this, 'help_admin_notice'));
- }
- }
- $short_v = implode('.', array_slice(explode('.', ICL_SITEPRESS_VERSION), 0, 3));
- if(is_admin() && (!isset($this->settings['hide_upgrade_notice']) || $this->settings['hide_upgrade_notice'] != $short_v)){
- add_action('admin_notices', array($this, 'upgrade_notice'));
- }
- if(is_admin() && current_user_can('manage_options')){
- if($this->icl_account_configured()) {
- add_action('admin_notices', array($this, 'icl_reminders'));
- }
- }
- require ICL_PLUGIN_PATH . '/inc/template-constants.php';
- if(defined('WPML_LOAD_API_SUPPORT')){
- require ICL_PLUGIN_PATH . '/inc/wpml-api.php';
- }
- add_action('wp_footer', array($this, 'display_wpml_footer'),20);
- if(defined('XMLRPC_REQUEST') && XMLRPC_REQUEST){
- add_action('xmlrpc_call', array($this, 'xmlrpc_call_actions'));
- add_filter('xmlrpc_methods',array($this, 'xmlrpc_methods'));
- }
- if(defined('WPML_TM_VERSION') && is_admin()){
- require ICL_PLUGIN_PATH . '/inc/quote.php';
- }
-
- }
-
- function setup(){
- return !empty($this->settings['setup_complete']);
- }
-
- function automatic_redirect(){
-
- $save_cookie = false;
-
- if(empty($_COOKIE['_icl_visitor_lang'])){
- //No cookie found
- $lang = $this->get_current_language();
- $langs = @explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
- foreach($langs as $lang){
- $lang = preg_replace('#q=(.+)$#', '', $lang);
- $lang = str_replace('-', '_', $lang); // normalize
- if(!in_array($lang, array_keys($this->get_active_languages()))){
- $lang = substr($lang, 0, strpos($lang, '_'));
- }
- if(in_array($lang, array_keys($this->get_active_languages()))){
- //'Got lang from browser: %s', $lang
- $save_cookie = true;
- break;
- }
- }
- }else{
- //'Cookie found: %s', $_COOKIE['_icl_visitor_lang']
- if($_COOKIE['_icl_visitor_lang'] != $this->get_current_language()){
- //'User changed language: %s', $this->get_current_language())
- $lang = $this->get_current_language();
- $save_cookie = true;
- }else{
- //'Using cookie lang: %s', $_COOKIE['_icl_visitor_lang']
- $lang = $_COOKIE['_icl_visitor_lang'];
- }
- }
- if($save_cookie){
- $cookie_domain = defined('COOKIE_DOMAIN') ? COOKIE_DOMAIN : $_SERVER['HTTP_HOST'];
- $cookie_path = defined('COOKIEPATH') ? COOKIEPATH : '/';
- $s = setcookie('_icl_visitor_lang', $lang, time()+3600 * intval($this->settings['remember_language']), $cookie_path, $cookie_domain);
- //'Saving cookie: %s', $lang
- }
- if($lang != $this->get_current_language()){
- //'Doing redirect from %s to %s', $this->get_current_language(), $lang
- if($this->settings['automatic_redirect'] == 1){
- $args['skip_missing'] = 1;
- }else{
- $args['skip_missing'] = 0;
- }
- $languages = $this->get_ls_languages($args);
- if(isset($languages[$lang])){
- header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
- header("Expires: Sat, 16 Aug 1980 05:00:00 GMT"); // Date in the past
-
- if(false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Safari')){
- $http_code = 307;
- }else{
- $http_code = 300;
- }
-
- wp_redirect($languages[$lang]['url'], $http_code);
- exit;
- }
- }
- //'No redirect needed.'
- }
- function ajax_setup(){
- require ICL_PLUGIN_PATH . '/ajax.php';
- }
- function configure_custom_column(){
- global $pagenow, $wp_post_types;
- $pagenow_ = '';
- $is_ajax = false;
- if($pagenow == 'admin-ajax.php'){
- if(
- isset($_POST['action']) && $_POST['action']=='inline-save' ||
- isset($_GET['action']) && $_GET['action'] == 'fetch-list'
- ){
- $is_ajax = true;
- }
- }
- if(($pagenow == 'edit.php' || $pagenow_ == 'edit-pages.php' || $is_ajax)){
- $post_type = isset($_REQUEST['post_type']) ? $_REQUEST['post_type'] : 'post';
- switch($post_type){
- case 'post': case 'page':
- add_filter('manage_'.$post_type.'s_columns',array($this,'add_posts_management_column'));
- if(isset($_GET['post_type']) && $_GET['post_type']=='page'){
- add_action('manage_'.$post_type.'s_custom_column',array($this,'add_content_for_posts_management_column'));
- }
- add_action('manage_posts_custom_column',array($this,'add_content_for_posts_management_column'));
- break;
- default:
- if(in_array($post_type, array_keys($this->get_translatable_documents()))){
- add_filter('manage_'.$post_type.'_posts_columns',array($this,'add_posts_management_column'));
- if($wp_post_types[$post_type]->hierarchical){
- add_action('manage_pages_custom_column',array($this,'add_content_for_posts_management_column'));
- add_action('manage_posts_custom_column',array($this,'add_content_for_posts_management_column')); // add this too - for more types plugin
- }else{
- add_action('manage_posts_custom_column',array($this,'add_content_for_posts_management_column'));
- }
- }
- }
- add_action('admin_print_scripts', array($this, '__set_posts_management_column_width'));
- }
- }
- function _taxonomy_languages_menu(){
- // tags language selection
- global $pagenow, $wpdb;
- if($pagenow == 'edit-tags.php'){
- // handle case of the tax edit page (after a taxonomy has been added)
- // needs to redirect back to
- if(isset($_GET['trid']) && isset($_GET['source_lang'])){
- $translations = $this->get_element_translations($_GET['trid'], 'tax_' . $_GET['taxonomy']);
- if(isset($translations[$_GET['lang']])){
- wp_redirect(get_edit_term_link($translations[$_GET['lang']]->term_id, $_GET['taxonomy']));
- exit;
- }else{
- add_action( 'admin_notices', array($this, '_tax_adding') );
- }
- }
-
- $taxonomy = isset($_GET['taxonomy']) ? $wpdb->escape($_GET['taxonomy']) : 'post_tag';
- if($this->is_translated_taxonomy($taxonomy)){
- add_action('admin_print_scripts-edit-tags.php', array($this,'js_scripts_tags'));
- if($taxonomy == 'category'){
- add_action('edit_category_form', array($this, 'edit_term_form'));
- }else{
- add_action('add_tag_form', array($this, 'edit_term_form'));
- add_action('edit_tag_form', array($this, 'edit_term_form'));
- }
- add_action('admin_footer', array($this,'terms_language_filter'));
- add_filter('wp_dropdown_cats', array($this, 'wp_dropdown_cats_select_parent'));
- }
- }
- }
-
- function _tax_adding(){
- $translations = $this->get_element_translations($_GET['trid'], 'tax_' . $_GET['taxonomy']);
- if(!empty($translations) && isset($translations[$_GET['source_lang']]->name)){
- $tax_name = apply_filters('the_category', $translations[$_GET['source_lang']]->name);
- echo '<div id="icl_tax_adding_notice" class="updated fade"><p>'. sprintf(__('Adding translation for: %s.', 'sitepress'), $tax_name). '</p></div>';
- }
- }
-
- function the_posts($posts){
- global $wpdb, $wp_query;
- $db = debug_backtrace();
- $custom_wp_query = isset($db[3]['object']) ? $db[3]['object'] : false;
- //exceptions
- if(
- ($this->get_current_language() == $this->get_default_language()) // original language
- || ($wp_query != $custom_wp_query) // called by a custom query
- || (!$custom_wp_query->is_posts_page && !$custom_wp_query->is_home) // not the blog posts page
- || $wp_query->is_singular //is singular
- || !empty($custom_wp_query->query_vars['category__not_in'])
- //|| !empty($custom_wp_query->query_vars['category__in'])
- //|| !empty($custom_wp_query->query_vars['category__and'])
- || !empty($custom_wp_query->query_vars['tag__not_in'])
- || !empty($custom_wp_query->query_vars['post__in'])
- || !empty($custom_wp_query->query_vars['post__not_in'])
- || !empty($custom_wp_query->query_vars['post_parent'])
- ){
- //$wp_query->query_vars = $this->wp_query->query_vars;
- return $posts;
- }
- // get the posts in the default language instead
- $this_lang = $this->this_lang;
- $this->this_lang = $this->get_default_language();
- remove_filter('the_posts', array($this, 'the_posts'));
- $custom_wp_query->query_vars['suppress_filters'] = 0;
- if(isset($custom_wp_query->query_vars['pagename']) && !empty($custom_wp_query->query_vars['pagename'])){
- if (isset($custom_wp_query->queried_object_id) && !empty($custom_wp_query->queried_object_id)) {
- $page_id = $custom_wp_query->queried_object_id;
- } else {
- // urlencode added for languages that have urlencoded post_name field value
- $custom_wp_query->query_vars['pagename'] = urlencode($custom_wp_query->query_vars['pagename']);
- $page_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_name='{$custom_wp_query->query_vars['pagename']}' AND post_type='page'");
- }
- if($page_id){
- $tr_page_id = icl_object_id($page_id, 'page', false, $this->get_default_language());
- if($tr_page_id){
- $custom_wp_query->query_vars['pagename'] = $wpdb->get_var("SELECT post_name FROM {$wpdb->posts} WHERE ID={$tr_page_id}");
- }
- }
- }
- // look for posts without translations
- if($posts){
- foreach($posts as $p){
- $pids[] = $p->ID;
- }
- $trids = $wpdb->get_col("
- SELECT trid
- FROM {$wpdb->prefix}icl_translations
- WHERE element_type='post_post' AND element_id IN (".join(',', $pids).") AND language_code = '".$this_lang."'");
- if(!empty($trids)){
- $posts_not_translated = $wpdb->get_col("
- SELECT element_id, COUNT(language_code) AS c
- FROM {$wpdb->prefix}icl_translations
- WHERE trid IN (".join(',', $trids).") GROUP BY trid HAVING c = 1
- ");
- if(!empty($posts_not_translated)){
- $GLOBALS['__icl_the_posts_posts_not_translated'] = $posts_not_translated;
- add_filter('posts_where', array($this, '_posts_untranslated_extra_posts_where'), 99);
- }
- }
- }
- //fix page for posts
- unset($custom_wp_query->query_vars['page_id']); unset($custom_wp_query->query_vars['p']);
- $my_query = new WP_Query($custom_wp_query->query_vars);
-
- add_filter('the_posts', array($this, 'the_posts'));
- $this->this_lang = $this_lang;
- // create a map of the translated posts
- foreach($posts as $post){
- $trans_posts[$post->ID] = $post;
- }
- // loop original posts
- foreach($my_query->posts as $k=>$post){ // loop posts in the default language
- $trid = $this->get_element_trid($post->ID);
- $translations = $this->get_element_translations($trid); // get translations
- if(isset($translations[$this->get_current_language()])){ // if there is a translation in the current language
- if(isset($trans_posts[$translations[$this->get_current_language()]->element_id])){ //check the map of translated posts
- $my_query->posts[$k] = $trans_posts[$translations[$this->get_current_language()]->element_id];
- }else{ // check if the translated post exists in the database still
- $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d AND post_status='publish' LIMIT 1", $translations[$this->get_current_language()]->element_id));
- if(!empty($_post)){
- $_post = sanitize_post($_post);
- $my_query->posts[$k] = $_post;
- }else{
- $my_query->posts[$k]->original_language = true;
- }
- }
- }else{
- $my_query->posts[$k]->original_language = true;
- }
- }
- if($custom_wp_query == $wp_query){
- $wp_query->max_num_pages = $my_query->max_num_pages;
- }
- $posts = $my_query->posts;
- unset($GLOBALS['__icl_the_posts_posts_not_translated']);
- remove_filter('posts_where', array($this, '_posts_untranslated_extra_posts_where'), 99);
- return $posts;
- }
- function _posts_untranslated_extra_posts_where($where){
- global $wpdb;
- $where .= ' OR ' . $wpdb->posts . '.ID IN (' . join(',', $GLOBALS['__icl_the_posts_posts_not_translated']) . ')';
- return $where;
- }
- function initialize_cache(){
- require_once ICL_PLUGIN_PATH . '/inc/cache.php';
- $this->icl_translations_cache = new icl_cache();
- $this->icl_locale_cache = new icl_cache('locale', true);
- $this->icl_flag_cache = new icl_cache('flags', true);
- $this->icl_language_name_cache = new icl_cache('language_name', true);
- $this->icl_term_taxonomy_cache = new icl_cache();
- }
- function set_admin_language(){
- global $wpdb, $current_user;
- if(is_null($current_user) && function_exists('wp_get_current_user')){
- $u = wp_get_current_user();
- if(isset($u->ID) && $u->ID > 0){
- $current_user = $u;
- }else{
- return $this->get_default_language();
- }
- }
- $active_languages = array_keys($wpdb->get_col("SELECT code FROM {$wpdb->prefix}icl_languages WHERE active=1")); //don't use method get_active_language()
- if(!empty($current_user->data->ID)){
- $this->admin_language = $this->get_user_admin_language($current_user->data->ID);
- }
- if($this->admin_language != '' && !in_array($this->admin_language, $active_languages)){
- delete_user_meta($current_user->data->ID,'icl_admin_language');
- }
- if(empty($this->settings['admin_default_language']) || !in_array($this->settings['admin_default_language'], $active_languages)){
- $this->settings['admin_default_language'] = '_default_';
- $this->save_settings();
- }
- if(!$this->admin_language){
- $this->admin_language = $this->settings['admin_default_language'];
- }
- if($this->admin_language == '_default_' && $this->get_default_language()){
- $this->admin_language = $this->get_default_language();
- }
-
- }
- function get_admin_language(){
- return $this->admin_language;
- }
- function get_user_admin_language($user_id) {
- static $lang = array();
- if (!isset($lang[$user_id])) {
- $lang[$user_id] = get_user_meta($user_id,'icl_admin_language',true);
- if(empty($lang[$user_id])){
- if(isset($this->settings['admin_default_language'])){
- $lang[$user_id] = $this->settings['admin_default_language'];
- }
- if(empty($lang[$user_id]) || '_default_' == $lang[$user_id]){
- $lang[$user_id] = $this->get_admin_language();
- }
- }
- }
- return $lang[$user_id];
- }
- function administration_menu(){
- if (1 < count($this->get_active_languages())) {
- $main_page = apply_filters('icl_menu_main_page', basename(ICL_PLUGIN_PATH).'/menu/languages.php');
- add_menu_page(__('WPML','sitepress'), __('WPML','sitepress'), 'manage_options',
- $main_page, null, ICL_PLUGIN_URL . '/res/img/icon16.png');
- do_action('icl_wpml_top_menu_added');
- add_submenu_page($main_page,
- __('Languages','sitepress'), __('Languages','sitepress'),
- 'manage_options', basename(ICL_PLUGIN_PATH).'/menu/languages.php');
- add_submenu_page($main_page,
- __('Theme and plugins localization','sitepress'), __('Theme and plugins localization','sitepress'),
- 'manage_options', basename(ICL_PLUGIN_PATH).'/menu/theme-localization.php');
- if(!defined('WPML_TM_VERSION')){
- add_submenu_page($main_page,
- __('Translation options','sitepress'), __('Translation options','sitepress'),
- 'manage_options', basename(ICL_PLUGIN_PATH).'/menu/translation-options.php');
- }
- /*
- add_submenu_page($main_page,
- __('Comments translation','sitepress'), __('Comments translation','sitepress'),
- 'manage_options', basename(ICL_PLUGIN_PATH).'/menu/comments-translation.php');
- */
- } else {
- $main_page = basename(ICL_PLUGIN_PATH).'/menu/languages.php';
- add_menu_page(__('WPML','sitepress'), __('WPML','sitepress'), 'manage_options',
- $main_page,null, ICL_PLUGIN_URL . '/res/img/icon16.png');
- add_submenu_page($main_page,
- __('Languages','sitepress'), __('Languages','sitepress'),
- 'manage_options', basename(ICL_PLUGIN_PATH).'/menu/languages.php');
- }
- if(isset($_GET['page']) && $_GET['page'] == basename(ICL_PLUGIN_PATH).'/menu/troubleshooting.php'){
- add_submenu_page($main_page,
- __('Troubleshooting','sitepress'), __('Troubleshooting','sitepress'),
- 'manage_options', basename(ICL_PLUGIN_PATH).'/menu/troubleshooting.php');
- }
- //$alert = ' <img width="12" height="12" style="margin-bottom:-2px;" src="'.ICL_PLUGIN_URL.'/res/img/alert.png" />';
- add_submenu_page($main_page,
- __('Support','sitepress'), __('Support','sitepress'), 'manage_options', ICL_PLUGIN_FOLDER . '/menu/support.php');
- }
-
- function save_settings($settings=null){
- if(!is_null($settings)){
- foreach($settings as $k=>$v){
- if(is_array($v)){
- foreach($v as $k2=>$v2){
- $this->settings[$k][$k2] = $v2;
- }
- }else{
- $this->settings[$k] = $v;
- }
- }
- }
- if(!empty($this->settings)){
- update_option('icl_sitepress_settings', $this->settings);
- }
- do_action('icl_save_settings', $settings);
- }
- function get_settings(){
- return $this->settings;
- }
- function get_option($option_name){
- return isset($this->settings[$option_name]) ? $this->settings[$option_name] : null;
- }
-
- function verify_settings(){
- $default_settings = array(
- 'interview_translators' => 1,
- 'existing_content_language_verified' => 0,
- 'language_negotiation_type' => 3,
- 'theme_localization_type' => 1,
- 'icl_lso_header' => 0,
- 'icl_lso_link_empty' => 0,
- 'icl_lso_flags' => 0,
- 'icl_lso_native_lang' => 1,
- 'icl_lso_display_lang' => 1,
- 'sync_page_ordering' => 1,
- 'sync_page_parent' => 1,
- 'sync_page_template' => 1,
- 'sync_ping_status' => 1,
- 'sync_comment_status' => 1,
- 'sync_sticky_flag' => 1,
- 'sync_private_flag' => 1,
- 'sync_post_format' => 1,
- 'sync_delete' => 0,
- 'sync_post_taxonomies' => 1,
- 'sync_post_date' => 0,
- 'sync_taxonomy_parents' => 0,
- 'translation_pickup_method' => 0,
- 'notify_complete' => 1,
- 'translated_document_status' => 1,
- 'remote_management' => 0,
- 'auto_adjust_ids' => 1,
- 'alert_delay' => 0,
- 'promote_wpml' => 0,
- 'troubleshooting_options' => array('http_communication' => 1),
- 'automat…
Large files files are truncated, but you can click here to view the full file