array( 'font-current-normal' => '#222222', 'font-current-hover' => '#000000', 'background-current-normal' => '#eeeeee', 'background-current-hover' => '#eeeeee', 'font-other-normal' => '#222222', 'font-other-hover' => '#000000', 'background-other-normal' => '#e5e5e5', 'background-other-hover' => '#eeeeee', 'border' => '#cdcdcd', 'background' => '#e5e5e5' ), 'White' => array( 'font-current-normal' => '#444444', 'font-current-hover' => '#000000', 'background-current-normal' => '#ffffff', 'background-current-hover' => '#eeeeee', 'font-other-normal' => '#444444', 'font-other-hover' => '#000000', 'background-other-normal' => '#ffffff', 'background-other-hover' => '#eeeeee', 'border' => '#cdcdcd', 'background' => '#ffffff' ), 'Blue' => array( 'font-current-normal' => '#ffffff', 'font-current-hover' => '#000000', 'background-current-normal' => '#95bedd', 'background-current-hover' => '#95bedd', 'font-other-normal' => '#000000', 'font-other-hover' => '#ffffff', 'background-other-normal' => '#cbddeb', 'background-other-hover' => '#95bedd', 'border' => '#0099cc', 'background' => '#cbddeb' ) ); function __construct(){ $this->widget_css_defaults = $this->color_schemes['White']; $this->footer_css_defaults = $this->color_schemes['White']; add_action('plugins_loaded',array(&$this,'init')); } function init(){ global $sitepress_settings; $this->settings = $sitepress_settings; if (!empty($this->settings['icl_lang_sel_footer'])){ add_action('wp_head', array(&$this, 'language_selector_footer_style'),19); add_action('wp_footer', array(&$this, 'language_selector_footer'),19); } if (is_admin()) { add_action('icl_language_switcher_options',array(&$this,'admin'),1); } else if (!empty($this->settings['icl_post_availability'])) { if(function_exists('icl_register_string')){ icl_register_string('WPML', 'Text for alternative languages for posts', $this->settings['icl_post_availability_text']); } add_filter('the_content', array(&$this, 'post_availability'), 100); } // the language selector widget $this->language_selector_widget_init(); if(is_admin() && isset($_GET['page']) && $_GET['page'] == ICL_PLUGIN_FOLDER . '/menu/languages.php'){ add_action('admin_head', 'icl_lang_sel_nav_css', 1, 1, true); add_action('admin_head', array(&$this, 'custom_language_switcher_style')); } if(!is_admin()){ add_action('wp_head', array(&$this, 'custom_language_switcher_style')); } if(!empty($sitepress_settings['display_ls_in_menu'])){ add_filter('wp_nav_menu_items', array($this, 'wp_nav_menu_items_filter'), 10, 2); } } function language_selector_widget_init(){ wp_register_sidebar_widget('icl_lang_sel_widget', __('Language Selector', 'sitepress'), 'language_selector_widget', array('classname'=>'icl_languages_selector')); wp_register_widget_control('icl_lang_sel_widget_control', __('Language Selector', 'sitepress'), array(&$this, 'set_widget') ); add_action('template_redirect','icl_lang_sel_nav_ob_start', 0); add_action('wp_head','icl_lang_sel_nav_ob_end'); } function set_widget(){ global $sitepress, $sitepress_settings; if (isset($_POST['icl_widget_update'])){ $sitepress_settings['icl_widget_title_show'] = (isset($_POST['icl_widget_title_show'])) ? 1 : 0; $sitepress->save_settings($sitepress_settings); } echo ''; echo '
'; } function post_availability($content){ $out = ''; if(is_singular()){ $languages = icl_get_languages('skip_missing=true'); if(1 < count($languages)){ //$out .= $this->settings['post_available_before'] ? $this->settings['post_available_before'] : ''; foreach($languages as $l){ if(!$l['active']) $langs[] = ''.$l['translated_name'].''; } $out .= join(', ', $langs); //$out .= $this->settings['post_available_after'] ? $this->settings['post_available_after'] : ''; if(!function_exists('icl_t')){ function icl_t($c, $n, $str){return $str; } } $out = '

' . sprintf(icl_t('WPML', 'Text for alternative languages for posts', $this->settings['icl_post_availability_text']), $out) . '

'; } } $out = apply_filters('icl_post_alternative_languages', $out); if ($this->settings['icl_post_availability_position'] == 'above'){ $content = $out . $content; }else{ $content = $content . $out; } return $content; } function language_selector_footer_style(){ $add = false; foreach($this->footer_css_defaults as $key=>$d){ if (isset($this->settings['icl_lang_sel_footer_config'][$key]) && $this->settings['icl_lang_sel_footer_config'][$key] != $d){ $this->settings['icl_lang_sel_footer_config'][$key] . "\n"; $add = true; break; } } if($add){ echo "\n\n"; } } function language_selector_footer() { $languages = icl_get_languages('orderby=id&order=asc&skip_missing=0'); if(!empty($languages)){ echo ' '; } } function admin(){ foreach($this->color_schemes as $key=>$val): ?> widget_css_defaults as $k=>$v): ?>
 
 
  • color_schemes as $key=>$val): ?> footer_css_defaults as $k=>$v): ?> settings['icl_lang_sel_footer'])) echo 'style="display:none;" '; ?>>
  • settings['icl_lang_sel_type']) || $this->settings['icl_lang_sel_type'] == 'dropdown') echo ' style="display:none;"';?>>
    widget_css_defaults = $this->widget_css_defaults; $add = false; foreach($this->widget_css_defaults as $key=>$d){ if(isset($this->settings['icl_lang_sel_config'][$key]) && $this->settings['icl_lang_sel_config'][$key] != $d){ $this->settings['icl_lang_sel_config'][$key] . "\n"; $add = true; break; } } if($add){ $list = ($this->settings['icl_lang_sel_type'] == 'list') ? true : false; echo "\n\n"; } if (isset($this->settings['icl_additional_css']) && !empty($this->settings['icl_additional_css'])) { echo "\r\n"; } } function wp_nav_menu_items_filter($items, $args){ global $sitepress_settings, $sitepress; // menu can be passed as integger or object if(isset($args->menu->term_id)) $args->menu = $args->menu->term_id; $abs_menu_id = icl_object_id($args->menu, 'nav_menu', false, $sitepress->get_default_language()); if($abs_menu_id == $sitepress_settings['menu_for_ls']){ $languages = $sitepress->get_ls_languages(); $items .= ''; } return $items; } } // end class // language switcher functions function language_selector_widget($args){ global $sitepress, $sitepress_settings; extract($args, EXTR_SKIP); echo $before_widget; if ($sitepress_settings['icl_widget_title_show']) { echo $args['before_title']; _e('Languages','sitepress'); echo $args['after_title']; } $sitepress->language_selector(); echo $after_widget; } function icl_lang_sel_nav_ob_start(){ if(is_feed()) return; ob_start('icl_lang_sel_nav_prepend_css'); } function icl_lang_sel_nav_ob_end(){ $ob_handlers = ob_list_handlers(); $active_handler = array_pop( $ob_handlers ); if($active_handler == 'icl_lang_sel_nav_prepend_css'){ ob_end_flush(); } } function icl_lang_sel_nav_prepend_css($buf){ if(defined('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS') && ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS){ return $buf; } return preg_replace('##i','' . PHP_EOL . PHP_EOL . icl_lang_sel_nav_css(false), $buf); } function icl_lang_sel_nav_css($show = true){ if(defined('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS') && ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS){ return ''; } $link_tag = ''; if(!$show && (!isset($_GET['page']) || $_GET['page'] != ICL_PLUGIN_FOLDER . '/menu/languages.php')){ return $link_tag; }else{ echo $link_tag; } } global $icl_language_switcher; $icl_language_switcher = new SitePressLanguageSwitcher;