%n'); /* qTranslate-X Widget */ class qTranslateXWidget extends WP_Widget { function __construct() { $widget_ops = array('classname' => 'qtranxs_widget', 'description' => __('Allows your visitors to choose a Language.', 'qtranslate') ); parent::__construct('qtranslate', __('qTranslate Language Chooser', 'qtranslate'), $widget_ops); } function widget($args, $instance) { extract($args); //qtranxf_dbg_log('widget: $this: ',$this); //qtranxf_dbg_log('widget: $instance: ',$instance); if(!isset($instance['widget-css-off'])){ echo ''.PHP_EOL; } echo $before_widget; if(empty($instance['hide-title'])) { $title = $instance['title']; if(empty($title)) $title=__('Language', 'qtranslate'); if(empty($instance['hide-title-colon'])) $title .= ':'; $title=apply_filters('qtranslate_widget_title',$title,$this); echo $before_title . $title . $after_title; } qtranxf_generateLanguageSelectCode($instance,$this->id); echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; //qtranxf_dbg_log('update: $new_instance: ',$new_instance); //qtranxf_dbg_log('update: $old_instance: ',$old_instance); $instance['title'] = $new_instance['title']; if(isset($new_instance['hide-title'])) $instance['hide-title'] = true; else unset($instance['hide-title']); if(isset($new_instance['hide-title-colon'])) $instance['hide-title-colon'] = true; else unset($instance['hide-title-colon']); $instance['type'] = $new_instance['type']; if(!empty($new_instance['format'])) $instance['format'] = $new_instance['format']; else unset($instance['format']); if(isset($new_instance['widget-css-on'])) unset($instance['widget-css-off']); else $instance['widget-css-off'] = true; if($new_instance['widget-css'] == QTX_WIDGET_CSS) unset($instance['widget-css']); else $instance['widget-css'] = $new_instance['widget-css']; return $instance; } function form($instance) { $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'type' => 'text', 'format' => '', 'widget-css' => QTX_WIDGET_CSS ) ); $title = $instance['title']; $hide_title = isset($instance['hide-title']) && $instance['hide-title'] !== false; $hide_title_colon = isset($instance['hide-title-colon']); $type = $instance['type']; $format = $instance['format']; $widget_css_on = !isset($instance['widget-css-off']); $widget_css = $instance['widget-css']; if(empty($widget_css)) $widget_css=QTX_WIDGET_CSS; ?>


  • %f', '<img ... />', '
  • %s', '
  • %n', '
  • %a', '
  • %c', '') echo __('Accepted format arguments:','qtranslate').''; ?> %n'), __('Text and Image', 'qtranslate')) ?> 



    */ } } /** * Language Select Code for non-Widget users * @args is a hash array of options, which accepts the following keys: * ‘type’ – one of the values: ‘text’, ‘image’, ‘both’, ‘dropdown’ and ‘custom’, which match the choices on widget admin page. * ‘format’ – needs to be provided if ‘type’ is ‘custom’. Read help text to this option on widget admin page. * ‘id’ – id of widget, which is used as a distinctive string to create CSS entities. * @since 3.4.5 type of argument is changed, compatibility with old way is preserved. */ function qtranxf_generateLanguageSelectCode($args = array(), $id='') { global $q_config; if(is_string($args)) $type = $args; elseif(is_bool($args)&&$args) $type='image'; elseif(is_array($args)){ if(!empty($args['type'])) $type = $args['type']; if(empty($id) && !empty($args['id'])) $id = $args['id']; } if(empty($type)) $type='text'; else switch($type){ case 'text': case 'image': case 'both': case 'short': case 'css_only': case 'custom': case 'dropdown': break; default: $type='text'; } if(empty($id)) $id = 'qtranslate'; $id .= '-chooser'; if(is_404()) $url = get_option('home'); else $url = ''; $flag_location=qtranxf_flag_location(); echo PHP_EOL.'
    '.PHP_EOL; if($type=='dropdown') { echo ''.PHP_EOL; } } break; case 'both':{ foreach(qtranxf_getSortedLanguages() as $language) { $alt = $q_config['language_name'][$language].' ('.$language.')'; echo ''; //echo ''; echo ''.$q_config['language_name'][$language].'
  • '.PHP_EOL; } } break; case 'short': {// undocumented, to be removed foreach(qtranxf_getSortedLanguages() as $language) { $alt = $q_config['language_name'][$language].' ('.$language.')'; echo ''; echo ''.$language.''.PHP_EOL; } } break; case 'custom': { $format = isset($args['format']) ? $args['format'] : ''; foreach(qtranxf_getSortedLanguages() as $language) { $alt = $q_config['language_name'][$language].' ('.$language.')'; $s = $flag_location.$q_config['flag'][$language]; $n = $q_config['language_name'][$language]; $content = $format; $content = str_replace('%f', ''.$alt.'', $content); $content = str_replace('%s', $s, $content); $content = str_replace('%n', $n, $content); if(strpos($content,'%a')!==FALSE){ $a = qtranxf_getLanguageName($language);//this is an expensive function, do not call without necessity. $content = str_replace('%a', $a==$n ? '' : $a, $content); } $content = str_replace('%c', $language, $content); $classes = array('language-chooser-item', 'language-chooser-item-'.$language); if($language == $q_config['language']) $classes[] = 'active'; echo '
  • ' . $content . '
  • '.PHP_EOL; } } break; } echo '
    '.PHP_EOL; } function qtranxf_widget_init() { register_widget('qTranslateXWidget'); do_action('qtranslate_widget_init'); }