web/wp-content/plugins/xili-language/xili-language.php
changeset 194 32102edaa81b
parent 180 d8780eeb2607
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /*
     2 /*
     3 Plugin Name: xili-language
     3 Plugin Name: xili-language
     4 Plugin URI: http://dev.xiligroup.com/xili-language/
     4 Plugin URI: http://dev.xiligroup.com/xili-language/
     5 Description: This plugin modify on the fly the translation of the theme depending the language of the post or other blog elements - a way to create a real multilanguage site (cms or blog). It introduce a new taxonomy - here language - to describe posts and pages. To complete with tags, use also xili-tidy-tags plugin. 
     5 Description: This plugin modify on the fly the translation of the theme depending the language of the post or other blog elements - a way to create a real multilanguage site (cms or blog). Numerous template tags and three widgets are included. It introduce a new taxonomy - here language - to describe posts and pages. To complete with tags, use also xili-tidy-tags plugin. To include and set translation of .mo files use xili-dictionary plugin. Includes add-on for multilingual bbPress forums.
     6 Author: dev.xiligroup.com - MS
     6 Author: dev.xiligroup.com - MS
     7 Version: 1.4.1
       
     8 Author URI: http://dev.xiligroup.com
     7 Author URI: http://dev.xiligroup.com
       
     8 Version: 2.8.1
       
     9 License: GPLv2
       
    10 Text Domain: xili-language
       
    11 Domain Path: /languages/
     9 */
    12 */
    10 # updated 100220 - 1.4.1 - wp_title translation for categories, () suppressed in cats list display, auto-search linked posts option
    13 
    11 # updated 100216 - 1.3.2 - Option to modify home query according rules by chief editor. fixes gold functions. New Recent Posts Widget.
    14 # updated 120921 - 2.8.1 - fixes sticky perma - improvements for bbPress - new filters in admin - fixes feed links meta
    12 # updated 100216 - 1.3.1 - Just to correct a minor omission - Add New link works now for linked pages.
    15 # updated 120903 - 2.8.0 - fixes, new: admin side language selection - b : langstate
    13 # updated 100215 - 1.3.0 - new functions to change and restore loop's language query-tag. Better post UI to create linked post - fixes lost lang's link when trash or untrash.
    16 # updated 120819 - 120723 - 2.7.1 - fixes lang_perma detect for permalinks add-ons - new start via action
    14 # updated 100207 - 1.2.1 - fixes some directories issues in (rare) xamp servers - Some improvements in post edit UI.
    17 # updated 120721 - 2.7.0 - multilingual features in media library - centralize alert messages and ready for link to wiki
    15 # updated 100109 - 1.2.0 - tested with WP 2.9.1 - more localization for admin UI (RU)
    18 # updated 120708 - 2.6.3 - fixes notice when page-on-front - new icons - test propagate cats
    16 # updated 091104 - 1.1.9.1 - fixes special functions
    19 # updated 120701 - 2.6.2 - add news pointer in class admin, tabs in help
    17 # updated 091103 - 1.1.9 - optional improve hooking ways to be compatible with l10n cache of Johan see line 2200 - fix title of wp_get_archive links with current permalinks.
    20 # updated 120615 - 2.6.1 - fixes notice xlrp
    18 # updated 091019 - 1.1.8 - gold functions and shortcode for linked posts - first tests with WP 2.9
    21 # updated 120528 - 2.6.0 - class admin in separate file, able to detect and use local files (local-xx_XX.mo) containing translations
    19 # updated 091007 - 1.1.es - tests - gold functions active - update undefined posts functions in library
    22 # updated 120420 - 2.5.1 - add style for post edit (flag in imput)
    20 # updated 090918 - 1.1 - xiliml_the_other_posts function improved and upgraded for CMS webmasters
    23 # updated 120415 - 2.5.0 - new dashboard metabox for translations list of linked posts and actions (as in XD2), language postmetas now hidden, hreflang link added in head, WP3.4 pre-tests: fixes metaboxes columns
    21 # updated 090719 - 1.0.2 - fix unexpected like tags metabox added by WP 28 tracs #10437
    24 
    22 # updated 090626 - 1.0.1 - fix filter unique id for category link hooks
    25 # updated 120329 - 2.4.4 - fixes posts list language column in 3.2.1
    23 # updated 090615 - 1.0 - Via admin UI, new ways to choose default language of front-page (page, home,...)
    26 # updated 120225 - 2.4.3 - fixes before releasing
    24 # updated 090606 - 0.9.9.6 - ready for 2.8 hooks - ready for multiple languages list widget
    27 # updated 120212 - 2.4.2 - admin_bar replaced by toolbar and node (>= WP3.3) - cc: + Reply-To: - better merge loadthemedomain in multisite - ready for XD 2.0 - sub-sub-folder for language files
    25 # see readme text for these intermediate versions.
    28 # updated 120128 - 2.4.1 - new readme - new tabs in settings - improved lang slug creation - test menu location get_registered_nav_menus - 
       
    29 # updated 111222 - 2.4.0 - if needed and present add rtl.css for rtl languages - new date based on wp_locale - time options
       
    30 # less than 2.4….
       
    31 # see readme text for these intermediate versions for WP 2.x. or visit other previous versions (2.5).
    26 # updated 090228 - Class and OOP - see 0.9.7 in comments of functions below - only for WP 2.7.x
    32 # updated 090228 - Class and OOP - see 0.9.7 in comments of functions below - only for WP 2.7.x
    27 
    33 
    28 # This plugin is free software; you can redistribute it and/or
    34 # This plugin is free software; you can redistribute it and/or
    29 # modify it under the terms of the GNU Lesser General Public
    35 # modify it under the terms of the GNU Lesser General Public
    30 # License as published by the Free Software Foundation; either
    36 # License as published by the Free Software Foundation; either
    37 #
    43 #
    38 # You should have received a copy of the GNU Lesser General Public
    44 # You should have received a copy of the GNU Lesser General Public
    39 # License along with this plugin; if not, write to the Free Software
    45 # License along with this plugin; if not, write to the Free Software
    40 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    46 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    41 
    47 
    42 define('XILILANGUAGE_VER','1.4.1'); /* used in admin UI*/
    48 
       
    49 define('XILILANGUAGE_VER','2.8.1'); /* used in admin UI*/
       
    50 define('XILILANGUAGE_WP_VER','3.3'); /* used in error - see at end */
       
    51 define('XILILANGUAGE_PHP_VER','5.0.0'); /* used in error - see at end */
       
    52 define('XILILANGUAGE_PREV_VER','2.4.3');
       
    53 
       
    54 
       
    55 
       
    56 
       
    57 /********************* the CLASS **********************/
    43 
    58 
    44 class xili_language {
    59 class xili_language {
    45 	
    60 	
       
    61 	var $xili_settings; /* saved in options */
       
    62 	
       
    63 	var $langs_group_id; /* group ID and Term Taxo ID */
       
    64 	var $langs_group_tt_id; 
       
    65 	
    46 	var $default_lang; /* language of config.php*/
    66 	var $default_lang; /* language of config.php*/
       
    67 	var $default_slug; /* slug of language of config.php since 1.5.3 wpmu*/
    47 	var $curlang;
    68 	var $curlang;
       
    69 	
       
    70 	var $thetextdomain = ""; /* since 1.5.2 - used if multiple */
    48 	var $langstate; /* undefined or not */
    71 	var $langstate; /* undefined or not */
       
    72 	
    49 	var $browseroption = '';
    73 	var $browseroption = '';
       
    74 	var $lang_neither_browser = ''; // when neither match with browser
    50 	var $authorbrowseroption = '';
    75 	var $authorbrowseroption = '';
    51 	var $functions_enable = '';
    76 	
    52 	var $default_dir = ''; /* undefined or not in WP config '' or rtl or ltr */
    77 	var $default_dir = ''; /* undefined or not in WP config '' or rtl or ltr */
    53 	var $curlang_dir = ''; /* undefined or not according array */
    78 	var $curlang_dir = ''; /* undefined or not according array */
    54 	var $rtllanglist = 'ar-he-fa-ur'; /*default-list - can be set after class instantiation*/
    79 	var $rtllanglist = 'ar-he-fa-ur'; /* default-list - can be set after class instantiation */
    55 	var $post_ajax = false; /* ajax used in meta box in post edit UI unstable yet */
    80 	
    56 	var $is_metabox = false; /* meta box in post edit UI - if used don't use custom fields that are not refreshed */
       
    57 	var $xili_settings; /* saved in options */
       
    58 	var $langs_group_id; /* group ID and Term Taxo ID */
       
    59 	var $langs_group_tt_id; 
       
    60 	var $get_archives_called = array(); /* if != '' - insert lang in link */
    81 	var $get_archives_called = array(); /* if != '' - insert lang in link */
    61 	var $idx = array(); /* used to identify filter or action set from this class - since 0.9.9.6 */
    82 	var $idx = array(); /* used to identify filter or action set from this class - since 0.9.9.6 */
    62 	var $theme_locale = false; /* to control locale hook */
    83 	var $theme_locale = false; /* to control locale hook */
    63 	var $ossep = "/"; /* for recursive file search in xamp */
    84 	var $ossep = "/"; /* for recursive file search in xamp */
       
    85 	
    64 	var $current_lang_query_tag = ""; /* since 1.3.0 */
    86 	var $current_lang_query_tag = ""; /* since 1.3.0 */
    65 	var $temp_lang_query_tag = "";
    87 	var $temp_lang_query_tag = "";
    66 	
    88 	
    67 	function xili_language($metabox = false, $post_ajax = false, $locale_method = false) {
    89 	var $domaindetectmsg = ""; // used if pb with load_theme_textdomain
    68 		$this->is_metabox = $metabox;
    90 	
    69 		$this->post_ajax = $post_ajax;
    91 	var $langs_list_options = array( array('','default'), array('typeone','Type #1'), array('typeonenew','Type for single'), array('navmenu', 'Nav Menu' ) , array('navmenu-1', 'Nav Menu Singular' ) ); // type of languages list see options in xili_language_list or navmenu
       
    92 	
       
    93 	var $comment_form_labels = array ( // since 1.6.0 for comment_form 
       
    94 		'name' => 'Name',
       
    95 		'email' => 'Email',
       
    96 		'website' => 'Website',
       
    97 		'comment' => 'Comment',
       
    98 		'youmustbe' => 'You must be <a href="%s">logged in</a> to post a comment.',
       
    99 		'loggedinas' => 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>',
       
   100 		'emailnotpublished' => 'Your email address will not be published.',
       
   101 		'requiredmarked' => ' Required fields are marked <span class="required">*</span>',
       
   102 		'youmayuse' => 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:',
       
   103 		'leavereply' => 'Leave a Reply',
       
   104 		'replyto' => 'Leave a Reply to %s',
       
   105 		'cancelreply' => 'Cancel reply',
       
   106 		'postcomment' => 'Post Comment'
       
   107 		);
       
   108 		
       
   109 	var $sticky_keep_original = false ; // since 1.6.1 see translate_sticky_posts_ID function 
       
   110 	var $xl_recent_posts = false ;
       
   111 	var $ltd = false ; // load_textdomain detected 1.8.5
       
   112 	var $arraydomains = array();
       
   113 	var $show = false ;
       
   114 	
       
   115 	var $langs_ids_array ; // array slug => id
       
   116 	var $langs_slug_name_array ; // array slug => name // 2.4.2
       
   117 	var $langs_slug_fullname_array; // array slug => full name // 2.6.3
       
   118 	
       
   119 	var $show_page_on_front = false; 
       
   120 	
       
   121 	/* for permalink with lang at root */
       
   122 	var $lang_perma = false; // if true new permalink for root and categories /en_us/category/.... if special action available… 2.1.1
       
   123 	var $lpr = ''; // 2.3.2
       
   124 	var $show_page_on_front_array = array(); // array of lang=>page_id if show_on_front == page
       
   125 	
       
   126 	var $undefchar = "."; // 2.2.3 - used to detect undefined
       
   127 	var $sublang = ""; // 2.2.3 - used to detect - or fr_fr- of like
       
   128 	
       
   129 	// 2.5
       
   130 	// other in class admin
       
   131 	var $translation_state = '_xl_translation_state' ; // set to initial when post created from dashboard metabox (to update post slug)
       
   132 	
       
   133 	// 2.6 - class admin in separate file
       
   134 	var $file_file = ''; // see in construct below
       
   135 	var $file_basename = '';
       
   136 	var $plugin_basename = '';
       
   137 	var $plugin_url = '';
       
   138 	var $plugin_path = ''; // The path to this plugin - see construct
       
   139 	
       
   140 	var $xilidev_folder = '/xilidev-libraries'; //must be in plugins
       
   141 	
       
   142 	//since 2.7.1 - updated 2.8.0
       
   143 	var $examples_list = array();
       
   144 	
       
   145 	/**** Construct is future ****/
       
   146 	
       
   147 	public function __construct( $locale_method = false, $show = false, $class_admin = false ) {
       
   148 		
       
   149 		// 2.6 - class admin in separate file
       
   150 		$this->file_file = __FILE__ ; // see in construct below
       
   151 		$this->file_basename = basename(__FILE__) ;
       
   152 		$this->plugin_basename = plugin_basename(__FILE__) ;
       
   153 		$this->plugin_url = plugins_url('', __FILE__) ; 
       
   154 		$this->plugin_path = plugin_dir_path(__FILE__) ;
       
   155 		 
    70 		$this->locale_method = $locale_method; /* added for compatibility with cache plugin from johan */
   156 		$this->locale_method = $locale_method; /* added for compatibility with cache plugin from johan */
    71 		/*activated when first activation of plug*/
   157 		$this->show = $show;
       
   158 		$this->class_admin = $class_admin;
       
   159 		/* activated when first activation of plug */
       
   160 		
    72 		register_activation_hook(__FILE__,array(&$this,'xili_language_activate'));
   161 		register_activation_hook(__FILE__,array(&$this,'xili_language_activate'));
    73 		$this->ossep = strtoupper(substr(PHP_OS,0,3)=='WIN')?'\\':'/';
   162 		$this->ossep = strtoupper( substr(PHP_OS ,0 ,3 ) == 'WIN' ) ? '\\' : '/';	
    74 		/*get current settings - name of taxonomy - name of query-tag - 0.9.8 new taxonomy taxolangsgroup */
   163 		
    75 		$this->xili_settings = get_option('xili_language_settings');
   164 			 
    76 		if(empty($this->xili_settings)) {
   165 		/** 
    77 			$submitted_settings = array(
   166 		 * get current settings
       
   167 		 */
       
   168 		$this->xili_settings = get_option('xili_language_settings'); 
       
   169 		if( false === $this->xili_settings ) { //1.9.1
       
   170 			$this->initial_settings ();
       
   171 			update_option('xili_language_settings', $this->xili_settings);				
       
   172 		} else {
       
   173 			if ($this->xili_settings['version'] == '1.9') { /* 2.4.0 */	
       
   174 				$this->xili_settings['wp_locale'] = 'wp_locale'; //wp_locale new mode
       
   175 				$this->xili_settings['version'] = '2.0';
       
   176 				update_option('xili_language_settings', $this->xili_settings); //
       
   177 			}
       
   178 			if ($this->xili_settings['version'] == '2.0') { /* 2.4.0 */	
       
   179 				$this->xili_settings['available_langs'] = array(); // default array 
       
   180 				$this->xili_settings['version'] = '2.1';
       
   181 				update_option('xili_language_settings', $this->xili_settings); //
       
   182 			}
       
   183 			if ($this->xili_settings['version'] == '2.1') { /* 2.6.0 */	
       
   184 				$this->xili_settings['external_xl_style'] = "on";
       
   185 				$this->xili_settings['creation_redirect'] = 'redirect'; // default - after initial creation 
       
   186 				$this->xili_settings['version'] = '2.2';
       
   187 				update_option('xili_language_settings', $this->xili_settings);  //
       
   188 			}
       
   189 			
       
   190 			if ( ! isset ( $this->xili_settings['version'] ) || $this->xili_settings['version'] != '2.2') { // repair or restart from new
       
   191 				$this->initial_settings ();
       
   192 				update_option('xili_language_settings', $this->xili_settings);  
       
   193 			}
       
   194 		}
       
   195 		if ( ! $class_admin ) {
       
   196 			if ( ! defined( 'TAXONAME' ) ) define('TAXONAME', $this->xili_settings['taxonomy']);
       
   197 			if ( ! defined( 'QUETAG' ) ) define('QUETAG', $this->xili_settings['reqtag']); // 'lang'
       
   198 			if ( ! defined( 'TAXOLANGSGROUP' ) ) define('TAXOLANGSGROUP', $this->xili_settings['taxolangsgroup']);
       
   199 			if ( ! defined( 'LANG_UNDEF' ) ) define('LANG_UNDEF', $this->xili_settings['lang_undefined']); //2.2.3
       
   200 		}
       
   201 		
       
   202 		$this->browseroption = $this->xili_settings['browseroption']; 
       
   203 		$this->lang_neither_browser = $this->xili_settings['lang_neither_browser']; // 2.3.1
       
   204 		$this->authorbrowseroption = $this->xili_settings['authorbrowseroption'];
       
   205 		
       
   206 		
       
   207 		//$this->thetextdomain = $this->xili_settings['theme_domain']; /* since 1.5.2 */
       
   208 		$this->langsliststatus = $this->xili_settings['langs_list_status'];  /* 1.6.0 */
       
   209 		
       
   210 		/* detect research about permalinks */
       
   211 		
       
   212 		//$this->lang_perma = ( has_filter ( 'term_link', 'insert_lang_4cat' ) ) ? true : false ;	// 1.4.1
       
   213 		$this->show_page_on_front = ( 'page' == $this->get_option_wo_xili('show_on_front') ) ;
       
   214 		
       
   215 		if ( !$class_admin )  { // filtering only one time 2.6
       
   216 			add_action( 'init', array(&$this,'init_textdomain'));
       
   217 			add_action( 'init', array(&$this,'init_and_register_language_post_taxonomy') );
       
   218 		}
       
   219 		add_action( 'init', array(&$this,'init_vars') ); // moved here 2.8.0
       
   220 		
       
   221 		if ( !$class_admin ) { // filtering only one time 2.6
       
   222 			
       
   223 			add_action( 'init', array(&$this,'add_link_taxonomy'), 12 ); // 1.8.5	
       
   224 			/* special to detect theme changing since 1.1.9 */
       
   225 			add_action( 'switch_theme', array(&$this,'theme_switched') );	
       
   226 				
       
   227 			/* query filters */	
       
   228 			add_filter( 'posts_join', array(&$this,'posts_join_with_lang'), 10, 2 );
       
   229 			add_filter( 'posts_where', array(&$this,'posts_where_lang'), 10, 2 );
       
   230 			
       
   231 			add_filter( 'posts_search', array(&$this,'posts_search_filter'), 10, 2 ); //2.2.3
       
   232 			add_action( 'pre_get_posts', array(&$this,'xiliml_modify_querytag') );
       
   233 			
       
   234 			
       
   235 			add_action( 'wp', array(&$this,'xiliml_language_wp') ); /// since 2.2.3 - wp_loaded - wp before
       
   236 			/* 'wp' = where theme's language is defined just after query */
       
   237 			if ( $this->xili_settings['wp_locale'] == 'wp_locale' )
       
   238 				add_action( 'wp', array(&$this,'xili_locale_setup'), 15 ); // since 2.4
       
   239 			if ( $this->locale_method )
       
   240 				add_filter('locale', array(&$this,'xiliml_setlocale'), 10);
       
   241 			/* to be compatible with l10n cache from Johan since 1.1.9 */
       
   242 			
       
   243 			
       
   244 	 		add_filter( 'widget_title', array(&$this,'one_text')); /* added 0.9.8.1 */
       
   245 		 	add_filter( 'widget_text', array(&$this,'one_text'));
       
   246 		 	
       
   247 			add_filter( 'list_cats', array(&$this,'xiliml_cat_language'), 10, 2 ); /* mode 2 : content = name */
       
   248 			add_filter( 'link_category', array(&$this,'one_text')); // 1.6.0 for wp_list_bookmarks (forgotten)
       
   249 			add_filter( 'category_link', array(&$this,'xiliml_link_append_lang'), 10, 2 );
       
   250 			$filter = 'category_link';
       
   251 			$function = 'xiliml_link_append_lang';
       
   252 			$this->idx['xiliml_link_append_lang'] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), 10, 2); 
       
   253 			/* unique id of this filter from object fixed 1.0.1 */
       
   254 			add_filter( 'category_description',array(&$this,'xiliml_link_translate_desc'));
       
   255 			add_filter( 'single_cat_title',array(&$this,'xiliml_single_cat_title_translate')); /* 1.4.1 wp_title() */
       
   256 			
       
   257 			add_filter( 'tag_link', array(&$this,'xiliml_taglink_append_lang' ));
       
   258 			
       
   259 			add_filter( 'bloginfo', array(&$this,'xiliml_bloginfo'), 10, 2); /* since 1.6.0 - description - date - time */
       
   260 			
       
   261 			/* filters for archives since 0.9.9.4 */
       
   262 			add_filter( 'getarchives_join', array(&$this, 'xiliml_getarchives_join'), 10, 2 );
       
   263 			add_filter( 'getarchives_where', array(&$this, 'xiliml_getarchives_where'), 10, 2 );
       
   264 			add_filter( 'get_archives_link', array(&$this, 'xiliml_get_archives_link') );
       
   265 			
       
   266 			/* option modified */
       
   267 			add_filter( 'option_sticky_posts', array(&$this, 'translate_sticky_posts_ID') ); /* 1.6.1 */
       
   268 			
       
   269 			add_filter( 'option_page_on_front', array(&$this, 'translate_page_on_front_ID') ); /* 1.7.0 */
       
   270 			$filter = 'option_page_on_front';
       
   271 			$function = 'translate_page_on_front_ID';
       
   272 			$this->idx['translate_page_on_front_ID'] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), 10, 2);
       
   273 			
       
   274 			/* bookmarks and widget_links  1.8.5  #2500 */
       
   275 			add_filter( 'widget_links_args', array( &$this, 'widget_links_args_and_lang' ), 10, 1 ); // in class WP_Widget_Links (default-widgets.php)
       
   276 			add_filter( 'get_bookmarks', array( &$this, 'the_get_bookmarks_lang' ), 10, 2); // only active if 'lang' in wp_list_bookmarks()
       
   277 			
       
   278 			add_action( 'wp_head', array(&$this,'head_insert_language_metas'), 11 ); // © and options present in functions.php
       
   279 			
       
   280 			if ( !is_admin() ) {
       
   281 				add_filter( 'the_category', array(&$this,'xl_get_the_category_list'), 10, 2); /* 1.7.0 */
       
   282 				add_filter( 'gettext', array(&$this,'change_plugin_domain'), 10, 3); /* 1.8.7 */
       
   283 				add_filter( 'gettext_with_context', array(&$this,'change_plugin_domain_with_context'), 10, 4); /* 1.8.8 */
       
   284 				add_filter( 'ngettext', array(&$this,'change_plugin_domain_plural'), 10, 5);
       
   285 				add_filter( 'ngettext_with_context', array(&$this,'change_plugin_domain_plural_with_context'), 10, 6);
       
   286 				
       
   287 				// for wp nav menu
       
   288 				add_filter('the_title', array(&$this,'wp_nav_title_text'),10,2);
       
   289 				if ('' != $this->xili_settings['in_nav_menu'])
       
   290 						add_filter('wp_nav_menu_items', 'xili_nav_lang_list',10,2);
       
   291 				if ('' != $this->xili_settings['page_in_nav_menu'])
       
   292 						add_filter('wp_nav_menu_items', 'xili_nav_page_list',9,2); // before lang's links - 1.7.1
       
   293 				if ('' != $this->xili_settings['home_item_nav_menu'])
       
   294 						add_filter('walker_nav_menu_start_el', 'xili_nav_page_home_item',10,4); // add lang if - 1.8.9.2
       
   295 				
       
   296 				add_filter( 'language_attributes',  array(&$this,'head_language_attributes'));
       
   297 				add_action( 'wp_head', array(&$this,'head_insert_hreflang_link' ), 10 ); // since 2.5
       
   298 				
       
   299 				add_filter( 'option_date_format', array(&$this, 'translate_date_format') ); /* 1.7.0 */
       
   300 				
       
   301 				add_filter( 'category_feed_link', array(&$this, 'category_feed_link') ); // 2.8.1
       
   302 			}
       
   303 			
       
   304 			// since 1.5.5
       
   305 			add_filter( 'comment_form_default_fields', array(&$this,'xili_comment_form_default_fields'));
       
   306 			add_filter( 'comment_form_defaults', array(&$this,'xili_comment_form_defaults'));
       
   307 			
       
   308 			// since 2.4.0 for rtl.css
       
   309 			add_filter( 'locale_stylesheet_uri', array(&$this, 'change_locale_stylesheet_uri' ),10, 2 ) ;
       
   310 	
       
   311 			// since 1.8.8 - activate xl widget series
       
   312 			if ( $this->xili_settings['widget'] == 'enable' )
       
   313 				add_action( 'widgets_init', array(&$this,'add_new_widgets') );
       
   314 		
       
   315 			/* new actions for xili-language theme's templates tags */
       
   316 			
       
   317 			$this->add_action( 'xili_language_list', 'xili_language_list', 10, 5); /* add third param 0.9.7.4 - 4th 1.6.0*/
       
   318 			$this->add_action( 'xili_post_language', 'xili_post_language', 10, 2);
       
   319 			
       
   320 			$this->add_action( 'xiliml_the_other_posts', 'the_other_posts', 10, 4); /* add a param 1.1 */
       
   321 			$this->add_action( 'xiliml_the_category', 'the_category', 10, 3);
       
   322 			$this->add_filter( 'xiliml_langinsearchform', 'xiliml_langinsearchform', 10, 3); // 1.8.2 action to filter
       
   323 		
       
   324 		// verify theme and set ltd for both parent and admin child
       
   325 			add_filter( 'override_load_textdomain', array(&$this,'xiliml_override_load'), 10, 3); // since 1.5.0
       
   326 			add_filter( 'theme_locale', array(&$this,'xiliml_theme_locale'), 10, 2);	// two times if is_admin()
       
   327 		}
       
   328 	}
       
   329 	
       
   330 	/** 
       
   331 	 * first activation or empty settings 
       
   332 	 */
       
   333 	function initial_settings () {
       
   334 		$this->xili_settings = array(
    78 			    'taxonomy'		=> 'language',
   335 			    'taxonomy'		=> 'language',
    79 			    'version' 		=> '0.4',
   336 			    'version' 		=> '2.2',
    80 			    'reqtag'		=> 'lang',
   337 			    'reqtag'		=> 'lang', // query_var
    81 			    'browseroption' => '',
   338 			    'browseroption' => '',
    82 			    'authorbrowseroption' => '',
   339 			    'authorbrowseroption' => '',
    83 			    'taxolangsgroup' => 'languages_group',
   340 			    'taxolangsgroup' => 'languages_group',
    84 			    'functions_enable' => '',
   341 			    'functions_enable' => '',
    85 			    'langs_folder' => '',
   342 			    'langs_folder' => '',
    86 			    'theme_domain' => '',
   343 			    'theme_domain' => '',
    87 			    'homelang' => '' 
   344 			    'homelang' => '',
       
   345 			    'langs_list_status' => '',
       
   346 			    'in_nav_menu' => '',
       
   347 			    'page_in_nav_menu' => '',
       
   348 				'args_page_in_nav_menu' => '',
       
   349 				'multilingual_custom_post' => array(),
       
   350 				'langs_in_root_theme' => '',
       
   351 				'domains' => array( 'all' => 'disable', 'default' => 'disable','bbpress' => 'disable' ),  // no default domain to theme domain 1.8.7
       
   352 				'widget' => 'enable',
       
   353 				'delete_settings' => '', //1.8.8 for uninstall
       
   354 				'allcategories_lang' => 'browser', // 1.8.9.1
       
   355 				'lang_features' => array() ,
       
   356 				'home_item_nav_menu' => '', // 1.8.9.2
       
   357 				'lang_undefined' => $this->undefchar, //2.2.3
       
   358 				'lang_neither_browser' => '', // 2.3.1
       
   359 				'wp_locale' => 'wp_locale', // 2.7.1 new mode as default - 2.4.0 = old mode based on db strftime
       
   360 				'available_langs' => array(),
       
   361 				'creation_redirect' => 'redirect', // 2.6 to redirect to new post after creation
       
   362 				'external_xl_style' => "on" // activate external xl-style.css - on by default :2.6.3
    88 		    );
   363 		    );
    89 			define('TAXONAME','language');
   364 	}
    90 			define('QUETAG','lang');
   365 	
    91 			define('TAXOLANGSGROUP','languages_group');
   366 	/* first activation of plugin */
    92 			update_option('xili_language_settings', $submitted_settings);	
   367 	function xili_language_activate() {
    93 			$this->xili_settings = get_option('xili_language_settings');		
   368 		$this->xili_settings = get_option('xili_language_settings');
    94 		} else {
   369 		if( empty($this->xili_settings) ) {
    95 			define('TAXONAME',$this->xili_settings['taxonomy']);
   370 			$this->initial_settings ();
    96 			define('QUETAG',$this->xili_settings['reqtag']);
   371 		    update_option('xili_language_settings', $this->xili_settings);  
    97 			$this->browseroption = $this->xili_settings['browseroption'];
   372 		}
    98 			$this->authorbrowseroption = $this->xili_settings['authorbrowseroption'];
   373 	}
    99 			$this->functions_enable = $this->xili_settings['functions_enable'];
   374 	
   100 			if ($this->xili_settings['version'] == '0.2' || $this->xili_settings['version'] == '0.3') { /* 1.3.2 */
   375 	function add_action ( $action, $function = '', $priority = 10, $accepted_args = 1 )
   101 				$this->xili_settings['taxolangsgroup'] = 'languages_group';
   376 	{
   102 				$this->xili_settings['homelang'] = '';
   377 		add_action ($action, array (&$this, $function == '' ? $action : $function), $priority, $accepted_args);
   103 				$this->xili_settings['version'] = '0.4';
   378 		$this->idx[$action] = _wp_filter_build_unique_id($action, array (&$this, $function == '' ? $action : $function), $priority); /* unique id of this filter from object */		 
   104 				update_option('xili_language_settings', $this->xili_settings);
   379 	}
   105 			}	
   380 	
   106 			define('TAXOLANGSGROUP',$this->xili_settings['taxolangsgroup']);
   381 	function add_filter ( $filter, $function = '', $priority = 10, $accepted_args = 1 )
   107 		}
   382 	{
   108 		define('XILIFUNCTIONSPATH',WP_PLUGIN_DIR.'/xilidev-libraries'); /* since 1.0 to add xili-libraries */
   383 		add_filter ($filter, array (&$this, $function == '' ? $filter : $function), $priority, $accepted_args);
   109 		
   384 		$this->idx[$filter] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), $priority); /* unique id of this filter from object fixed 1.0.1 */
       
   385 	}
       
   386 		
       
   387 	/**
       
   388 	 * for wpmu 
       
   389 	 * register functions must be called by init
       
   390 	 *
       
   391 	 * @since 1.5.1
       
   392 	 *
       
   393 	 */
       
   394 	function init_and_register_language_post_taxonomy () {
   110 		/** add new taxonomy in available taxonomies 
   395 		/** add new taxonomy in available taxonomies 
   111 		 * 1.0.2 - add label false as http://core.trac.wordpress.org/ticket/10437 
   396 		 * 1.0.2 - add label false as http://core.trac.wordpress.org/ticket/10437 
   112 		 * 			to avoid metabox as tag displayed
   397 		 * 			to avoid metabox as tag displayed  , 'query_var' => QUETAG 
       
   398 		 * @updated 1.4.1
   113 		 */
   399 		 */
   114 		register_taxonomy( TAXONAME, 'post',array('hierarchical' => false, 'label'=>false, 'rewrite' => false, 'update_count_callback' => array(&$this,'_update_post_lang_count')));
   400 		
   115 		register_taxonomy( TAXOLANGSGROUP, 'term',array('hierarchical' => false, 'update_count_callback' => ''));
   401 		if ( !$this->class_admin ) {
   116 		$thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group'));
   402 			if ( $this->xili_settings['wp_locale'] == 'wp_locale' )
   117 		if (!$thegroup) { /* update langs group 0.9.8 */
   403 				xiliml_declare_xl_wp_locale ();
   118 			$args = array( 'alias_of' => '', 'description' => 'the group of languages', 'parent' => 0, 'slug' =>'the-langs-group');
   404 			
   119 			wp_insert_term( 'the-langs-group', TAXOLANGSGROUP, $args); /* create and link to existing langs */
   405 			if ( $this->lang_perma ) {
   120 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
   406 				
   121 			foreach($listlanguages as $language) {
   407 				register_taxonomy( TAXONAME, 'post', array('hierarchical' => false, 'label' => false, 'rewrite' => false , 'update_count_callback' => array(&$this, '_update_post_lang_count'), 'show_ui' => false, '_builtin' => false, 'query_var' => QUETAG ));
   122 				wp_set_object_terms($language->term_id, 'the-langs-group', TAXOLANGSGROUP);
   408 				$this->lpr = "-"; // 2.3.2
   123 			}
   409 			} else {
   124 			$thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group'));
   410 				add_filter('query_vars', array(&$this,'keywords_addQueryVar')); // now in taxonomy decl. // 2.1.1
   125 		}
   411 				register_taxonomy( TAXONAME, 'post', array('hierarchical' => false, 'label' => false, 'rewrite' => false , 'update_count_callback' => array(&$this, '_update_post_lang_count'), 'show_ui' => false, '_builtin' => false ));
   126 		$this->langs_group_id = $thegroup[0]->term_id;
   412 				
   127 		$this->langs_group_tt_id = $thegroup[0]->term_taxonomy_id;
   413 			}
   128 		
   414 			
       
   415 			register_taxonomy( TAXOLANGSGROUP, 'term', array('hierarchical' => false, 'update_count_callback' => '', 'show_ui' => false, 'label'=>false, 'rewrite' => false, '_builtin' => false ));
       
   416 		}
       
   417 		
       
   418 	}
       
   419 	
       
   420 	/**
       
   421 	 * since 2.6
       
   422 	 *
       
   423 	 */
       
   424 	function init_vars () {
       
   425 		
       
   426 		$this->examples_list = array(
       
   427 		'af' => __('afrikaans','xili-language'),
       
   428 		'ar_AR' => __('arabic', 'xili-language'),
       
   429 		'be_BY' => __('belarusian', 'xili-language'),
       
   430 		'bs_BA' => __('bosnian', 'xili-language'),
       
   431 		'bg_BG' => __('bulgarian', 'xili-language'),
       
   432 		'bn_BD' => __('bangla', 'xili-language'),
       
   433 		'ca' => __('catalan', 'xili-language'),
       
   434 		'cs_CZ' => __('czech', 'xili-language'),
       
   435 		'cy' => __('welsh', 'xili-language'),
       
   436 		'da_DK' => __('danish', 'xili-language'),
       
   437 		'de_DE' => __('german', 'xili-language'),
       
   438 		'el' => __('greek', 'xili-language'),
       
   439 		'en_GB' => __('british english', 'xili-language'),
       
   440 		'en_US' => __('english', 'xili-language'),
       
   441 		'eo' => __('esperanto', 'xili-language'),
       
   442 		'es_ES' => __('spanish', 'xili-language'),
       
   443 		'es_CL' => __('chilean', 'xili-language'),
       
   444 		'et' => __('estonian', 'xili-language'),
       
   445 		'eu' => __('euskara', 'xili-language'),
       
   446 		'fa_IR' => __('persian', 'xili-language'),
       
   447 		'fi_FI' => __('finnish', 'xili-language'),
       
   448 		'fo' => __('faroese', 'xili-language'),
       
   449 		'fr_FR' => __('french', 'xili-language'),
       
   450 		'ge_GE' => __('georgian', 'xili-language'),
       
   451 		'gl_ES' => __('galician', 'xili-language'),
       
   452 		'he_IL' => __('hebrew', 'xili-language'),
       
   453 		'hr' => __('croatian', 'xili-language'),
       
   454 		'hu_HU' => __('hungarian', 'xili-language'),
       
   455 		'id_ID' => __('indonesian', 'xili-language'),
       
   456 		'is_IS' => __('icelandic', 'xili-language'),
       
   457 		'it_IT' => __('italian', 'xili-language'),
       
   458 		'ja' => __('japanese', 'xili-language'),
       
   459 		'km_KH' => __('khmer', 'xili-language'),
       
   460 		'ko_KR' => __('korean', 'xili-language'),
       
   461 		'lt_LT' => __('lithuanian', 'xili-language'),
       
   462 		'lv' => __('latvian', 'xili-language'),
       
   463 		'mg_MG' => __('malagasy', 'xili-language'),
       
   464 		'mk_MK' => __('macedonian', 'xili-language'),
       
   465 		'mn_MN' => __('mongolian', 'xili-language'),
       
   466 		'ms_MY' => __('malay', 'xili-language'),
       
   467 		'nb_NO' => __('norwegian', 'xili-language'),
       
   468 		'ni_ID' => __('nias', 'xili-language'),
       
   469 		'nl_NL' => __('dutch', 'xili-language'),
       
   470 		'pl_PL' => __('polish', 'xili-language'),
       
   471 		'pt_BR' => __('brazilian portuguese', 'xili-language'),
       
   472 		'pt_PT' => __('portuguese', 'xili-language'),
       
   473 		'ro_RO' => __('romanian', 'xili-language'),
       
   474 		'ru_RU' => __('russian', 'xili-language'),
       
   475 		'si_LK' => __('sinhala', 'xili-language'),
       
   476 		'sk_SK' => __('slovak', 'xili-language'),
       
   477 		'sl_SI' => __('slovenian', 'xili-language'),
       
   478 		'sq_AL' => __('albanian', 'xili-language'),
       
   479 		'sr_CS' => __('serbian', 'xili-language'),
       
   480 		'sv_SE' => __('swedish', 'xili-language'),
       
   481 		'su_ID' => __('sundanese', 'xili-language'),
       
   482 		'tg' => __('tajik', 'xili-language'),
       
   483 		'th' => __('thai', 'xili-language'),
       
   484 		'tr' => __('turkish', 'xili-language'),
       
   485 		'uk_UA' => __('ukrainian', 'xili-language'),
       
   486 		'uz_UZ' => __('uzbek', 'xili-language'),
       
   487 		'vi' => __('vietnamese', 'xili-language'),
       
   488 		'zh_CN' => __('chinese', 'xili-language'),
       
   489 		'zh_TW' => __('taiwan chinese', 'xili-language'),
       
   490 		'zh_HK' => __('hong kong chinese', 'xili-language')
       
   491 		);
   129 		/* default values */
   492 		/* default values */
   130 		if (''!= WPLANG && strlen(WPLANG)==5) :
   493 		if ( ''!= WPLANG && ( strlen( WPLANG )==5 || strlen( WPLANG ) == 2 ) ) : // for japanese
   131 			$this->default_lang = WPLANG;
   494 			$this->default_lang = WPLANG;
   132 		else:
   495 		else:
   133 			$this->default_lang = 'en_US';
   496 			$this->default_lang = 'en_US';
   134 		endif;
   497 		endif;
   135 		define('DEFAULTSLUG', $this->get_default_slug());
   498 		
       
   499 		$thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group'));
       
   500 		if ( array() == $thegroup ) { /* update langs group 0.9.8 and if from start 2.3.1 */ 
       
   501 			$args = array( 'alias_of' => '', 'description' => 'the group of languages', 'parent' => 0, 'slug' =>'the-langs-group');
       
   502 			wp_insert_term( 'the-langs-group', TAXOLANGSGROUP, $args); /* create and link to existing langs */
       
   503 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false, 'get' => 'all'));
       
   504 			if ( array() == $listlanguages ) { /*create two default lines with the default language (as in config)*/ 
       
   505 		  		/* language of WP */
       
   506 				
       
   507 				$term = 'en_US';
       
   508 				$args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'en_us');
       
   509 				
       
   510 				$theids = $this->safe_lang_term_creation ( $term, $args );
       
   511 				if ( ! is_wp_error($theids) ) {
       
   512 					wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
   513 					$this->xili_settings['lang_features']['en_us'] = array('charset'=>"",'hidden'=>"");
       
   514 				}
       
   515 				$term = $this->default_lang;
       
   516 		 		$desc = ( isset($this->examples_list[$term]) ) ? $this->examples_list[$term] : $this->default_lang;
       
   517 		 		$slug = strtolower( $this->default_lang ) ; // 2.3.1
       
   518 		 		if (!defined('WPLANG') || $this->default_lang == 'en_US' || $this->default_lang == '' ) {
       
   519 		 			$term = 'fr_FR'; $desc = 'french'; $slug = 'fr_fr' ;
       
   520 		 		}
       
   521 		 		$args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug);
       
   522 		 		
       
   523 		 		$theids = $this->safe_lang_term_creation ( $term, $args ) ;
       
   524 				if ( ! is_wp_error($theids) ) {
       
   525 					wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
   526 					$this->xili_settings['lang_features'][$slug] = array('charset'=>"",'hidden'=>"");
       
   527 		 		}
       
   528 				update_option('xili_language_settings', $this->xili_settings); 
       
   529 				$listlanguages = get_terms(TAXONAME, array('hide_empty' => false, 'get' => 'all'));
       
   530 			}	
       
   531 			foreach( $listlanguages as $language ) {
       
   532 				wp_set_object_terms( $language->term_id, 'the-langs-group', TAXOLANGSGROUP );
       
   533 			}
       
   534 			$thegroup = get_terms( TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group', 'get' => 'all') );
       
   535 		}
       
   536 		
       
   537 		if (function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 - 1.8.5
       
   538 			if ( $this->xili_settings['langs_in_root_theme'] == 'root' ) {
       
   539 				$this->get_template_directory = get_template_directory();
       
   540 			} else {
       
   541 				$this->get_template_directory = get_stylesheet_directory();
       
   542 			}
       
   543 		} else {
       
   544 			$this->get_template_directory = get_template_directory();
       
   545 		}
       
   546 		
       
   547 		$this->langs_group_id = $thegroup[0]->term_id;
       
   548 		$this->langs_group_tt_id = $thegroup[0]->term_taxonomy_id;
       
   549 		
       
   550 		$this->get_lang_slug_ids(); // default array of languages slug=>id and slug=>name // 2.4.2
       
   551 		
       
   552 		if ( $this->show_page_on_front ) $this->get_show_page_on_front_array();
       
   553 		/* here because taxonomy is registered : since 1.5.3 */
       
   554 		
       
   555 		$this->default_slug = $this->get_default_slug(); /*no constant for wpmu */
       
   556 		if (!is_multisite() && !defined('DEFAULTSLUG')) define('DEFAULTSLUG',$this->default_slug); /* for backward compatibility */ 
       
   557 		
       
   558 			
   136 		if ( $dir = get_bloginfo('text_direction') ) /* if present in blog options @since 0.9.9 */
   559 		if ( $dir = get_bloginfo('text_direction') ) /* if present in blog options @since 0.9.9 */
   137 			$this->default_dir = $dir;
   560 			$this->default_dir = $dir;
   138 		
   561 			
   139 		add_filter('query_vars', array(&$this,'keywords_addQueryVar'));
   562 			// 1.8.4
   140 		add_filter('posts_join', array(&$this,'with_lang'));
   563 		if ( isset($this->xili_settings['available_langs'])  && array() != $this->xili_settings['available_langs'] ) {
   141 		add_filter('posts_where', array(&$this,'where_lang'));
   564 			$this->available_langs = $this->xili_settings['available_langs']; 
   142 		
   565 		} else {
   143 		add_action('wp', array(&$this,'xiliml_language_wp')); 
   566 			$this->available_langs = $this->get_lang_ids() ;
   144 		/* 'wp' = where theme's language is defined just after query */
   567 			$this->xili_settings['available_langs'] = $this->available_langs;
   145 		if ($this->locale_method)
   568 			update_option('xili_language_settings', $this->xili_settings); 
   146 			add_filter('locale', array(&$this,'xiliml_setlocale'), 10);
   569 		}
   147 		/* to be compatible with l10n cache from Johan since 1.1.9 */
   570 		
   148 		add_filter('language_attributes',  array(&$this,'head_language_attributes'));
   571 		// 2.2.0 - add_roles -
   149 		add_action('wp_head', array(&$this,'head_insert_language_metas'),10,2);
   572 		
   150  
   573 		if ( is_admin() ) {
   151  	 	add_filter('widget_title', array(&$this,'widget_texts')); /* added 0.9.8.1 */
   574 			global $wp_roles;
   152 	 	add_filter('widget_text', array(&$this,'widget_texts'));
   575 			
   153 		add_filter('list_cats', array(&$this,'xiliml_cat_language'),10,2); /* mode 2 : content = name */
   576 			if ( current_user_can ('activate_plugins') ) {
   154 		
   577 				$wp_roles->add_cap ('administrator', 'xili_language_set');
   155 		add_filter('category_link', array(&$this,'xiliml_link_append_lang'));
   578 				$wp_roles->add_cap ('administrator', 'xili_language_menu');
   156 		$filter = 'category_link';
   579 				$wp_roles->add_cap ('administrator', 'xili_language_clone_tax');
   157 		$function = 'xiliml_link_append_lang';
   580 			} elseif ( current_user_can ('editor') ) {
   158 		$this->idx['xiliml_link_append_lang'] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), 10); /* unique id of this filter from object fixed 1.0.1 */
   581 				$wp_roles->add_cap ('editor', 'xili_language_menu');
   159 		
   582 				$wp_roles->add_cap ('editor', 'xili_language_clone_tax'); // able to clone taxonomy ('categeory') during propagate or create post
   160 		add_filter('category_description',array(&$this,'xiliml_link_translate_desc'));
   583 			}
   161 		add_filter('single_cat_title',array(&$this,'xiliml_single_cat_title_translate')); /* 1.4.1 wp_title() */
   584 		}
   162 		add_filter('tag_link', array(&$this,'xiliml_taglink_append_lang' ));
   585 	}
   163 		
   586 	
   164 		add_action('pre_get_posts', array(&$this,'xiliml_modify_querytag'));
   587 	/**
   165 		/* filters for archives since 0.9.9.4 */
   588 	 * Safe language term creation 
   166 		add_filter('getarchives_join', array(&$this,'xiliml_getarchives_join'),10,2);
   589 	 *
   167 		add_filter('getarchives_where', array(&$this,'xiliml_getarchives_where'),10,2);
   590 	 * @since 2.4.1 
   168 		add_filter('get_archives_link', array(&$this,'xiliml_get_archives_link'));
   591 	 */
   169 		/* actions for post and page admin UI */
   592 	 function safe_lang_term_creation ( $term, $args ) {
   170 		add_action('save_post', array(&$this,'xili_language_add'));
   593 	 	global $wpdb ;
   171 		//add_action('publish_post', array(&$this,'xili_language_add')); /* only set when published !*/
   594 		// test if exists with other slug or name 
   172 		add_action('save_page', array(&$this,'xili_language_add'));
   595 		if ( $term_id = term_exists( $term ) ) { 
   173 		//add_action('publish_page', array(&$this,'xili_language_add'));
   596 			$existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name, slug FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A );
   174 		if ($this->post_ajax) {
   597 			if ( $existing_term['slug'] != $args['slug'] ) {
   175 			add_action( 'wp_ajax_oklinked', array(&$this,'ok_linked') );
   598 				$res = wp_insert_term( $term.'xl', TAXONAME, $args); // temp insert with temp other name
   176 			add_action( 'wp_ajax_customrefresh', array(&$this,'custom_refresh') );
   599 				$args['name'] = $term ;
   177 		}
   600 				$res = wp_update_term( $res['term_id'], TAXONAME, $args);
   178 		/* admin settings UI*/
   601 			} else {
   179 		add_action('init', array(&$this, 'init_textdomain'));
   602 				return new WP_Error('term_exists', __('A term with the name provided already exists.'), $term_id );
   180 		add_filter('plugin_action_links',  array(&$this,'xililang_filter_plugin_actions'), 10, 2);
   603 			}
   181 		
   604 		} else {
   182 		add_action('admin_menu', array(&$this,'myplugin_add_custom_box'));
   605 			$res = wp_insert_term( $term, TAXONAME, $args);
   183 		add_action('admin_menu', array(&$this,'xili_add_pages'));
   606 		}
   184 		/* special to detect theme changing since 1.1.9 */
   607 		if (is_wp_error($res)) { 
   185 		add_action('switch_theme', array(&$this,'theme_switched'));
   608 			return $res ;
   186 		/* inspired from custax */
   609 		} else { 
   187 		add_action('manage_posts_custom_column', array(&$this,'xili_manage_column'), 10, 2);
   610 			$theids = $res;
   188 		add_filter('manage_edit_columns', array(&$this,'xili_manage_column_name'));
   611 		}
   189 
   612 		return $theids ;		
   190 		add_action('manage_pages_custom_column', array(&$this,'xili_manage_column'), 10, 2);
   613 	 }
   191 		add_filter('manage_edit-pages_columns', array(&$this,'xili_manage_column_name'));
   614 	 
   192 		
   615 	/**
   193 		/* new actions for xili-language theme's templates tags */
   616 	 * Get list language Objects - designed and used to avoid query by using settings
   194 		
   617 	 *
   195 		$this->add_action('xili_language_list','xili_language_list',10,3); /* add third param 0.9.7.4*/
   618 	 * @since 1.6.0
   196 		$this->add_action('xili_post_language','xili_post_language',10,2);
   619 	 * @param $force to avoid buffer
   197 		
   620 	 * @return array of objects
   198 		$this->add_action('xiliml_the_other_posts','xiliml_the_other_posts',10,4); /* add a param 1.1 */
   621 	 */
   199 		$this->add_action('xiliml_the_category','xiliml_the_category',10,3);
   622 	function get_listlanguages( $force = false ) { 
   200 		$this->add_action('xiliml_langinsearchform','xiliml_langinsearchform',10,2);
   623 		if ( $this->xili_settings['langs_list_status'] != "set" || $force === true ) {
   201 		
   624 	 		$listlanguages = get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); 
   202 	}
   625 	 		if ( $listlanguages ) {
   203 	
   626 	 			$this->xili_settings['languages_list'] = $listlanguages;
   204 	function add_action ($action, $function = '', $priority = 10, $accepted_args = 1)
   627 	 			$this->xili_settings['langs_list_status'] = "set";
   205 	{
   628 	 			if ( ! $this->class_admin )  {
   206 		add_action ($action, array (&$this, $function == '' ? $action : $function), $priority, $accepted_args);
   629 	 				update_option('xili_language_settings', $this->xili_settings); 
   207 		$this->idx[$action] = _wp_filter_build_unique_id($action, array (&$this, $function == '' ? $action : $function), $priority); /* unique id of this filter from object */		 
   630 	 			}
   208 	}
   631 	 		}
   209 	
   632 	 		return $listlanguages;
   210 	function add_filter ($filter, $function = '', $priority = 10, $accepted_args = 1)
   633 		} else {
   211 	{
   634 			return $this->xili_settings['languages_list'];
   212 		add_filter ($filter, array (&$this, $function == '' ? $filter : $function), $priority, $accepted_args);
   635 		}
   213 		$this->idx[$filter] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), $priority); /* unique id of this filter from object fixed 1.0.1 */
   636 	}
       
   637 	
       
   638 	/**
       
   639 	 * Get list language IDs
       
   640 	 *
       
   641 	 * @since 1.8.4
       
   642 	 */
       
   643 	function get_lang_ids() {
       
   644 		 
       
   645 		$lang_ids = array() ;
       
   646 		$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
       
   647 		foreach ( $listlanguages as $lang) {
       
   648 			$lang_ids[] = $lang->term_id;
       
   649 		}
       
   650 		return $lang_ids ;
       
   651 	}
       
   652 	
       
   653 	/**
       
   654 	 * Get list languages slug_IDs
       
   655 	 *
       
   656 	 * @since 2.1.1
       
   657 	 */
       
   658 	function get_lang_slug_ids() {
       
   659 		 
       
   660 		$lang_slugs = array() ;
       
   661 		$lang_names = array() ;
       
   662 		$lang_full_names = array() ;
       
   663 		$listlanguages = $this->get_listlanguages( true );
       
   664 		foreach ( $listlanguages as $lang) {
       
   665 			$key = $lang->slug;
       
   666 			$lang_slugs[$key] = $lang->term_id;
       
   667 			$lang_names[$key] = $lang->name;
       
   668 			$lang_full_names[$key] = $lang->description;
       
   669 		}
       
   670 		$this->langs_ids_array = $lang_slugs;
       
   671 		$this->langs_slug_name_array = $lang_names;
       
   672 		$this->langs_slug_fullname_array = $lang_full_names;
       
   673 		
       
   674 		$this->xili_settings['langs_ids_array'] = $lang_slugs;  
       
   675 		if ( is_admin () && !$this->class_admin ) { 
       
   676 			update_option( 'xili_language_settings', $this->xili_settings );
       
   677 		
       
   678 		}// if changing occurs...
       
   679 	}
       
   680 	
       
   681 	/**
       
   682 	 * get show pages on front 
       
   683 	 *
       
   684 	 * @since 2.1.1
       
   685 	 * 
       
   686 	 *  
       
   687 	 * update $this->show_page_on_front_array array
       
   688 	 */
       
   689 	function get_show_page_on_front_array() {
       
   690 		$front_pages_array = array();
       
   691 		$languages = $this->get_listlanguages( true );
       
   692 		$front_page_id = $this->get_option_wo_xili ('page_on_front');
       
   693 		foreach ( $languages as $lang) {
       
   694 			$key = $lang->slug;
       
   695 			$id = get_post_meta ( $front_page_id, QUETAG.'-'.$key, true );
       
   696 			$page_id = ( ''!= $id ) ? $id : $front_page_id ;  
       
   697 			$front_pages_array[$key] = $page_id; //
       
   698 		} 
       
   699 		
       
   700 		$this->show_page_on_front_array = $front_pages_array; 
       
   701 		$this->xili_settings['show_page_on_front_array'] = $front_pages_array;  
       
   702 		if ( is_admin () ) update_option( 'xili_language_settings', $this->xili_settings ); // if changing occurs...
   214 	}
   703 	}
   215 			
   704 			
   216 	/**
   705 	/**
   217 	 * More than one filter for the function. 
   706 	 * More than one filter for the function. 
   218 	 *
   707 	 *
   219 	 * @since 0.9.7
   708 	 * @since 0.9.7
   220 	 * 
   709 	 * 
   221 	 * @param $the_function (string). 
   710 	 * @param $the_function (string). 
   222 	 * @return true if more than one.
   711 	 * @return true if more than one.
   223 	 */
   712 	 */
   224 	function this_has_filter($the_function) {
   713 	function this_has_filter( $the_function ) {
   225 		global $wp_filter;
   714 		global $wp_filter;
       
   715 		if ( !isset ( $wp_filter[$the_function]) ) return false; // avoid php warning 2.3.0
   226 		$has = $wp_filter[$the_function];
   716 		$has = $wp_filter[$the_function];
   227 		//print_r($has);
   717 		
       
   718 		if ( ! is_array( $has ) ) return false; // avoid php warning 2.1.0
   228 		$keys = array_keys($has);
   719 		$keys = array_keys($has);
   229 		//echo count($has[$keys[0]]);
   720 		
   230 		if (count($has[$keys[0]]) >= 2) { /*one from class others from functions.php or elsewhere*/
   721 		if (count($has[$keys[0]]) >= 2) { /*one from class others from functions.php or elsewhere*/
   231 			return true;
   722 			return true;
   232 		} else {
   723 		} else {
   233 			return false;
   724 			return false;
   234 		} 	
   725 		} 	
   235 	}	
   726 	}
   236 
   727 	
   237 	function myplugin_add_custom_box() {		
   728 	/**
   238  		add_meta_box('xilil-2', __("Page's language",'xili-language'), array(&$this,'xili_language_checkboxes_n'), 'page', 'side','high');
   729 	 *
   239  		add_meta_box('xilil-2', __("Post's language",'xili-language'), array(&$this,'xili_language_checkboxes_n'), 'post', 'side','high');
   730 	 *
   240  		if ($this->is_metabox) {
   731 	 */
   241  			add_meta_box('xilil-1', __('Linked posts','xili-language'), array(&$this,'xili_language_linked_posts'), 'post', 'side','high');
   732 	function get_post_language ( $post_ID, $result = 'slug' ) {
   242  			add_meta_box('xilil-1', __('Linked pages','xili-language'), array(&$this,'xili_language_linked_posts'), 'page', 'side','high');
   733 		$ress = wp_get_object_terms($post_ID, TAXONAME);
   243  		}
   734 		if ( $ress ) {
       
   735 			$obj_term = $ress[0]; // today only one language per post
       
   736 			
       
   737 			switch ( $result ) {
       
   738 				case 'iso':
       
   739 					$postlang = ('' != $obj_term->name) ? $obj_term->name : ""; 
       
   740 					break;
       
   741 				case 'name':
       
   742 					$postlang = ('' != $obj_term->description) ? $obj_term->description : ""; 
       
   743 					break;
       
   744 				default: // slug 
       
   745 					$postlang = ('' != $obj_term->slug) ? $obj_term->slug : ""; 
       
   746 			}
       
   747 		} else {
       
   748 			$postlang = "";
       
   749 		}
       
   750 		return $postlang;
       
   751 	}
       
   752 	
       
   753 	
       
   754 	
       
   755 	
       
   756 	/**
       
   757 	 * Create a linked copy of current post in target language
       
   758 	 *
       
   759 	 * @since 2.5
       
   760 	 *
       
   761 	 */
       
   762 	function create_initial_translation ( $target_lang, $from_post_title = "" , $frompostlang = "", $from_post_ID ) {
       
   763 		global $user_ID;
       
   764 		
       
   765 		$post_title_prefix = sprintf ( __('Please translate in %s:', 'xili-language' ), $target_lang );
       
   766 		$target_post_title = ( $from_post_title == '' ) ? $post_title_prefix . ' ' . $from_post_ID : $post_title_prefix . ' ' . $from_post_title ;
       
   767 		
       
   768 		$post_type = get_post_type( $from_post_ID );
       
   769 		
       
   770 		$params = array('post_status' => 'draft', 'post_type' => $post_type, 'post_author' => $user_ID,
       
   771 			'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
       
   772 			'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',
       
   773 			'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0,
       
   774 			'post_content' => $target_post_title, 'post_title' => $target_post_title);
       
   775 		
       
   776 		$post_ID = wp_insert_post( $params ) ;
       
   777 		
       
   778 		if ( $post_ID != 0 ) {
       
   779 			// taxonomy
       
   780 			wp_set_object_terms( $post_ID, $target_lang, TAXONAME );
       
   781 			// metas
       
   782 			// from
       
   783 			update_post_meta( $from_post_ID, QUETAG.'-'.$target_lang, $post_ID );
       
   784 			
       
   785 			// this with other target of from
       
   786 			$listlanguages = $this->get_listlanguages () ;
       
   787 			foreach ( $listlanguages as $language ) {
       
   788 				if ( $language->slug != $target_lang && $language->slug != $frompostlang ) {
       
   789 					$id = get_post_meta( $from_post_ID, QUETAG.'-'.$language->slug, true );
       
   790 					if ( $id != "" ) {
       
   791 						update_post_meta( $post_ID, QUETAG.'-'.$language->slug, $id );
       
   792 					}
       
   793 				}
       
   794 			}
       
   795 			// this
       
   796 			update_post_meta( $post_ID, QUETAG.'-'.$frompostlang, $from_post_ID );
       
   797 			update_post_meta( $post_ID, $this->translation_state, "initial" ); // to update further slug - post_name
       
   798 			
       
   799 			// categories of from_post
       
   800 			$this->propagate_categories ( $from_post_ID, $post_ID );
       
   801 			return $post_ID;
       
   802 		}
       
   803 	}
       
   804 	
       
   805 	/**
       
   806 	 * propagate categories from a reference post to another (loop is in class admin)
       
   807 	 * if cat is not in target, cat will be unassigned in target if mode is 'erase'
       
   808 	 *
       
   809 	 * @since 2.6 
       
   810 	 *
       
   811 	 */
       
   812 	function propagate_categories ( $from_post_ID, $post_ID, $mode = '' ) {
       
   813 		// categories of from_post
       
   814 		// get
       
   815 		$categories = get_the_category( $from_post_ID );
       
   816 		if ( ! empty( $categories ) ) {
       
   817 			if ( is_object_in_taxonomy( get_post_type( $from_post_ID ), 'category' ) ) {
       
   818 				// set
       
   819 				$the_cats = array();
       
   820 				foreach ( $categories as $category ) { 
       
   821 					$the_cats[] = $category->slug; // wp_set_object_terms don't like loop
       
   822 				}
       
   823 				// prepare target (erase all)
       
   824 				if ( $mode == 'erase' ) wp_delete_object_term_relationships ( $post_ID, 'category' );
       
   825 				wp_set_object_terms( $post_ID, $the_cats, 'category' );	
       
   826 			}
       
   827 		}
       
   828 	} 
       
   829 	 
       
   830 	
       
   831 	/**
       
   832 	 * return post object
       
   833 	 *
       
   834 	 * @since 2.5
       
   835 	 *
       
   836 	 */
       
   837 	function temp_get_post ( $post_id ) {
       
   838 		global $wpdb ;
       
   839 		$res = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id)); 
       
   840 		if ( $res && !is_wp_error($res) ) 
       
   841 			return $res;
       
   842 		else
       
   843 			return false;		
       
   844 	}
       
   845 	
       
   846 	/**
       
   847 	 * return saved list of post_type and custom_post_type
       
   848 	 *
       
   849 	 * @since 2.5
       
   850 	 *
       
   851 	 */
       
   852 	function authorized_custom_post_type () {
       
   853 	
       
   854 		$custompoststype = $this->xili_settings['multilingual_custom_post'] ;
       
   855 		$custom = get_post_type_object ('post');
       
   856 		$clabels = $custom->labels;
       
   857 		$custompoststype['post'] = array( 'name' => $custom->label , 'singular_name' => $clabels->singular_name , 'multilingual' => 'enable');
       
   858 		$custom = get_post_type_object ('page');
       
   859 		$clabels = $custom->labels;
       
   860 		$custompoststype['page'] = array( 'name' => $custom->label, 'singular_name' => $clabels->singular_name , 'multilingual' => 'enable');
       
   861 		return $custompoststype;
   244 	}
   862 	}
   245 	
   863 	
   246 	/**
   864 	/**
   247 	 * Will update term count based on posts AND pages.
   865 	 * Will update term count based on posts AND pages.
   248 	 *  
   866 	 *  
   259 			$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
   877 			$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
   260 		}
   878 		}
   261 	}
   879 	}
   262 	
   880 	
   263 	/**
   881 	/**
   264 	 * set language when post or page is saved or changed 
       
   265 	 *
       
   266 	 * @since 0.9.0
       
   267 	 * @completed 0.9.7.1 to record postmeta of linked posts in other languages
       
   268 	 * @updated 0.9.7.5 to delete relationship when undefined
       
   269 	 * @updated 0.9.9 to avoid delete relationship when in quick_edit
       
   270 	 * @updated 1.3.0 to avoid delete relationship when trashing - 1.4.1 - create post-meta xl-search-linked
       
   271 	 * @param $post_ID
       
   272 	 */
       
   273 	function xili_language_add($post_ID) {
       
   274 		if (!isset($_POST['_inline_edit'])) { /* to avoid delete relationship when in quick_edit (edit.php) */
       
   275 			$sellang = $_POST['xili_language_set'];
       
   276 			if ("" != $sellang) {
       
   277 				wp_set_object_terms($post_ID, $sellang, TAXONAME);
       
   278 			} else {
       
   279 				if ($_GET['action'] != 'trash' && $_GET['action'] != 'untrash')
       
   280 						wp_delete_object_term_relationships( $post_ID, TAXONAME ); 	
       
   281 			}
       
   282 			if ($this->is_metabox) {	
       
   283 				/* the linked posts set by author */	
       
   284 				$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
       
   285 				foreach ($listlanguages as $language) {
       
   286 					$inputid = 'xili_language_'.QUETAG.'-'.$language->slug ;
       
   287 					$recinputid = 'xili_language_rec_'.QUETAG.'-'.$language->slug ;
       
   288 					$linkid = $_POST[$inputid];
       
   289 					$reclinkid = $_POST[$recinputid]; /* hidden previous value */
       
   290 					$langslug = QUETAG.'-'.$language->slug ;
       
   291 					
       
   292 					if ($reclinkid != $linkid) { /* only if changed value or created since 1.3.0 */			
       
   293 						if ((is_numeric($linkid) && $linkid == 0) || '' == $linkid ) {
       
   294 							delete_post_meta($post_ID, $langslug);
       
   295 						} elseif (is_numeric($linkid) && $linkid > 0) {
       
   296 							update_post_meta($post_ID, $langslug, $linkid);
       
   297 							if ($reclinkid == "-1")	update_post_meta($linkid, QUETAG.'-'.$sellang, $post_ID); 
       
   298 						}
       
   299 					}	
       
   300 				}
       
   301 				//if (isset($_POST['xili_language_search_lang'])) {
       
   302 					if ('' != $_POST['xili_language_search_lang']) {
       
   303 						update_post_meta($post_ID, '_xl-search-linked', $_POST['xili_language_search_lang']);
       
   304 					} else {
       
   305 						if ($_GET['action'] != 'trash' && $_GET['action'] != 'untrash')
       
   306 												delete_post_meta($post_ID, '_xl-search-linked');
       
   307 					}
       
   308 				//}	
       
   309 				
       
   310 			}
       
   311 		} /* quick edit */		
       
   312 	}
       
   313 	
       
   314 	/**
       
   315 	 * Return language dir
   882 	 * Return language dir
   316 	 *
   883 	 *
   317 	 * @since 0.9.9
   884 	 * @since 0.9.9
   318 	 * @param slug of lang
   885 	 * @param slug of lang
   319 	 */
   886 	 */
   320 	function get_dir_of_cur_language($lang_slug) {
   887 	function get_dir_of_cur_language( $lang_slug ) {
   321 		$rtlarray = explode ('-',$this->rtllanglist);			
   888 		$rtlarray = explode ('-',$this->rtllanglist);			
   322 		$dir = (in_array(substr(strtolower($lang_slug),0,2),$rtlarray)) ? 'rtl' : 'ltr';
   889 		$dir = ( in_array(substr(strtolower($lang_slug), 0, 2 ),$rtlarray) ) ? 'rtl' : 'ltr';
   323 		return $dir;
   890 		return $dir;
   324 	}
   891 	}
       
   892 	
       
   893 	/**
       
   894 	 * Insert rtl.css if exists (default filter of wp_head) - see theme.php (Thanks Sam R.) 
       
   895 	 *
       
   896 	 * @since 2.4.0
       
   897 	 */
       
   898 	function change_locale_stylesheet_uri ( $stylesheet_uri,  $stylesheet_dir_uri ) { 
       
   899 		$rtlarray = explode ('-', $this->rtllanglist);
       
   900 		$dir = ( in_array( substr( strtolower( $this->curlang ), 0, 2 ), $rtlarray ) ) ? 'rtl' : 'ltr';
       
   901 		$dircss = get_stylesheet_directory();
       
   902 		// avoid with locale.css
       
   903 		if ( $stylesheet_uri == '' || false !== strpos($stylesheet_uri, 'rtl.css'  ) || false !== strpos($stylesheet_uri, 'ltr.css'  ) ) {
       
   904 			if ( in_array ( substr( $this->curlang, 0, 2 ) , $rtlarray ) ) {
       
   905 				
       
   906 				if ( file_exists("$dircss/{$dir}.css") ) { 
       
   907 					return $stylesheet_dir_uri."/{$dir}.css";
       
   908 				} else {
       
   909 					return '';
       
   910 				}
       
   911 				
       
   912 			}	
       
   913 		}
       
   914 		return $stylesheet_uri ; // non filtered value
       
   915 	}
       
   916 	
   325 	
   917 	
   326 	/**
   918 	/**
   327 	 * Return language of post.
   919 	 * Return language of post.
   328 	 *
   920 	 *
   329 	 * @since 0.9.0
   921 	 * @since 0.9.0
   330 	 * @updated 0.9.7.6, 0.9.9
   922 	 * @updated 0.9.7.6, 0.9.9
   331 	 *
   923 	 *
   332 	 * @param $post_ID.
   924 	 * @param $post_ID.
   333 	 * @return slug of language of post or false if var langstate is false.
   925 	 * @return slug of language of post or false if var langstate is false.
   334 	 */
   926 	 */
   335 	function get_cur_language($post_ID) {
   927 	function get_cur_language( $post_ID ) {
   336 		$ress = wp_get_object_terms($post_ID, TAXONAME);
   928 		$ress = wp_get_object_terms($post_ID, TAXONAME);
   337 		if ($ress) {
   929 		if ($ress) {
   338 			if (is_a($ress, 'WP_Error')){
   930 			if (is_a($ress, 'WP_Error')){
   339 				echo "Language table not created ! see plug-in admin";
   931 				echo "Language table not created ! see plug-in admin";
   340 				$this->langstate = false;
   932 				$this->langstate = false;
   341 			} else {
   933 			} else {
   342 				$obj_term = $ress[0];
   934 				$obj_term = $ress[0];
   343 				$this->langstate = true;
   935 				$this->langstate = true;
   344 				$postlang = $obj_term->slug;
   936 				$postlang = $obj_term->slug;
   345 				$postlangdir = $this->get_dir_of_cur_language($postlang);
   937 				$postlangdir = $this->get_dir_of_cur_language($postlang);
   346 				return array('lang'=>$postlang,'direction'=>$postlangdir);
   938 				return array( QUETAG => $postlang, 'direction' => $postlangdir);
   347 			}
   939 			}
   348 	 	} else {
   940 	 	} else {
   349 	 		$this->langstate = false; /* can be used in language attributes for header */
   941 	 		$this->langstate = false; /* can be used in language attributes for header */
   350 	  		return false;	/* undefined state */
   942 	  		return false;	/* undefined state */
   351 	 	}		
   943 	 	}		
   352 	}
   944 	}
   353 		
   945 		
   354 	/* first activation of plugin */
   946 	/** enable the new query tag associated with new taxonomy */
   355 	function xili_language_activate() {
   947 	function keywords_addQueryVar( $vars ) {
   356 		$this->xili_settings = get_option('xili_language_settings');
       
   357 		if(empty($this->xili_settings)) {
       
   358 			$this->xili_settings = array(
       
   359 			    'taxonomy'		=> 'language',
       
   360 			    'version' 		=> '0.4',
       
   361 			    'reqtag'		=> 'lang',
       
   362 			    'browseroption' => '',
       
   363 			    'authorbrowseroption' => '',
       
   364 			    'taxolangsgroup' => 'languages_group',
       
   365 			    'functions_enable' => '',
       
   366 			    'langs_folder' => '',
       
   367 			    'theme_domain' => '',
       
   368 			    'homelang' => '' 
       
   369 		    );
       
   370 		    update_option('xili_language_settings', $this->xili_settings);
       
   371 		}
       
   372 	}
       
   373 	
       
   374 	/*enable the new query tag associated with new taxonomy*/
       
   375 	function keywords_addQueryVar($vars) {
       
   376 		$vars[] = QUETAG;
   948 		$vars[] = QUETAG;
   377 	return $vars ;
   949 	return $vars ;
   378 	}
   950 	}
   379 
   951 
   380 	function get_default_slug() {
   952 	function get_default_slug() {
   381 		$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
   953 		$listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); 
   382 		$default_slug = 'en_us';
   954 		$default_slug = 'en_us';
   383 		foreach ($listlanguages as $language) {
   955 		foreach ($listlanguages as $language) {
   384 			if ($language->name == $this->default_lang ) return $language->slug;
   956 			if ($language->name == $this->default_lang ) return $language->slug;
   385 		}
   957 		}
   386 		return $default_slug ;
   958 		return $default_slug ;
   387 	}
   959 	}
   388 	
   960 	
   389 	/** 
   961 	/** 
   390 	 * filters used when querytag is used - 
   962 	 * Query join filter used when querytag is used or home 
   391 	 * see below and functions.php where rules depend from theme
   963 	 *  
   392 	 */
   964 	 * @updated 1.7.0 modify page on front and home query
   393 	function with_lang($join) {
   965 	 * @updated 1.8.4 * to select posts with undefined lang
   394 		global $wp_query, $wpdb;	
   966 	 * @updated 2.2.3 LANG_UNDEF = . and no * 
   395 		if ( '' != $wp_query->query_vars[QUETAG] ) {
   967 	 *
   396 			$join .= " LEFT JOIN $wpdb->term_relationships as tr ON ($wpdb->posts.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) ";
   968 	 */
   397 		}
   969 	function posts_join_with_lang( $join, $query_object = null ) {
   398 	
   970 		global $wpdb, $wp_query;
   399 	return $join;
   971 		
   400 	}
   972 		
   401 	
   973 		$insert_join = false ;	
   402 	/**
   974 		if ( isset ( $query_object->query_vars[QUETAG] ) && '' != $query_object->query_vars[QUETAG] ) {
   403 	 * Setup global post data.
   975 			if ( ( isset ( $query_object->query_vars['caller_get_posts'] ) && $query_object->query_vars['caller_get_posts']) || ( isset ( $query_object->query_vars['ignore_sticky_posts'] ) && $query_object->query_vars['ignore_sticky_posts']) ) {
       
   976 				if ( isset ( $query_object->query_vars['xlrp'] ) && $query_object->query_vars['xlrp'] == 1 ) $insert_join = true ; // called by xili recent posts
       
   977 			} else {
       
   978 				$a = $query_object->query_vars['page_id']; 
       
   979 				$b = get_option('page_on_front'); 
       
   980 				
       
   981 				if ( !($query_object->is_home && $this->show_page_on_front ) ) { // join if no front-page and other page
       
   982 					if ( $a == $b && $a !='' ) { 
       
   983 						// 1.8.1 - two pages in results when language is selected at front !!
       
   984 						// 1.8.4 - home as home + lang
       
   985 						$insert_join = false ;
       
   986 					} else {
       
   987 						
       
   988 						$insert_join = true ; // as in cat or home+lang
       
   989 					}	
       
   990 				} elseif ( $query_object->is_home && !$this->show_page_on_front ) { // home and lang 
       
   991 					$insert_join = true ;
       
   992 				} else {
       
   993 					$insert_join = true ;
       
   994 				}
       
   995 				
       
   996 				if ( $this->lang_perma ) {  
       
   997 					
       
   998 					if ( $query_object->query_vars['category_name'] == ""  && isset( $query_object->query_vars[QUETAG])  && $this->show_page_on_front && !is_admin()) {
       
   999 						$join = '';
       
  1000 						$insert_join = false ;
       
  1001 						unset($wp_query->queried_object); // to avoid notice in get_page_template and force get_queried_object -2.3.2
       
  1002 					}
       
  1003 					if ( $query_object->is_tax &&  $query_object->query_vars['category_name'] != '' ) $insert_join = true ;
       
  1004 				}
       
  1005 			}
       
  1006 			 
       
  1007 		} else { // join if home and modify home according rule ignore_sticky_posts
       
  1008 			
       
  1009 			if ( ''== $this->sublang ) { 
       
  1010 				if ( ( isset ( $query_object->query_vars['caller_get_posts'] ) && $query_object->query_vars['caller_get_posts']) || ( isset ( $query_object->query_vars['ignore_sticky_posts'] ) && $query_object->query_vars['ignore_sticky_posts']) ) {
       
  1011 					if ( isset( $query_object->query_vars['xlrp'] ) && $query_object->query_vars['xlrp'] == 1 ) $insert_join = true ; // called by xili recent posts
       
  1012 					
       
  1013 				} else { 
       
  1014 					if ( ( $query_object->is_home && $this->xili_settings['homelang'] == 'modify') || $query_object->query_vars['ignore_sticky_posts']) {
       
  1015 						
       
  1016 							$insert_join = true ; //error_log ('************ join ************' . serialize ( $query_object->query_vars['post_type']));
       
  1017 						
       
  1018 					}
       
  1019 				}
       
  1020 			}
       
  1021 		}
       
  1022 		
       
  1023 		
       
  1024 		if ( $insert_join ) {  
       
  1025 			$join .= " LEFT JOIN $wpdb->term_relationships as xtr ON ($wpdb->posts.ID = xtr.object_id) LEFT JOIN $wpdb->term_taxonomy as xtt ON (xtr.term_taxonomy_id = xtt.term_taxonomy_id) ";
       
  1026 		}	
       
  1027 		return $join;
       
  1028 	}
       
  1029 	/**
       
  1030 	 * to detect undefined query and unset language tax query
       
  1031 	 * @since 2.2.3 - LANG_UNDEF
       
  1032 	 *
       
  1033 	 */
       
  1034 	
       
  1035 	function posts_search_filter ( $search, $the_query) {
       
  1036 		$this->sublang = "";
       
  1037 		
       
  1038 		if ( isset( $the_query->query_vars[QUETAG] ) && false !== strpos( $the_query->query_vars[QUETAG] , LANG_UNDEF ) ) {
       
  1039 			
       
  1040 			
       
  1041 			if ( array() != $the_query->tax_query->queries ) {
       
  1042 				$new_queries = array();
       
  1043 				foreach ( $the_query->tax_query->queries as $query ) {
       
  1044 					if ( $query['taxonomy'] != TAXONAME ) {
       
  1045 						$new_queries[] = $query ;
       
  1046 					}
       
  1047 				}
       
  1048 				$the_query->tax_query->queries = $new_queries; 
       
  1049 			}
       
  1050 			$this->sublang = $the_query->query_vars[QUETAG]; // to adapt in where filter below
       
  1051 			unset ( $the_query->query_vars[QUETAG] );
       
  1052 			unset ( $the_query->tax_query->relation );
       
  1053 			if ( array() == $the_query->tax_query->queries ) {
       
  1054 				$the_query->is_tax = false ;
       
  1055 			}
       
  1056 		}
       
  1057 		return $search;
       
  1058 	}
       
  1059 	
       
  1060 	
       
  1061 	/**
       
  1062 	 * Modify the query including lang or home
   404 	 *
  1063 	 *
   405 	 * @since 0.9.0
  1064 	 * @since 0.9.0
   406 	 * @updated 0.9.4 (OR added) lang=xx_xx,yy_yy,..
  1065 	 * @updated 0.9.4 (OR added) lang=xx_xx,yy_yy,..
       
  1066 	 * @updated 1.7.0 modify page on front and home query 
       
  1067 	 * @updated 2.2.3 LANG_UNDEF
   407 	 *
  1068 	 *
   408 	 * @param object $where.
  1069 	 * @param object $where.
   409 	 * @return $where.
  1070 	 * @return $where.
   410 	 */
  1071 	 */
   411 	function where_lang($where) {
  1072 	function posts_where_lang( $where, $query_object = null ) {
   412 		global $wp_query , $wpdb;
  1073 		global $wpdb, $wp_query;
   413 		$reqtags = array();
  1074 		$reqtags = array();
   414 		$thereqtags = array();
  1075 		$thereqtags = array();
   415 		if ( '' != $wp_query->query_vars[QUETAG] ) {
  1076 		
   416 		/* one or more lang - no + because only one lang per post now */
  1077 		
   417 			if ( strpos($wp_query->query_vars[QUETAG], ',') !== false ) {
  1078 		if ( "" != $this->sublang )  { // see above
   418 				$langs = preg_split('/[,\s]+/', $wp_query->query_vars[QUETAG]);
  1079 		    
   419 				foreach ( (array) $langs as $lang ) {
  1080 		    $lang =  str_replace ( LANG_UNDEF, '' , $this->sublang ); //$query_object->query_vars[QUETAG] ) ;
   420 					$lang = sanitize_term_field('slug', $lang, 0, 'post_tag', 'db');
  1081 		    if ( "" == $lang ) {
   421 					$reqtags[]= $lang;
  1082 				$lang_string = implode( ", ", $this->available_langs );
       
  1083 		    } else {
       
  1084 		    	$id = $this->langs_ids_array[ $lang ];
       
  1085 		    	$remain = array_diff( $this->available_langs, array($id)); 
       
  1086 		    	$lang_string = implode( ", ", $remain  );
       
  1087 		    }	
       
  1088 		
       
  1089 			$where .= " AND $wpdb->posts.ID NOT IN ( SELECT xtr.object_id FROM $wpdb->term_relationships AS xtr INNER JOIN $wpdb->term_taxonomy AS xtt ON xtr.term_taxonomy_id = xtt.term_taxonomy_id WHERE xtt.taxonomy = '".TAXONAME."' AND xtt.term_id IN ($lang_string) )";
       
  1090 		
       
  1091 		} elseif ( isset ($query_object->query_vars[QUETAG]) && '' != $query_object->query_vars[QUETAG] ) {
       
  1092 			
       
  1093 			$do_it = false;
       
  1094 			if ( (isset ( $query_object->query_vars['caller_get_posts'] ) && $query_object->query_vars['caller_get_posts']) || ( isset ( $query_object->query_vars['ignore_sticky_posts'] ) && $query_object->query_vars['ignore_sticky_posts']) ) { 
       
  1095 				
       
  1096 				if ( isset ( $query_object->query_vars['xlrp'] ) && $query_object->query_vars['xlrp'] == 1) $do_it = true;
       
  1097 				
       
  1098 			} else {
       
  1099 				
       
  1100 				if ( $this->lang_perma && !is_admin ()) { 
       
  1101 					if ( $query_object->is_page && isset( $query_object->query_vars[QUETAG]) ) {
       
  1102 						$do_it == false;  
       
  1103 					} elseif (!($query_object->is_home && $this->show_page_on_front )) {
       
  1104 						
       
  1105 						$do_it = true; 
       
  1106 					}
       
  1107 					if ( $query_object->is_tax &&  $query_object->query_vars['taxonomy'] == 'category' ) {
       
  1108 						$do_it = true;
       
  1109 					}
       
  1110 					if ( $query_object->is_tax &&  $query_object->query_vars['taxonomy'] == TAXONAME && "" == $query_object->query_vars['category_name'] ) {
       
  1111 						$do_it = false;
       
  1112 						if ( !$query_object->is_page ) {
       
  1113 							$where .= " AND $wpdb->posts.post_type = 'post'";
       
  1114 						}	
       
  1115 					} 
       
  1116 				} else {
       
  1117 				    if ( !( $query_object->is_home && $this->show_page_on_front ) ) { 
       
  1118 						$do_it = true; // all but not home	
       
  1119 					}
       
  1120 				}
       
  1121 			}
       
  1122 			
       
  1123 			
       
  1124 			if ($do_it) { // insertion of selection
       
  1125 				
       
  1126 				if ( strpos($query_object->query_vars[QUETAG], ',') !== false ) {
       
  1127 					$langs = preg_split('/[,\s]+/', $query_object->query_vars[QUETAG]);
       
  1128 					foreach ( (array) $langs as $lang ) {
       
  1129 						$lang = sanitize_term_field('slug', $lang, 0, 'post_tag', 'db');
       
  1130 						$reqtags[]= $lang;
       
  1131 					}
       
  1132 					foreach ($reqtags as $reqtag){
       
  1133 						$thereqtagids[] = $this->langs_ids_array[$reqtag];
       
  1134 					}
       
  1135 					$wherereqtag = implode(", ", $thereqtagids); 
       
  1136 					$where .= " AND xtt.taxonomy = '".TAXONAME."' ";
       
  1137 					$where .= " AND xtt.term_id IN ( $wherereqtag )";
       
  1138 				 
       
  1139 				} else {  
       
  1140 				/* only one lang */
       
  1141 					$query_object->query_vars[QUETAG] = sanitize_term_field('slug', $query_object->query_vars[QUETAG], 0, 'post_tag', 'db');
       
  1142 					$reqtag = $query_object->query_vars[QUETAG];
       
  1143 										
       
  1144 					$wherereqtag = $this->langs_ids_array[$reqtag];
       
  1145 					$where .= " AND xtt.taxonomy = '".TAXONAME."' ";
       
  1146 					$where .= " AND xtt.term_id = $wherereqtag ";
       
  1147 				 }
       
  1148 				 	 
       
  1149 			} else { // is_home and page
       
  1150 			
       
  1151 				if ( $query_object->is_home && $this->show_page_on_front ) {  
       
  1152 					$query_object->is_home = false ; // renew the values because the query contains lang=
       
  1153 					$query_object->is_page = true ;
       
  1154 					$query_object->is_singular = true ;
       
  1155 					$query_object->query = array();
       
  1156 					$query_object->query_vars['page_id'] = get_option('page_on_front'); // new filtered value 
       
  1157 					//$query_object->query_vars['p'] = $query_object->query_vars['page_id'];
       
  1158 					
       
  1159 					$where = str_replace ("'post'","'page'",$where); // post_type = 
       
  1160 					$where .= " AND 3=3 AND {$wpdb->posts}.ID = " . $query_object->query_vars['page_id'];
       
  1161 					
   422 				}
  1162 				}
   423 				
  1163 				
   424 				foreach ($reqtags as $reqtag){
  1164 				if ( $this->lang_perma && $this->show_page_on_front) { // 2.1.1 
   425 					$reqtagt = is_term( $reqtag, TAXONAME );
  1165 					if ( $query_object->query_vars[QUETAG] != "" && $query_object->query_vars['taxonomy'] == TAXONAME  ) {
   426 					if ($reqtagt)
  1166 						$query_object->is_page = true ;
   427 						$thereqtags[] = $reqtagt['term_id']; 
  1167 						$query_object->is_tax = false ; 
       
  1168 						$query_object->is_archive = false ;
       
  1169 						$query_object->is_singular = true ;
       
  1170 						
       
  1171 						$query_object->query = array();
       
  1172 						$pid = $this->get_option_wo_xili ('page_on_front') ; 
       
  1173 						$lang = ( isset ( $query_object->query_vars[QUETAG] ) ? $query_object->query_vars[QUETAG] : 'en_us' );
       
  1174 						$id = get_post_meta ( $pid, QUETAG.'-'.$lang, true );
       
  1175 						$pagid = ( ''!= $id ) ? $id : $pid ; 
       
  1176 						$query_object->query_vars['page_id'] = $pagid ;
       
  1177 						
       
  1178 						unset ( $query_object->query_vars['taxonomy'] );
       
  1179 						
       
  1180 						$where = str_replace ("'post'","'page'",$where); // post_type = 
       
  1181 						$where = "AND {$pagid} = {$pagid} "." AND {$wpdb->posts}.ID = " . $query_object->query_vars['page_id'] . " AND {$wpdb->posts}.post_type = 'page'";
       
  1182 						 
       
  1183 						$query_object->query_vars['page_id'] = get_option ('page_on_front') ;
       
  1184 						//$query_object->query_vars['p'] = $query_object->query_vars['page_id'];
       
  1185 						
       
  1186 						unset($wp_query->queried_object);
       
  1187 						$wp_query->queried_object_id = $query_object->query_vars['page_id'];
       
  1188 						$wp_query->queried_object->ID = $query_object->query_vars['page_id']; 
       
  1189 						//$this->first_change = $lang ;
       
  1190 						//update_option('xili_language_settings_test', $this->first_change);
       
  1191 					}
   428 				}
  1192 				}
       
  1193 			}
       
  1194 		
       
  1195 					
       
  1196 		} else { // no query tag 
       
  1197 			//error_log ( "****** join ******" );
       
  1198 			if ( ( isset ( $query_object->query_vars['caller_get_posts'] ) && $query_object->query_vars['caller_get_posts']) || ( isset ( $query_object->query_vars['ignore_sticky_posts'] ) && $query_object->query_vars['ignore_sticky_posts']) ) { 
   429 				
  1199 				
   430 				$wherereqtag = implode(", ", $thereqtags);
  1200 				if ( isset($query_object->query_vars['xlrp']) && $query_object->query_vars['xlrp'] == 1) {
   431 				$where .= " AND tt.taxonomy = '".TAXONAME."' ";
  1201 					$reqtag = $query_object->query_vars[QUETAG];
   432 				$where .= " AND tt.term_id IN ( $wherereqtag )";
  1202 										
   433 			
  1203 					$wherereqtag = $this->langs_ids_array[$reqtag];
       
  1204 					$where .= " AND xtt.taxonomy = '".TAXONAME."' ";
       
  1205 					$where .= " AND xtt.term_id = $wherereqtag ";
       
  1206 					
       
  1207 				}
       
  1208 			} else {	 //error_log ( "****** ici ******" . serialize ( $query_object->query_vars['post_type']) );
       
  1209 				if (  $query_object->is_home && !$this->show_page_on_front && $this->xili_settings['homelang'] == 'modify' )  {
       
  1210 					
       
  1211 						// force change if loop
       
  1212 						$curlang = $this->choice_of_browsing_language();
       
  1213 				
       
  1214 						$wherereqtag = $this->langs_ids_array[$curlang];
       
  1215 						$where .= " AND xtt.taxonomy = '".TAXONAME."' ";
       
  1216 						$where .= " AND xtt.term_id = $wherereqtag ";	
       
  1217 					
       
  1218 				} 
       
  1219 			}
       
  1220 		}
       
  1221 		//error_log ( "****** join ******".$where );
       
  1222 		return $where; 
       
  1223 	}
       
  1224 
       
  1225 	/******** template theme live modifications ********/
       
  1226 	
       
  1227 	/**
       
  1228 	 * wp action for theme at end of query  
       
  1229 	 *
       
  1230 	 * @since 0.9.0
       
  1231 	 * @updated 1.1.9, 1.4.2a
       
  1232 	 * call by wp hook	   
       
  1233 	 *   
       
  1234 	 */
       
  1235 	function xiliml_language_wp() {
       
  1236 		if ( !is_admin() ) {
       
  1237 			$this->curlang = $this->get_curlang_action_wp(); // see hooks in that function 
       
  1238 			//$this->curlang = 'en_us';
       
  1239 			
       
  1240 			$this->curlang_dir = $this->get_dir_of_cur_language( $this->curlang ); /* general dir of the theme */
       
  1241 			if ( $this->locale_method ) {
       
  1242 				$this->xiliml_load_theme_textdomain ( $this->thetextdomain ); /* new method for cache compatibility - tests */
   434 			} else {
  1243 			} else {
   435 			/* only one lang */
  1244 				$this->set_mofile( $this->curlang );
   436 				$wp_query->query_vars[QUETAG] = sanitize_term_field('slug', $wp_query->query_vars[QUETAG], 0, 'post_tag', 'db');
  1245 			}
   437 				$reqtag = $wp_query->query_vars[QUETAG];
  1246 		}
   438 				$reqtag = is_term( $reqtag, TAXONAME );
  1247 	}
   439 				if (''!= $reqtag) {
  1248 	
   440 					$wherereqtag = $reqtag['term_id'];
  1249 	
   441 				} else {
  1250 	
   442 					$wherereqtag = 0;	
  1251 	/**
   443 				}
  1252 	 * wp action to switch wp_locale only on front-end
   444 				$where .= " AND tt.taxonomy = '".TAXONAME."' ";
  1253 	 *
   445 				$where .= " AND tt.term_id = $wherereqtag ";
  1254 	 * @since 2.4.0
   446 			}
  1255 	 * 
   447 					
  1256 	 * call by wp hook after theme cur_lang set	   
   448 		}	
       
   449 		return $where;
       
   450 	}
       
   451 
       
   452 	/******** template theme live modifications ********/
       
   453 	
       
   454 	/**
       
   455 	 * wp action for theme at end of query  
       
   456 	 *
       
   457 	 * @since 0.9.0
       
   458 	 * @updated 1.1.9
       
   459 	 * can be hooked in functions.php xiliml_cur_lang_head
       
   460 	 * call by wp hook	 
       
   461 	 *   
  1257 	 *   
   462 	 */
  1258 	 */
   463 	function xiliml_language_wp() {
  1259 	function xili_locale_setup ( ) {
   464 		$this->curlang = $this->xiliml_cur_lang_head();
  1260 		if ( !is_admin() ) {
   465 		$this->curlang_dir = $this->get_dir_of_cur_language($this->curlang); /* general dir of the theme */
  1261 			unset($GLOBALS['wp_locale']);  
   466 		if (!defined('THEME_TEXTDOMAIN')) _e('xili-language plugin : THEME_TEXTDOMAIN UNDEFINED','xili-language'); /* here because not visible in admin UI */
  1262 			global $wp_locale;
   467 		
  1263 			$wp_locale = new xl_WP_Locale(); 
   468 		if ($this->locale_method) {
  1264 		}
   469 			$this->xiliml_load_theme_textdomain (THEME_TEXTDOMAIN); /* new method for cache compatibility - tests */
  1265 	}
   470 		} else {
  1266 	
   471 			$this->set_mofile($this->curlang);
  1267 	/**
   472 		}
  1268 	 * only called in front-end
       
  1269 	 *
       
  1270 	 * @since 2.4.0
       
  1271 	 *
       
  1272 	 */
       
  1273 	function translate_date_format ( $format ) {
       
  1274 		if ( $this->xili_settings['wp_locale'] == 'wp_locale' )
       
  1275 	 	 	return __( $format , $this->thetextdomain );
       
  1276 	 	else
       
  1277 	 		return $format;
       
  1278 	}
       
  1279 	
       
  1280 	/**
       
  1281 	 * fixes feed link if not permalinks because called after category filter
       
  1282 	 *
       
  1283 	 * @since 2.8.1
       
  1284 	 *
       
  1285 	 */
       
  1286 	function category_feed_link ( $link, $feed = '' ) {
       
  1287 		$permalink_structure = get_option( 'permalink_structure' );
       
  1288 
       
  1289 		if ( '' != $permalink_structure ) {	
       
  1290 			if ( $feed == get_default_feed() )
       
  1291 				$feed_link = 'feed';
       
  1292 			else
       
  1293 				$feed_link = "feed/$feed";
       
  1294 		// clean current link
       
  1295 			$root_link = str_replace ( user_trailingslashit( $feed_link, 'feed' ), '', $link );
       
  1296 		// get part after ?lang=
       
  1297 			$parts = explode ( '?'.QUETAG.'=', $root_link );
       
  1298 			if ( isset( $parts[1] ) ) {
       
  1299 				// recreate current link
       
  1300 				$link = trailingslashit( $parts[0] ) . user_trailingslashit( $feed_link, 'feed' ) . '?'.QUETAG.'='. str_replace ( '/','',$parts[1] );
       
  1301 			}
       
  1302 		}
       
  1303 		return $link;
       
  1304 		
       
  1305 	}
       
  1306 	
       
  1307 	/**
       
  1308 	 * 'theme_locale' filter to detect theme and don't load theme_domain in functions.php
       
  1309 	 *
       
  1310 	 * @since 1.5.0
       
  1311 	 *
       
  1312 	 * call by 'theme_locale' filter
       
  1313 	 */
       
  1314 	function xiliml_theme_locale ( $locale, $domain ) {
       
  1315 		$this->xili_settings['theme_domain'] = $domain; 
       
  1316 		$this->thetextdomain = $domain;
       
  1317 		
       
  1318 		//if ( defined ( "WP_DEBUG" ) && WP_DEBUG == true ) error_log ( $this->class_admin . ' < domain = ' . $domain ) ;
       
  1319 		 
       
  1320 		return 'wx_YZ'; // dummy local
       
  1321 	}
       
  1322 	
       
  1323 	/**
       
  1324 	 * 'override_load_textdomain' filter to avoid dummy load
       
  1325 	 *
       
  1326 	 * @since 1.5.0
       
  1327 	 * @updated 1.8.1 - 1.8.5
       
  1328 	 *
       
  1329 	 */
       
  1330 	function xiliml_override_load ( $falseval, $domain, $mofile ) { 
       
  1331 		if ( $this->show ) {
       
  1332 			if ( !in_array( $domain , $this->arraydomains ) )
       
  1333 				$this->arraydomains[] = $domain;
       
  1334 		}
       
  1335 	   	if (false === strpos ($mofile ,'wx_YZ.mo')) {//
       
  1336 	   		return false;
       
  1337 	   	} else {
       
  1338 	   		if ( str_replace( get_stylesheet_directory(), '', $mofile ) == $mofile ) { // no effect
       
  1339 	   			$this->get_template_directory = get_template_directory();
       
  1340 	   			$this->xili_settings['langs_in_root_theme'] = 'root';
       
  1341 	   		} else {
       
  1342 	   			$this->get_template_directory = get_stylesheet_directory(); // a load is in child
       
  1343 	   			$this->xili_settings['langs_in_root_theme'] = '';
       
  1344 	   			
       
  1345 	   		}
       
  1346 	   		$this->ltd = true ; 
       
  1347 	   		
       
  1348 	   		$langs_folder = str_replace('/wx_YZ.mo','',str_replace( $this->get_template_directory, '', $mofile ));
       
  1349 	   		// in wp3 the detection is only done here (end user side by theme domain) so updated is mandatory for xili-dico
       
  1350 	   		if ( $this->xili_settings['langs_folder'] != $langs_folder ) { 
       
  1351 		 		$this->xili_settings['langs_folder'] = $langs_folder ;
       
  1352 		 		update_option( 'xili_language_settings', $this->xili_settings ); 
       
  1353 		 	}
       
  1354 		 	// to restore theme mo if theme datas and terms in admin ui….
       
  1355 		 	if ( is_admin() ) load_textdomain( $domain, str_replace('wx_YZ', get_locale(), $mofile )); // 2.3.1 - 18h18
       
  1356 	   		return true;
       
  1357 	   		
       
  1358 	   	}	
       
  1359 	}
       
  1360 	
       
  1361 	/**
       
  1362 	 *
       
  1363 	 * Introduced only in visitors side (not in admin) to change domain of plugin or other
       
  1364 	 * gettext filter from function translate() in wp-includes/I10n.php
       
  1365 	 * 
       
  1366 	 * @since 1.8.7 - 1.8.8
       
  1367 	 */
       
  1368 	function change_plugin_domain ($translation, $text, $domain ) {
       
  1369 		
       
  1370 		$domain = $this->switching_domain ( $domain );
       
  1371 		
       
  1372 		$translations = &get_translations_for_domain( $domain );
       
  1373 		return $translations->translate( $text );
       
  1374 	}
       
  1375 	function change_plugin_domain_with_context ($translation, $text, $context, $domain ) {
       
  1376 		
       
  1377 		$domain = $this->switching_domain ( $domain );
       
  1378 		 
       
  1379 		$translations = &get_translations_for_domain( $domain );
       
  1380 		return $translations->translate( $text, $context );
       
  1381 	}
       
  1382 	function change_plugin_domain_plural ($translation, $single, $plural, $number, $domain ) {
       
  1383 		
       
  1384 		$domain = $this->switching_domain ( $domain );
       
  1385 		 
       
  1386 		$translations = &get_translations_for_domain( $domain );
       
  1387 		$translation = $translations->translate_plural( $single, $plural, $number );
       
  1388 		return $translation ;
       
  1389 	}
       
  1390 	function change_plugin_domain_plural_with_context ($translation, $single, $plural, $number, $context, $domain ) {
       
  1391 		
       
  1392 		$domain = $this->switching_domain ( $domain );
       
  1393 		 
       
  1394 		$translations = &get_translations_for_domain( $domain );
       
  1395 		$translation = $translations->translate_plural( $single, $plural, $number, $context );
       
  1396 		return $translation ;
       
  1397 	}
       
  1398 	
       
  1399 	/** 
       
  1400 	 * domain switching 
       
  1401 	 */
       
  1402 	function switching_domain ( $domain ) {
       
  1403 		$ok = false ;
       
  1404 		if ( $domain != $this->thetextdomain ) {
       
  1405 			if ( in_array ( $domain, array_keys( $this->xili_settings['domains'] ) ) ) {
       
  1406 				if ( $this->xili_settings['domains'][$domain] == 'enable' ) $ok = true ;
       
  1407 			} else {
       
  1408 				if ( $this->xili_settings['domains']['all'] == 'enable' ) $ok = true ;
       
  1409 			}
       
  1410 			if ( $ok ) 
       
  1411 				$domain = $this->thetextdomain ;
       
  1412 		} 
       
  1413 		return $domain;
   473 	}
  1414 	}
   474 	
  1415 	
   475 	/**
  1416 	/**
   476 	 * locale hook when load_theme_textdomain is present in functions.php
  1417 	 * locale hook when load_theme_textdomain is present in functions.php
   477 	 *
  1418 	 *
   478 	 * @since 1.1.9
  1419 	 * @since 1.1.9
   479 	 *
  1420 	 *
   480 	 * call by locale hook
  1421 	 * call by locale hook
   481 	 */
  1422 	 */
   482 	function xiliml_setlocale ($locale) {
  1423 	function xiliml_setlocale ( $locale ) {
   483 		if ($this->theme_locale === true) {
  1424 		if ($this->theme_locale === true) {
   484 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $this->curlang));
  1425 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $this->curlang));
   485 			return $listlanguages[0]->name;
  1426 			return $listlanguages[0]->name;
   486 		} else {
  1427 		} else {
   487 			return $locale; 	
  1428 			return $locale; 	
   493 	 *
  1434 	 *
   494 	 * @since 1.1.9
  1435 	 * @since 1.1.9
   495 	 *
  1436 	 *
   496 	 * call by locale hook
  1437 	 * call by locale hook
   497 	 */
  1438 	 */
   498 	function xiliml_load_theme_textdomain ($domain) {
  1439 	function xiliml_load_theme_textdomain ( $domain ) {
   499 		$this->theme_locale = true;
  1440 		$this->theme_locale = true;
   500 		$langfolder = (defined('THEME_LANGS_FOLDER')) ? THEME_LANGS_FOLDER : $this->xili_settings['langs_folder'];
  1441 		$langfolder = $this->xili_settings['langs_folder'];
   501 		$langfolder = '/'.str_replace("/","",$langfolder); /* please no lang folder in sub-subfolder */
  1442 		//$langfolder = '/'.str_replace("/","",$langfolder); /* please no lang folder in sub-subfolder */
   502 		$langfolder = ($langfolder == "/") ? "" : $langfolder;
  1443 		$langfolder = ($langfolder == "/") ? "" : $langfolder; 
   503 		load_theme_textdomain($domain, get_template_directory() . $langfolder);
  1444 		load_theme_textdomain($domain, $this->get_template_directory . $langfolder);
   504 		$this->theme_locale = false;		
  1445 		$this->theme_locale = false;		
   505 	}
  1446 	}
   506 	
  1447 	
   507 	/**
  1448 	/**
   508 	 * select .mo file 
  1449 	 * select .mo file 
   509 	 * @since 0.9.0
  1450 	 * @since 0.9.0
   510 	 * @updated 0.9.7.1 - 1.1.9
  1451 	 * @updated 0.9.7.1 - 1.1.9 - 1.5.2 wpmu - 1.8.9.1 (domain select)
   511 	 * call by function xiliml_language_wp()
  1452 	 * call by function xiliml_language_wp()
   512 	 * @param $curlang .
  1453 	 * @param $curlang .
   513 	 */
  1454 	 */
   514 	function set_mofile($curlang) {
  1455 	function set_mofile( $curlang ) {
   515 		// load_theme_textdomain(THEME_TEXTDOMAIN); - replaced to be flexible -
  1456 		// load_theme_textdomain(THEME_TEXTDOMAIN); - replaced to be flexible -
   516 		if (defined('THEME_TEXTDOMAIN')) {$themetextdomain = THEME_TEXTDOMAIN; } else {$themetextdomain = 'ttd-not-defined';  }
  1457 		if ( ""!=$this->thetextdomain ) { $themetextdomain = $this->thetextdomain; } else { $themetextdomain = 'ttd-not-defined'; }
   517 		$langfolder = (defined('THEME_LANGS_FOLDER')) ? THEME_LANGS_FOLDER : $this->xili_settings['langs_folder'];
  1458 		$langfolder = $this->xili_settings['langs_folder']; 
   518 		$langfolder = '/'.str_replace("/","",$langfolder); /* please no lang folder in sub-subfolder */
  1459 		
   519 		$langfolder = ($langfolder == "/") ? "" : $langfolder;
  1460 		$langfolder = ($langfolder == "/") ? "" : $langfolder;
   520 		$listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $curlang));
  1461 		
   521 		$filename = $listlanguages[0]->name;
  1462 		$filename = '';
   522 		$filename .= '.mo';
  1463 		if ( '' != $curlang ) {
   523 		if ('' != $filename) {
  1464 			
   524 			$mofile = get_template_directory() .$langfolder."/$filename";	
  1465 			$filename = $this->langs_slug_name_array[$curlang]; // 2.4.2
   525 			load_textdomain($themetextdomain,$mofile);
  1466 		}
   526 		}
  1467 			
   527 	}
  1468 		if ( '' != $filename ) {
   528 	
  1469 			$filename .= '.mo'; 
   529 	/**
  1470 			$mofile = $this->get_template_directory .$langfolder."/$filename";	
   530 	 * default rules - set curlang in head according rules 
  1471 			
   531 	 *
  1472 			if ( is_multisite() ) { /* completes theme's language with db structure languages (cats, desc,…) */
   532 	 * @since 0.9.7
  1473 				if ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) {
   533 	 * @updated 0.9.7.1 - if no posts 0.9.9.1 - 0.9.9.4 
  1474 					$wpmu_curdir = $uploads['basedir']."/languages";
   534 	 * @updated 1.3.2 - Option for home.php
  1475 					load_textdomain( $themetextdomain, $wpmu_curdir."/local-" . $this->langs_slug_name_array[$curlang] . ".mo" ); // here to be the last value
   535 	 * 
  1476 					load_textdomain( $themetextdomain, $wpmu_curdir."/$filename" );
   536 	 * default filter of xiliml_cur_lang_head
  1477 				}
   537 	 * @return $curlang .
  1478 			}
   538 	 */
  1479 			load_textdomain( $themetextdomain, $this->get_template_directory .$langfolder."/local-" . $this->langs_slug_name_array[$curlang] . ".mo" ); // here to be the last value
   539 	function xiliml_cur_lang_head () {
  1480 			load_textdomain( $themetextdomain, $mofile ); // moved here for merge (prior for site and not theme)
   540 		if (has_filter('xiliml_cur_lang_head')) return apply_filters('xiliml_cur_lang_head',''); /* '' warning on some server need one arg by default*/
  1481 			
       
  1482 			// 2.8.1
       
  1483 			do_action ( 'xiliml_add_frontend_mofiles' , $themetextdomain, $this->langs_slug_name_array[$curlang] ); // to add bbpress good mo
       
  1484 				
       
  1485 		}
       
  1486 	}
       
  1487 	
       
  1488 	/**
       
  1489 	 * default rules - set curlang for wp action 
       
  1490 	 *
       
  1491 	 * @since 1.7.0 - new mechanism for front-page
       
  1492 	 * @updated 1.8.9.1 - better category case
       
  1493 	 * @updated 2.2.3 - fixes rare frontpage infinite loop
       
  1494 	 * replace xiliml_cur_lang_head (0.9.7 -> 1.6.1)
       
  1495 	 * @return $curlang
       
  1496 	 */
       
  1497 	function get_curlang_action_wp () {
       
  1498 		
       
  1499 		if ( has_filter( 'xiliml_curlang_action_wp' ) ) return apply_filters( 'xiliml_curlang_action_wp', '' ); /* '' warning on some server need one arg by default*/
   541 		/* default */
  1500 		/* default */
   542 		global $post,$wp_query, $query_string;
  1501 		global $post, $wp_query ;
   543 			if (have_posts()) {
  1502 		
   544 				if(!is_front_page()) { /* every pages */
  1503 		
   545 					$curlangdir = $this->get_cur_language($post->ID);
  1504 		if ( have_posts() ) {
   546 					$curlang = $curlangdir['lang']; /* the first post give the current lang*/
  1505 			$showpage = get_option('show_on_front');
   547 					if ($curlangdir == false) $curlang = DEFAULTSLUG; /* can be changed if use hook */
  1506 			$condition = false;
   548 					if (is_page()) {
  1507 			if ( 'page' == $showpage ) {
   549 						if (isset($_GET["loclang"])) {
  1508 				if (!in_array ( $wp_query->query_vars['page_id'], $this->xili_settings['show_page_on_front_array'] ) ) $condition = true;
   550 			    			$curlang=$_GET["loclang"];
  1509 			} else {
   551 			    		/* get var to override the selected lang - ex. in bi-lingual contact*/
  1510 				if ( !is_home() ) 	$condition = true;
       
  1511 			}
       
  1512 			
       
  1513 			if ( $condition ) { /* every pages !is_front_page() */ 
       
  1514 				$curlangdir = $this->get_cur_language($post->ID); 
       
  1515 				$curlang = $curlangdir[QUETAG]; /* the first post give the current lang*/ 
       
  1516 				if ( $curlangdir == false ) $curlang = $this->choice_of_browsing_language(); //$this->default_slug; /* no more constant - wpmu - can be changed if use hook */
       
  1517 				if ( is_page() ) {
       
  1518 					if ( isset( $_GET["loclang"] ) ) {
       
  1519 		    			$curlang = $_GET["loclang"]; 
       
  1520 		    		/* get var to override the selected lang - ex. in bi-lingual contact*/ 
       
  1521 					}
       
  1522 					//
       
  1523 					if ( isset($wp_query->query_vars[QUETAG]) ) {
       
  1524 						$curlang = $wp_query->query_vars[QUETAG] ;
       
  1525 					}
       
  1526 				} elseif ( is_search() ) {
       
  1527 					if ( isset( $wp_query->query_vars[QUETAG] ) ) $curlang = $wp_query->query_vars[QUETAG] ; //
       
  1528 				} elseif ( is_category() ) {
       
  1529 					if ( $this->lang_perma ) {
       
  1530 						if ( isset( $wp_query->query_vars[QUETAG] ) ) {
       
  1531 							$curlang = str_replace ( LANG_UNDEF, "", $wp_query->query_vars[QUETAG]) ;
       
  1532 						} else {
       
  1533 							$curlang = $this->choice_of_categories_all_languages( $curlang ) ;
   552 						}
  1534 						}
   553 					} 
  1535 					} else {
   554 					elseif (is_search() && isset($_GET["lang"])) {
  1536 						if ( isset( $_GET[QUETAG] ) ) {
   555 						$curlang=$_GET["lang"]; /*useful when no result*/
  1537 							$curlang = $_GET[QUETAG] ;
       
  1538 						} else {
       
  1539 							$curlang = $this->choice_of_categories_all_languages( $curlang ) ;  //$this->choice_of_browsing_language(); // again as defined 1.8.9.1
       
  1540 						}
   556 					}
  1541 					}
   557 				} else { /* front page */
  1542 				} 
   558 					if ( '' != $wp_query->query_vars[QUETAG] ) {
  1543 			} else { /* front page - switch between lang (and post/page) is done in query posts_where_lang filter see above */
   559 						$curlang = $wp_query->query_vars[QUETAG];	/* home series type*/
  1544 				
   560 					} else {
  1545 				
   561 						$showpage = get_settings('show_on_front');
  1546 				if ( isset ( $wp_query->query_vars[QUETAG] ) && '' != $wp_query->query_vars[QUETAG] ) { 
   562 						$page_front = get_settings('page_on_front');
  1547 					$this->langstate = true; // 2.8.0 b
   563 						$hcurlang = (isset($_GET["hlang"])) ? $_GET["hlang"] : $this->choice_of_browsing_language() ; 
  1548 					$curlang = $wp_query->query_vars[QUETAG];	// home series type 
   564 						$target = get_post_meta($page_front, 'lang-'.$hcurlang, true);
  1549 				} else {
   565 						if ($showpage == "page") {
  1550 					
   566 							if ($target && $target != $post->ID) { /* only if present and diff */
  1551 					if ( 'page' == $showpage ) { //$this->show_page_on_front ) {
   567 								query_posts('page_id='.$target); 
  1552 						$page_front = get_option('page_on_front');
   568 								if (have_posts()) {
  1553 						$curlang = get_cur_language($page_front); 
   569 									the_post();
  1554 					} else { // home.php - 1.3.2 
   570 									$curlang = get_cur_language($post->ID);
  1555 						$curlang = $this->choice_of_browsing_language();
   571 									rewind_posts();
       
   572 								} else {
       
   573 									query_posts('page_id='.$page_front); /* restore */
       
   574 									$curlang = get_cur_language($page_front);
       
   575 								}
       
   576 							} else {
       
   577 								$curlang = get_cur_language($post->ID);	
       
   578 							}
       
   579 						} else { /* home.php - 1.3.2 */
       
   580 							$curlang = $this->choice_of_browsing_language();
       
   581 							if ($this->xili_settings['homelang'] == 'modify') query_posts($query_string."&lang=".$curlang);
       
   582 						}	
       
   583 					}	
  1556 					}	
   584 				}
  1557 				}
   585 			} else { /*no posts for instance in category + lang */
  1558 			}
   586 			 	if (isset($_GET["lang"])) {
  1559 		} else { /*no posts for instance in category + lang */
   587 			    		$curlang=$_GET["lang"];
  1560 		 	if ( $this->lang_perma ) {
   588 			    } else {
  1561 				if ( isset( $wp_query->query_vars[QUETAG] ) ) {
   589 			    		$curlang = $this->choice_of_browsing_language();//strtolower(WPLANG); /* select here the default language of the site */
  1562 					$curlang = $wp_query->query_vars[QUETAG] ;
   590 			   	}
  1563 				} else {
   591 			}	
  1564 					$curlang = $this->choice_of_browsing_language();
   592 			return $curlang; /* as in external hook for filter*/
  1565 				}
       
  1566 			} else {
       
  1567 				if ( isset( $_GET[QUETAG] ) ) {
       
  1568 					$curlang = $_GET[QUETAG];
       
  1569 				} else {
       
  1570 					$curlang = $this->choice_of_browsing_language() ;  //$this->choice_of_browsing_language(); // again as defined 1.8.9.1
       
  1571 				}
       
  1572 			} 	
       
  1573 		} 	
       
  1574 		
       
  1575 		
       
  1576 		return str_replace ( LANG_UNDEF  , '' , $curlang ) ; // 2.3 to return main part
   593 	}
  1577 	}
   594 	
  1578 	
   595 	/**
  1579 	/**
   596 	 * modify  language_attributes() output
  1580 	 * modify  language_attributes() output
   597 	 *
  1581 	 *
   599 	 *  
  1583 	 *  
   600 	 * The - language_attributes() -  template tag is use in header of theme file in html tag 
  1584 	 * The - language_attributes() -  template tag is use in header of theme file in html tag 
   601 	 *   
  1585 	 *   
   602 	 * @param $output
  1586 	 * @param $output
   603 	 */
  1587 	 */
   604 	function head_language_attributes($output) {
  1588 	function head_language_attributes( $output ) {
   605 		/* hook head_language_attributes */
  1589 		/* hook head_language_attributes */
   606 		if (has_filter('head_language_attributes')) return apply_filters('head_language_attributes',$output);
  1590 		
       
  1591 		if ( has_filter('head_language_attributes') ) return apply_filters('head_language_attributes',$output);
   607 		$attributes = array();
  1592 		$attributes = array();
   608 		$output = '';
  1593 		$output = '';
   609 
  1594 
   610 		if ( $dir = get_bloginfo('text_direction') ) /*use hook for future use */
  1595 		if ( $dir = get_bloginfo('text_direction') ) /*use hook for future use */
   611 			$attributes[] = "dir=\"$dir\"";
  1596 			$attributes[] = "dir=\"$dir\"";
   612 		if ($this->langstate == true) {	
  1597 		if ( $this->langstate = true ) {	
   613 			$lang = str_replace('_','-',substr($this->curlang,0,3).strtoupper(substr($this->curlang,-2)));
  1598 			if (strlen($this->curlang) == 5) {
       
  1599 				$lang = str_replace('_','-',substr( $this->curlang, 0, 3).strtoupper( substr( $this->curlang, -2))); 
       
  1600 			} else {
       
  1601 				$lang = $this->curlang; //1.5.2 for ja as commented in 200909
       
  1602 			}
   614 		} else {
  1603 		} else {
   615 			//use hook if you decide to display limited list of languages for use by instance in frontpage 
  1604 			//use hook if you decide to display limited list of languages for use by instance in frontpage 
   616 			$listlang = array();
  1605 			$listlang = array();
   617 			//$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
  1606 			
   618 			$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
  1607 			$listlanguages = $this->get_listlanguages();
   619 			foreach ($listlanguages as $language) {
  1608 			if ( $listlanguages ) {
   620 				$listlang[] = str_replace('_','-',$language->name);
  1609 				foreach ( $listlanguages as $language ) {
   621 			}	
  1610 					$listlang[] = str_replace( '_', '-', $language->name );
   622 			$lang = $listlang[0]; // implode(', ',$listlang); // not w3c compatible
  1611 				}	
   623 		}
  1612 				$lang = $listlang[0]; // implode(', ',$listlang); // not w3c compatible
   624 		if ( get_option('html_type') == 'text/html')
  1613 			}
       
  1614 		}
       
  1615 		if ( get_option('html_type') == 'text/html' )
   625 				$attributes[] = "lang=\"$lang\"";
  1616 				$attributes[] = "lang=\"$lang\"";
   626 	
  1617 	// to use both - use the hook - head_language_attributes
   627 		if ( get_option('html_type') != 'text/html')
  1618 		if ( get_option('html_type') != 'text/html' )
   628 			$attributes[] = "xml:lang=\"$lang\"";	
  1619 			$attributes[] = "xml:lang=\"$lang\"";	
   629 
  1620 
   630 		$output = implode(' ', $attributes);
  1621 		$output = implode(' ', $attributes);
       
  1622 		
   631 		return $output;
  1623 		return $output;
   632 	}
  1624 	}
   633 	
  1625 	
   634 	/**
  1626 	/**
   635 	 * modify  insert language metas in head (via wp_head)
  1627 	 * modify  insert language metas in head (via wp_head)
   638 	 * @updated 1.1.8 
  1630 	 * @updated 1.1.8 
   639 	 * @must be defined in functions.php according general theme design (wp_head) 
  1631 	 * @must be defined in functions.php according general theme design (wp_head) 
   640 	 *   
  1632 	 *   
   641 	 * @param $curlang
  1633 	 * @param $curlang
   642 	 */
  1634 	 */
   643 	function head_insert_language_metas($curlang,$undefined=true) {
  1635 	function head_insert_language_metas( ) {
   644 		$curlang = $this->curlang;
  1636 		$curlang = $this->curlang; 
   645 		$undefined = $this->langstate;
  1637 		$undefined = $this->langstate;
   646 		echo "<!-- multilingual website powered with xili-language v. ".XILILANGUAGE_VER." WP plugin of dev.xiligroup.com -->\n";
  1638 		echo "<!-- multilingual website powered with xili-language v. ".XILILANGUAGE_VER." ".$this->lpr." WP plugin of dev.xiligroup.com -->\n";
   647 			if (has_filter('head_insert_language_metas')) return apply_filters('head_insert_language_metas',$curlang,$undefined);
  1639 		if ( has_filter('head_insert_language_metas') ) return apply_filters( 'head_insert_language_metas', $curlang, $undefined );
   648 	}
  1640 	}
   649 	
  1641 	
   650 	/**
  1642 	/**
   651 	 * Translate texts of widgets  
  1643 	 * insert hreflang link in head (via wp_head)
   652 	 *
  1644 	 *
   653 	 * @since 0.9.8.1
  1645 	 * @since 2.5
       
  1646 	 * as commented in Google rel="alternate" 
       
  1647 	 *
       
  1648 	 * to change rules or be compatible with cpt and taxonomy use head_insert_hreflang_link filter
       
  1649 	 *   
       
  1650 	 * @param $curlang
       
  1651 	 */
       
  1652 	function head_insert_hreflang_link ( ) {
       
  1653 		if ( has_filter('head_insert_hreflang_link') ) return apply_filters( 'head_insert_hreflang_link', $this->curlang );
       
  1654 		global $post, $cat;
       
  1655 		if ( is_front_page() || is_category () ) {
       
  1656 			$listlanguages = $this->get_listlanguages();
       
  1657 			$currenturl = $this->current_url ( $this->lang_perma );
       
  1658 			foreach ( $listlanguages as $language ) {
       
  1659 				if ( $language->slug != $this->curlang ) {
       
  1660 					if ( is_category() ) { 
       
  1661 						$category = get_category ( $cat ); // test targets count
       
  1662 						if ( 0 < $this->count_posts_in_taxonomy_and_lang ( 'category', $category->slug , $language->slug ) ) { 
       
  1663 							$do_it = true; // 
       
  1664 						} else {
       
  1665 							$do_it = false;
       
  1666 						}	
       
  1667 					} else {
       
  1668 						$do_it = true;
       
  1669 					}
       
  1670 					if ( $do_it ) {
       
  1671 						$lang = str_replace( '_', '-', $language->name );
       
  1672 						$hreflang = ( $this->lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ;
       
  1673 						printf ( '<link rel="alternate" hreflang="%s" href="%s" />'."\n", $lang, $hreflang ) ;
       
  1674 					}
       
  1675 				} 		
       
  1676 			
       
  1677 			}
       
  1678 		} elseif ( is_singular() ) {
       
  1679 			$listlanguages = $this->get_listlanguages();
       
  1680 			foreach ( $listlanguages as $language ) {
       
  1681 				$targetpost = $this->linked_post_in ( $post->ID, $language->slug ) ; 
       
  1682 				if ( $language->slug != $this->curlang  && !empty ( $targetpost ) ) {
       
  1683 					$hreflang = $this->link_of_linked_post ( $post->ID, $language->slug ) ;
       
  1684 					$lang = str_replace( '_', '-', $language->name );
       
  1685 					printf ( '<link rel="alternate" hreflang="%s" href="%s" />'."\n", $lang, $hreflang ) ;
       
  1686 				}
       
  1687 			}
       
  1688 		} 
       
  1689 	}
       
  1690 	
       
  1691 	/**
       
  1692 	 * used in head_insert_hreflang_link and in xili_language_list
       
  1693 	 *
       
  1694 	 * @since 2.5
       
  1695 	 */
       
  1696 	function current_url ( $lang_perma ) { 
       
  1697 		if ( $lang_perma ) {	
       
  1698 			if (is_category()) {  
       
  1699 				remove_filter('term_link', 'insert_lang_4cat') ;
       
  1700 				$catcur = xiliml_get_category_link();
       
  1701 				add_filter( 'term_link', 'insert_lang_4cat', 10, 3 );
       
  1702 				$currenturl = $catcur; 
       
  1703 			} else {
       
  1704 				$currenturl = get_bloginfo('url').'/%lang%/';
       
  1705 			}
       
  1706 		} else {	
       
  1707 			if (is_category()) {  
       
  1708 				$catcur = xiliml_get_category_link();
       
  1709 				$permalink = get_option('permalink_structure'); /* 1.6.0 */
       
  1710 				$sep = ('' == $permalink) ? "&amp;" : "?" ;
       
  1711 				$currenturl = $catcur.$sep;
       
  1712 			} else {
       
  1713 			 	$currenturl = get_bloginfo('url').'/?';
       
  1714 			}
       
  1715 		}
       
  1716 		return $currenturl;
       
  1717 	}
       
  1718 	
       
  1719 	/**
       
  1720 	 * return count of posts in taxonomy and language
       
  1721 	 *
       
  1722 	 * called by head_insert_hreflang_link
       
  1723 	 * available for specific behaviour - why not in custom plugin for xili_language_list or...
       
  1724 	 * @params taxonomy (category), current slug, current lang
       
  1725 	 * @since 2.5
       
  1726 	 */ 
       
  1727 	 function count_posts_in_taxonomy_and_lang ( $taxonomy, $slug = '' , $language = '', $post_type = 'post' ) {
       
  1728 	 	
       
  1729 	 	$args = array(
       
  1730 	 		'post_type' => $post_type,
       
  1731 			'tax_query' => array(
       
  1732 				'relation' => 'AND',
       
  1733 				array(
       
  1734 					'taxonomy' => $taxonomy,
       
  1735 					'field' => 'slug',
       
  1736 					'terms' => array( $slug )
       
  1737 				),
       
  1738 				array( // language
       
  1739 					'taxonomy' => TAXONAME, 
       
  1740 					'field' => 'slug',
       
  1741 					'terms' => array( $language )	
       
  1742 				)
       
  1743 			)	
       
  1744 		);
       
  1745 		$query = new WP_Query( $args );
       
  1746 	 	
       
  1747 	 	return $query->found_posts;
       
  1748 	 }
       
  1749 	
       
  1750 	/**
       
  1751 	 * Translate texts of widgets or other simple text... 
       
  1752 	 *
       
  1753 	 * @updated 1.6.0 - Old name widget_texts
       
  1754 	 * @since 0.9.8.1 
   654 	 * @ return
  1755 	 * @ return
   655 	 */
  1756 	 */
   656 	function widget_texts ($value){
  1757 	function one_text ( $value ){
   657 		return __($value,THEME_TEXTDOMAIN);
  1758 		if ('' != $value)
       
  1759 			return __($value, $this->thetextdomain);
       
  1760 		else
       
  1761 			return $value;
       
  1762 	}
       
  1763 	
       
  1764 	/**
       
  1765 	 * Translate title of wp nav menu  
       
  1766 	 *
       
  1767 	 * @since 1.6.0
       
  1768 	 * @ return
       
  1769 	 */
       
  1770 	function wp_nav_title_text ( $value = "", $itemID = 0 ){
       
  1771 		if ('' != $value) { 
       
  1772 			return __( $value, $this->thetextdomain );
       
  1773 		} else {
       
  1774 			return $value;
       
  1775 		}
       
  1776 	}
       
  1777 	
       
  1778 	/**
       
  1779 	 * Add filters of texts of comment form  - because default text are linked with wp language (and not theme)
       
  1780 	 *
       
  1781 	 * @since 1.5.5
       
  1782 	 * @ return arrays with themetextdomain
       
  1783 	 */
       
  1784 	function xili_comment_form_default_fields ( $fields ) {
       
  1785 		$commenter = wp_get_current_commenter();
       
  1786 
       
  1787 		$req = get_option( 'require_name_email' );
       
  1788 		$aria_req = ( $req ? " aria-required='true'" : '' );
       
  1789 		$fields =  array(
       
  1790 			'author' => '<p class="comment-form-author">' . '<label for="author">' . __( $this->comment_form_labels['name'], $this->thetextdomain ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
       
  1791 			            '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
       
  1792 			'email'  => '<p class="comment-form-email"><label for="email">' . __( $this->comment_form_labels['email'], $this->thetextdomain ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
       
  1793 			            '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
       
  1794 			'url'    => '<p class="comment-form-url"><label for="url">' . __( $this->comment_form_labels['website'], $this->thetextdomain ) . '</label>' .
       
  1795 			            '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
       
  1796 		);
       
  1797 		return $fields;
       
  1798 	}
       
  1799 	/** 2.3.2 - noun context */
       
  1800 	function xili_comment_form_defaults ( $defaults ) { 
       
  1801 		global $user_identity, $post;
       
  1802 		$req = get_option( 'require_name_email' );
       
  1803 		$xilidefaults = array(
       
  1804 		
       
  1805 		'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( $this->comment_form_labels['comment'], 'noun', $this->thetextdomain ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
       
  1806 		'must_log_in'          => '<p class="must-log-in">' .  sprintf( __( $this->comment_form_labels['youmustbe'], $this->thetextdomain ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post->ID ) ) ) ) . '</p>',
       
  1807 		'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( $this->comment_form_labels['loggedinas'], $this->thetextdomain ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post->ID ) ) ) ) . '</p>',
       
  1808 		'comment_notes_before' => '<p class="comment-notes">' . __( $this->comment_form_labels['emailnotpublished'], $this->thetextdomain ) . ( $req ? __( $this->comment_form_labels['requiredmarked'], $this->thetextdomain ) : '' ) . '</p>',
       
  1809 		'comment_notes_after'  => '<dl class="form-allowed-tags"><dt>' . __( $this->comment_form_labels['youmayuse'], $this->thetextdomain ) . '</dt> <dd><code>' . allowed_tags() . '</code></dd></dl>',
       
  1810 		'id_form'              => 'commentform',
       
  1811 		'id_submit'            => 'submit',
       
  1812 		'title_reply'          => __( $this->comment_form_labels['leavereply'], $this->thetextdomain ),
       
  1813 		'title_reply_to'       => __( $this->comment_form_labels['replyto'], $this->thetextdomain ),
       
  1814 		'cancel_reply_link'    => __( $this->comment_form_labels['cancelreply'], $this->thetextdomain ),
       
  1815 		'label_submit'         => __( $this->comment_form_labels['postcomment'], $this->thetextdomain ),
       
  1816 		);
       
  1817 		$args = wp_parse_args( $xilidefaults, $defaults);
       
  1818 		return $args;
   658 	}
  1819 	}
   659 			
  1820 			
   660 	/**
  1821 	/**
   661 	 * insert other language of wp_list_categories 
  1822 	 * insert other language of wp_list_categories 
   662 	 *
  1823 	 *
   664 	 * @updated 0.9.8.4 - 1.4.1 = no original term in ()
  1825 	 * @updated 0.9.8.4 - 1.4.1 = no original term in ()
   665 	 * can be hooked by filter add_filter('xiliml_cat_language','yourfunction',2,3) in functions.php
  1826 	 * can be hooked by filter add_filter('xiliml_cat_language','yourfunction',2,3) in functions.php
   666 	 * call by do_filter list_cats 
  1827 	 * call by do_filter list_cats 
   667 	 * @param $content, $category
  1828 	 * @param $content, $category
   668 	 */
  1829 	 */
   669 	function xiliml_cat_language ($content, $category = null) {
  1830 	function xiliml_cat_language ( $content, $category = null ) {
   670 		if (has_filter('xiliml_cat_language')) return apply_filters('xiliml_cat_language',$content, $category,$this->curlang);
  1831 		if (has_filter('xiliml_cat_language')) return apply_filters('xiliml_cat_language',$content, $category,$this->curlang);
   671 	    $new_cat_name = (!is_admin()) ? __($category->name,THEME_TEXTDOMAIN) : $content ;  /*to detect admin UI*/
  1832 	    $new_cat_name = (!is_admin()) ? __($category->name,$this->thetextdomain) : $content ;  /*to detect admin UI*/
   672 	    return $new_cat_name;
  1833 	    return $new_cat_name;
   673 	 } 
  1834 	 } 
   674 	
  1835 	
   675 	/**
  1836 	/**
   676 	 * add the language key in category links of current pages
  1837 	 * add the language key in category links of current pages
   677 	 *
  1838 	 *
   678 	 * @since 0.9.0
  1839 	 * @since 0.9.0
   679 	 * update 0.9.7
  1840 	 * update 0.9.7 1.5.1
   680 	 * can be hooked by filter add_filter('xiliml_link_append_lang','yourfunction',10,2) in functions.php
  1841 	 * can be hooked by filter add_filter('xiliml_link_append_lang','yourfunction',10,2) in functions.php
   681 	 * call by do_filter 
  1842 	 * call by do_filter 
   682 	 * @param $content,
  1843 	 * @param $content,
   683 	 */
  1844 	 */
   684 	function xiliml_link_append_lang( $link ) {
  1845 	function xiliml_link_append_lang( $link, $category_id = 0 ) {
   685 		if (has_filter('xiliml_link_append_lang')) return apply_filters('xiliml_link_append_lang',$link,$this->curlang);
  1846 		if ( has_filter( 'xiliml_link_append_lang' ) ) return apply_filters( 'xiliml_link_append_lang', $link, $category_id, $this->curlang );
   686 		/*default*/
  1847 		/*default*/
       
  1848 			
   687 	  		if ($this->curlang) :
  1849 	  		if ($this->curlang) :
   688 	  			$link .= '&amp;'.QUETAG.'='.$this->curlang ;
  1850 	  		 	if ( !$this->lang_perma ){ // 2.1.1
       
  1851 	  				$permalink = get_option( 'permalink_structure' );
       
  1852 	  			 	$sep = ('' == $permalink) ? "&amp;".QUETAG."=" : "?".QUETAG."=";
       
  1853 	  				$link .= $sep.$this->curlang ; // wpmu
       
  1854 				} 			
       
  1855 	  			
   689 	  		endif;
  1856 	  		endif;
   690 	  	
  1857 	  	
   691 	  return $link;
  1858 	  return $link;
   692 	}
  1859 	}
   693 	
  1860 	
   711 	  		endif;
  1878 	  		endif;
   712 	  	
  1879 	  	
   713 	  	*/
  1880 	  	*/
   714 	 return $taglink;
  1881 	 return $taglink;
   715 	} 
  1882 	} 
       
  1883 	
       
  1884 	/**
       
  1885 	 * Setup global post data.
       
  1886 	 *
       
  1887 	 * @since 1.6.0 
       
  1888 	 * can be hooked by filter add_filter('xiliml_bloginfo','yourfunction',10,3) in functions.php
       
  1889 	 *
       
  1890 	 * @param $output, $show.
       
  1891 	 * @return translated $output.
       
  1892 	 */ 
       
  1893 	 function xiliml_bloginfo ( $output, $show ) {
       
  1894 	 	if (has_filter('xiliml_bloginfo')) return apply_filters('xiliml_bloginfo',$output, $show, $this->curlang);
       
  1895 	 	$info_enabled = array('name', 'blogname', 'description');
       
  1896 	 	if (in_array($show, $info_enabled)) {
       
  1897 	 		return __($output, $this->thetextdomain);
       
  1898 	 	} else {
       
  1899 	 		return $output;
       
  1900 	 	}
       
  1901 	 }
   716 	 
  1902 	 
   717 	/**
  1903 	/**
   718 	 * to cancel sub select by lang in cat 1 by default 
  1904 	 * to cancel sub select by lang in cat 1 by default 
   719 	 *
  1905 	 *
   720 	 * @since 0.9.2
  1906 	 * @since 0.9.2
   721 	 * update 0.9.7
  1907 	 * update 0.9.7 - 1.8.4
   722 	 * can be hooked by filter add_filter('xiliml_modify_querytag','yourfunction') in functions.php
  1908 	 * can be hooked by filter add_filter('xiliml_modify_querytag','yourfunction') in functions.php
   723 	 *
  1909 	 *
   724 	 *
  1910 	 *
   725 	 */
  1911 	 */
   726 	function xiliml_modify_querytag() {
  1912 	function xiliml_modify_querytag() {
   727 		if (has_filter('xiliml_modify_querytag')) {
  1913 		if ( has_filter('xiliml_modify_querytag') ) {
   728 			apply_filters('xiliml_modify_querytag','');
  1914 			apply_filters('xiliml_modify_querytag','');
   729 		} else {	
  1915 		} else {	
   730 		/*default*/
  1916 			/*default*/
   731 		global $wp_query;
  1917 			global $wp_query;
   732 		if (!defined('XILI_CATS_ALL')) define('XILI_CATS_ALL','1'); /* change in functions.php or use hook in cat 1 by default*/
  1918 			if ( defined('XILI_CATS_ALL') && !empty($wp_query->query_vars['cat']) )  { /* change in functions.php or use hook in cat 1 by default*/
   733 			$excludecats = explode(",", XILI_CATS_ALL);
  1919 				$excludecats = explode(",", XILI_CATS_ALL);
   734 			if (!empty($wp_query->query_vars['cat'])) {
  1920 				if 	( $excludecats != array() && in_array($wp_query->query_vars['cat'],$excludecats) ) {
   735 				if 	(in_array($wp_query->query_vars['cat'],$excludecats)) {
       
   736 					$wp_query->query_vars[QUETAG] = "";	/* to cancel sub select */
  1921 					$wp_query->query_vars[QUETAG] = "";	/* to cancel sub select */
   737 				}
  1922 				}
   738 			}
  1923 			}
   739 		}	
  1924 		}	
   740 	}	
  1925 	}
       
  1926 		
   741 	/**
  1927 	/**
   742 	 * filters for wp_get_archives 
  1928 	 * filters for wp_get_archives 
   743 	 *
  1929 	 *
   744 	 * @since 0.9.2
  1930 	 * @since 0.9.2
   745 	 * @params $join or $where and template params
  1931 	 * @params $join or $where and template params
   746 	 *
  1932 	 *
   747 	 */
  1933 	 */
   748 	function xiliml_getarchives_join($join,$r) {
  1934 	function xiliml_getarchives_join( $join, $r ) {
   749 		global $wpdb;
  1935 		global $wpdb;
   750 		if (has_filter('xiliml_getarchives_join')) return apply_filters('xiliml_getarchives_join',$join,$r,$this->curlang);
  1936 		if (has_filter('xiliml_getarchives_join')) return apply_filters('xiliml_getarchives_join',$join,$r,$this->curlang);
   751 		extract( $r, EXTR_SKIP );
  1937 		extract( $r, EXTR_SKIP );
   752 		$this->get_archives_called = $r;
  1938 		$this->get_archives_called = $r;
   753 		if (isset($lang)) {
  1939 		if (isset($lang)) {
   754 			if ("" == $lang ) { /* used for link */
  1940 			if ("" == $lang ) { /* used for link */
   755 				$this->get_archives_called['lang'] = $this->curlang;
  1941 				$this->get_archives_called[QUETAG] = $this->curlang;
   756 			} else {
  1942 			} else {
   757 				$this->get_archives_called['lang'] = $lang;
  1943 				$this->get_archives_called[QUETAG] = $lang;
   758 			}
  1944 			}
   759 			$join = " INNER JOIN $wpdb->term_relationships as tr ON ($wpdb->posts.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) ";
  1945 			$join = " INNER JOIN $wpdb->term_relationships as tr ON ($wpdb->posts.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) ";
   760 		
  1946 		
   761 		}
  1947 		}
   762 		return $join;
  1948 		return $join;
   763 		
  1949 		
   764 	}
  1950 	}
   765 	
  1951 	
   766 	function xiliml_getarchives_where($where,$r) {
  1952 	function xiliml_getarchives_where( $where, $r ) {
   767 		global $wpdb;
  1953 		global $wpdb;
   768 		if (has_filter('xiliml_getarchives_where')) return apply_filters('xiliml_getarchives_where',$where,$r,$this->curlang);
  1954 		if (has_filter('xiliml_getarchives_where')) return apply_filters('xiliml_getarchives_where',$where,$r,$this->curlang);
   769 		extract( $r, EXTR_SKIP );
  1955 		extract( $r, EXTR_SKIP );
   770 		if (isset($lang)) {
  1956 		if (isset($lang)) {
   771 			if ("" == $lang ) {
  1957 			if ("" == $lang ) {
   772 				$curlang = $this->curlang;
  1958 				$curlang = $this->curlang;
   773 			} else {
  1959 			} else {
   774 				$curlang = $lang;
  1960 				$curlang = $lang;
   775 			}
  1961 			}
   776 			$reqtag = is_term( $curlang, TAXONAME );
  1962 			$reqtag = term_exists( $curlang, TAXONAME );
   777 				if (''!= $reqtag) {
  1963 				if (''!= $reqtag) {
   778 					$wherereqtag = $reqtag['term_id'];
  1964 					$wherereqtag = $reqtag['term_id'];
   779 				} else {
  1965 				} else {
   780 					$wherereqtag = 0;	
  1966 					$wherereqtag = 0;	
   781 				}
  1967 				}
   783 				$where .= " AND tt.term_id = $wherereqtag ";
  1969 				$where .= " AND tt.term_id = $wherereqtag ";
   784 		}		
  1970 		}		
   785 		return $where;
  1971 		return $where;
   786 	}
  1972 	}
   787 	
  1973 	
   788 	/* here basic translation - to improve depending theme features : use hook 'xiliml_get_archives_link' */
  1974 	/** *here basic translation - to improve depending theme features : use hook 'xiliml_get_archives_link' */
   789 	function xiliml_get_archives_link($link_html) {
  1975 	function xiliml_get_archives_link( $link_html ) {
   790 		if (has_filter('xiliml_link_translate_desc')) return apply_filters('xiliml_get_archives_link', $link_html,$this->get_archives_called, $this->curlang);
  1976 		if ( has_filter('xiliml_link_translate_desc')) return apply_filters('xiliml_get_archives_link', $link_html,$this->get_archives_called, $this->curlang );
   791 		extract( $this->get_archives_called, EXTR_SKIP );
  1977 		extract( $this->get_archives_called, EXTR_SKIP );
   792 		if ('' != $lang) {
  1978 		if ( isset( $lang ) && '' != $lang ) {
   793 			$permalink = get_option('permalink_structure');
  1979 			$permalink = get_option('permalink_structure');
   794 			$sep = ('' == $permalink) ? "&amp;lang=" : "?lang=";
  1980 			$sep = ('' == $permalink) ? "&amp;".QUETAG."=" : "?".QUETAG."=";
   795 			if ($format != 'option' && $format != 'link' && $type != 'postbypost' && $type != 'alpha') {
  1981 			if ($format != 'option' && $format != 'link' && $type != 'postbypost' && $type != 'alpha') {
   796 				/* text extract */
  1982 				/* text extract */
   797 				$i = preg_match_all("/'>(.*)<\/a>/Ui", $link_html, $matches,PREG_PATTERN_ORDER);
  1983 				$i = preg_match_all("/'>(.*)<\/a>/Ui", $link_html, $matches,PREG_PATTERN_ORDER);
   798 				$line = $matches[1][0];
  1984 				$line = $matches[1][0];
   799 				/* link extract */
  1985 				/* link extract */
   800 				$i = preg_match_all("/href='(.*)' title/Ui", $link_html, $matches,PREG_PATTERN_ORDER);
  1986 				$i = preg_match_all("/href='(.*)' title/Ui", $link_html, $matches,PREG_PATTERN_ORDER);
   801 				if ( '' == $type || 'monthly' == $type) {
  1987 				if ( '' == $type || 'monthly' == $type) {
   802 					if ('' == $permalink) {
  1988 					if ('' == $permalink) {
   803 						$archivedate = str_replace(get_bloginfo('siteurl').'/?' , "" , $matches[1][0]);
  1989 						$archivedate = str_replace(get_bloginfo('url').'/?' , "" , $matches[1][0]);
   804 						$r = wp_parse_args( $archivedate, array());
  1990 						$r = wp_parse_args( $archivedate, array());
   805 						extract($r, EXTR_SKIP );
  1991 						extract($r, EXTR_SKIP );
   806 						$month = substr($m,-2);
  1992 						$month = substr($m,-2);
   807 						$year = substr($m,0,4);
  1993 						$year = substr($m,0,4);
   808 					} else {
  1994 					} else {
   809 						/* Due to prevents post ID and date permalinks from overlapping using /date/ v 1.1.9 
  1995 						/* Due to prevents post ID and date permalinks from overlapping using /date/ v 1.1.9 
   810 						 * no / at end for "numeric" permalink giving /archives/date/2009/04
  1996 						 * no / at end for "numeric" permalink giving /archives/date/2009/04
   811 						 */
  1997 						 */
   812 						$thelink = $matches[1][0];
  1998 						$thelink = $matches[1][0];
   813 						$i = preg_match_all("/\/([0-9]{4})\/([0-9]{2})/Ui", $thelink, $results,PREG_PATTERN_ORDER);
  1999 						$i = preg_match_all("/\/([0-9]{4})\/([0-9]{2})/Ui", $thelink, $results,PREG_PATTERN_ORDER);
   814 						if ($i) { //print_r($results);
  2000 						if ($i) { 
   815 							$month = $results[2][0];
  2001 							$month = $results[2][0];
   816 							$year = $results[1][0];
  2002 							$year = $results[1][0];
   817 						}
  2003 						}
   818 					}	
  2004 					}	
   819 					$time = strtotime($month.'/1/'.$year);
  2005 					$time = strtotime($month.'/1/'.$year);
   836 	 * update 0.9.7 - 0.9.9.4
  2022 	 * update 0.9.7 - 0.9.9.4
   837 	 * can be hooked by filter add_filter('xiliml_link_translate_desc','yourfunction',2,4) in functions.php
  2023 	 * can be hooked by filter add_filter('xiliml_link_translate_desc','yourfunction',2,4) in functions.php
   838 	 *
  2024 	 *
   839 	 *
  2025 	 *
   840 	 */
  2026 	 */
   841 	function xiliml_link_translate_desc( $description, $category=null,$context='') {
  2027 	function xiliml_link_translate_desc( $description, $category=null, $context='' ) {
   842 		if (has_filter('xiliml_link_translate_desc')) return apply_filters('xiliml_link_translate_desc',$description,$category,$context,$this->curlang);
  2028 		if (has_filter('xiliml_link_translate_desc')) return apply_filters('xiliml_link_translate_desc',$description,$category,$context,$this->curlang);
   843 	  	$translated_desc = ($this->curlang && ''!= $description) ? __($description,THEME_TEXTDOMAIN) : $description ;
  2029 	  	$translated_desc = ($this->curlang && ''!= $description) ? __($description, $this->thetextdomain) : $description ;
   844 	 	return $translated_desc;
  2030 	 	return $translated_desc;
   845 	}
  2031 	}
   846 	
  2032 	
   847 	/**
  2033 	/**
   848 	 * filters for wp_title() translation - single_cat_title - 
  2034 	 * filters for wp_title() translation - single_cat_title - 
   849 	 * since 1.4.1
  2035 	 * since 1.4.1
   850 	 *
  2036 	 *
   851 	 */
  2037 	 */
   852 	function xiliml_single_cat_title_translate ($cat_name) {
  2038 	function xiliml_single_cat_title_translate ( $cat_name ) {
   853 		if (has_filter('xiliml_single_cat_title_translate')) return apply_filters('xiliml_single_cat_title_translate',$cat_name);
  2039 		if (has_filter('xiliml_single_cat_title_translate')) return apply_filters('xiliml_single_cat_title_translate',$cat_name);
   854 		$translated = ($this->curlang && ''!= $cat_name) ? __($cat_name,THEME_TEXTDOMAIN) : $cat_name;
  2040 		$translated = ($this->curlang && ''!= $cat_name) ? __($cat_name,$this->thetextdomain) : $cat_name;
   855 	 	return $translated;	
  2041 	 	return $translated;	
   856 	}
  2042 	}
   857 		
  2043 		
   858 	/**
  2044 	/**
   859 	 * Return the list of preferred languages for displaying pages (see in firefox prefs)
  2045 	 * Return the list of preferred languages for displaying pages (see in firefox prefs)
   860 	 * thanks to php.net comments HTTP_ACCEPT_LANGUAGE
  2046 	 * thanks to php.net comments HTTP_ACCEPT_LANGUAGE
   861 	 * @since 0.9.7.5
  2047 	 * @since 0.9.7.5
   862 	 * 
  2048 	 * @updated 2.7.1
   863 	 * @return array (non sorted)
  2049 	 * @return array (non sorted)
   864 	 */
  2050 	 */
   865 	function the_preferred_languages() {	 
  2051 	function the_preferred_languages() {	 
   866 		$preferred_languages = array();
  2052 		$preferred_languages = array();
   867 			if(preg_match_all("#([^;,]+)(;[^,0-9]*([0-9\.]+)[^,]*)?#i",$_SERVER["HTTP_ACCEPT_LANGUAGE"], $matches, PREG_SET_ORDER)) {
  2053 			if( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) && preg_match_all("#([^;,]+)(;[^,0-9]*([0-9\.]+)[^,]*)?#i",$_SERVER["HTTP_ACCEPT_LANGUAGE"], $matches, PREG_SET_ORDER)) {
   868 				foreach($matches as $match) {
  2054 				foreach($matches as $match) {
   869 					$preferred_languages[$match[1]] = floatval($match[3]);
  2055 					if(isset($match[3])) {
   870 					if($match[3]==NULL) $preferred_languages[$match[1]] = 1.0;
  2056 						$preferred_languages[$match[1]] = floatval($match[3]);
       
  2057 					} else {
       
  2058 						$preferred_languages[$match[1]] = 1.0; 
       
  2059 					}
   871 				}
  2060 				}
   872 				return $preferred_languages;	
  2061 				return $preferred_languages;	
   873 			} else {
  2062 			} else {
   874 				return false;	
  2063 				return false;	
   875 			}	
  2064 			}	
   893 	/**
  2082 	/**
   894 	 * Return the list of preferred languages for displaying pages (see in firefox prefs)
  2083 	 * Return the list of preferred languages for displaying pages (see in firefox prefs)
   895 	 * thanks to php.net comments HTTP_ACCEPT_LANGUAGE
  2084 	 * thanks to php.net comments HTTP_ACCEPT_LANGUAGE
   896 	 * @since 0.9.7.5
  2085 	 * @since 0.9.7.5
   897 	 * @update 0.9.9.4
  2086 	 * @update 0.9.9.4
   898 	 * @return array (non sorted)
  2087 	 * @update 2.3.1 - lang_neither_browser
       
  2088 	 * @return default target language
   899 	 */
  2089 	 */
   900 	function choice_of_browsing_language() {
  2090 	function choice_of_browsing_language() {
   901 		if (has_filter('choice_of_browsing_language')) return apply_filters('choice_of_browsing_language');
  2091 		if ( has_filter('choice_of_browsing_language') ) return apply_filters('choice_of_browsing_language',''); // '' 2.3.1
   902 		if ($this->browseroption != 'browser') return $this->choice_of_home_selected_lang(); /* in settings UI - after filter to hook w/o UI */
  2092 		if ( $this->browseroption != 'browser' ) return $this->choice_of_home_selected_lang(); /* in settings UI - after filter to hook w/o UI */
   903 		$listofprefs = $this->the_preferred_languages();
  2093 		$listofprefs = $this->the_preferred_languages();
   904 		if (is_array($listofprefs)) {
  2094 		$default_lang = ( "" != $this->lang_neither_browser ) ? $this->lang_neither_browser : $this->default_lang ; //2.3.1
       
  2095 		if ( is_array($listofprefs) ) {
   905 			arsort($listofprefs, SORT_NUMERIC);
  2096 			arsort($listofprefs, SORT_NUMERIC);
   906 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
  2097 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
   907 			$sitelanguage = $this->match_languages ($listofprefs,$listlanguages);
  2098 			$sitelanguage = $this->match_languages ( $listofprefs, $listlanguages );
   908 			if ($sitelanguage) return $sitelanguage->slug;
  2099 			if ( $sitelanguage ) return $sitelanguage->slug;
   909 			return strtolower($this->default_lang);
  2100 			return strtolower( $default_lang );
   910 		} else {
  2101 		} else {
   911 			return strtolower($this->default_lang);
  2102 			return strtolower( $default_lang );
   912 		}
  2103 		}
   913 	}
  2104 	}
   914 	
  2105 	
   915 	function match_languages ($listofprefs,$listlanguages) {
  2106 	function match_languages ( $listofprefs, $listlanguages ) {
   916 		
  2107 		
   917 			foreach($listofprefs as $browserlanguage => $priority) {
  2108 			foreach($listofprefs as $browserlanguage => $priority) {
   918 					/* match root languages to give similar in site  - first : five chars langs*/
  2109 					/* match root languages to give similar in site  - first : five chars langs*/
   919 					foreach($listlanguages as $sitelanguage) {
  2110 					foreach($listlanguages as $sitelanguage) {
   920 						if ($sitelanguage->slug == str_replace('-','_',$browserlanguage)) return $sitelanguage;
  2111 						if ($sitelanguage->slug == str_replace('-','_',$browserlanguage)) return $sitelanguage;
   926 						if (str_replace('-','_',$browserlanguage) == substr($sitelanguage->slug,0,2)) return $sitelanguage;
  2117 						if (str_replace('-','_',$browserlanguage) == substr($sitelanguage->slug,0,2)) return $sitelanguage;
   927 					}	
  2118 					}	
   928 			}
  2119 			}
   929 	}
  2120 	}
   930 	
  2121 	
   931 	/********************************** ADMIN UI ***********************************/
  2122 	/**
   932 			
  2123 	 * Choice of language when is_category and all languages
   933 	/**
  2124 	 *
   934 	 * add admin menu and associated pages of admin UI
  2125 	 * @since 1.8.9.1
   935 	 *
  2126 	 * called by get_curlang_action_wp
   936 	 * @since 0.9.0
  2127 	 *
   937 	 * @updated 0.9.6 - only for WP 2.7.X - do registering of new meta boxes and JS
  2128 	 */
   938 	 *
  2129 	function choice_of_categories_all_languages( $curlang ) {
   939 	 */
  2130 		$choice = $this->xili_settings['allcategories_lang'];
   940 	function xili_add_pages() {
  2131 		if ( $choice == "browser" ) {
   941 		 $this->thehook = add_options_page(__('Languages','xili-language'), __('Languages','xili-language'), 'manage_options', 'language_page', array(&$this,'languages_settings'));
  2132 			return $this->choice_of_browsing_language();
   942 		 add_action('load-'.$this->thehook, array(&$this,'on_load_page'));
  2133 		} elseif ( $choice == "firstpost" ) {
   943 	}
  2134 			return $curlang ;
   944 	
  2135 		} elseif ( $choice == "" ) {
   945 	function on_load_page() {
  2136 			if ( function_exists('xl_choice_of_categories_all_languages') ) {
   946 			wp_enqueue_script('common');
  2137 				return xl_choice_of_categories_all_languages () ;
   947 			wp_enqueue_script('wp-lists');
  2138 			} else {
   948 			wp_enqueue_script('postbox');
  2139 				return ''; // return without mo
   949 			add_meta_box('xili-language-sidebox-1', __('Message','xili-language'), array(&$this,'on_sidebox_1_content'), $this->thehook , 'side', 'core');
  2140 			}
   950 			add_meta_box('xili-language-sidebox-2', __('Info','xili-language'), array(&$this,'on_sidebox_2_content'), $this->thehook , 'side', 'core');
  2141 		}
   951 			add_meta_box('xili-language-sidebox-4', __('Special','xili-language'), array(&$this,'on_sidebox_4_content'), $this->thehook , 'side', 'core');
  2142 		return $choice;
   952 			
  2143 	}
   953 	}
  2144 	
   954 	
  2145 	/**
   955 	/**
  2146 	 * to encapsulate future method
   956 	 * Add action link(s) to plugins page
  2147 	 *
   957 	 * 
  2148 	 * @since 1.8.9.1
   958 	 * @since 0.9.3
  2149 	 * @param post_ID and lang slug
   959 	 * @author MS
  2150 	 */
   960 	 * @copyright Dion Hulse, http://dd32.id.au/wordpress-plugins/?configure-link and scripts@schloebe.de
  2151 	function linked_post_in ( $fromID, $lang_slug ) {
   961 	 */
  2152 		return get_post_meta( $fromID, QUETAG.'-'.$lang_slug, true ); // will be soon changed
   962 	function xililang_filter_plugin_actions($links, $file){
  2153 	}
   963 		static $this_plugin;
  2154 	
   964 		if( !$this_plugin ) $this_plugin = plugin_basename(__FILE__);
  2155 	/**
   965 		if( $file == $this_plugin ){
  2156 	 * if possible, translate the array of ID of sticky posts
   966 			$settings_link = '<a href="options-general.php?page=language_page">' . __('Settings') . '</a>';
  2157 	 *
   967 			$links = array_merge( array($settings_link), $links); // before other links
  2158 	 * @since 1.6.1
   968 		}
  2159 	 * called by hook option_sticky_posts
   969 		return $links;
  2160 	 * @updated 2.8.1
   970 	}
  2161 	 */
   971 	
  2162 	function translate_sticky_posts_ID( $original_array ) { 
   972 	/* UI added in sidebar of post admin (write , edit)
  2163 		global $wp_query ;
   973 	 *
  2164 		if ( !is_admin() && is_home() ) { // because impossible to register the value in admin UI - 
   974 	 * @since 0.9.0
  2165 		// and because tracs http://core.trac.wordpress.org/ticket/14115
   975 	 * @updated 0.9.5 : add a no-lang radio - again in top of sidebar admin post's UI
  2166 			if ($original_array != array()) {
   976 	 * @updated 0.9.8.3 : if new post and checked in settings : default language = author's browser's language !
  2167 				$translated_array = array(); 
   977 	 * @updated 1.3.0
  2168 				if ( isset( $wp_query->query_vars[QUETAG] )) { //if (isset($_GET[QUETAG])) {  // $_GET not usable by lang perma mode 2.8.1
   978 	 */
  2169 					$curlang = $wp_query->query_vars[QUETAG]; // $_GET[QUETAG]; 
   979 	function xili_language_checkboxes_n() { 
       
   980 		global $post_ID ;
       
   981 		//$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
       
   982 		$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
       
   983 		if ($this->authorbrowseroption == 'authorbrowser') { // setting = select language of author's browser
       
   984 			$listofprefs = $this->the_preferred_languages();
       
   985 			if (is_array($listofprefs)) {
       
   986 				arsort($listofprefs, SORT_NUMERIC);
       
   987 				$sitelanguage = $this->match_languages ($listofprefs,$listlanguages);
       
   988 				if ($sitelanguage) {
       
   989 					$defaultlanguage = $sitelanguage->name;
       
   990 				} else {
  2170 				} else {
   991 					$defaultlanguage = "";
  2171 					$curlang = $this->choice_of_browsing_language(); // rule defined in admin UI
   992 				}	
  2172 				}
   993 				$mention = '('.__('Browser language', 'xili-language').')';
  2173 				foreach ($original_array as $id) {
       
  2174 					$langpost = $this->get_cur_language($id); 
       
  2175 					$post_lang = $langpost[QUETAG];
       
  2176 					if ($post_lang != $curlang) { // only if necessary
       
  2177 						$trans_id = $this-> linked_post_in( $id, $curlang ) ; // get_post_meta($id, 'lang-'.$curlang, true);
       
  2178 						if ( '' != $trans_id ) { 
       
  2179 							$translated_array[] = $trans_id;
       
  2180 						} else {
       
  2181 							if ( $this->sticky_keep_original === true ) $translated_array[] = $id; 
       
  2182 							// set by webmaster  in theme functions
       
  2183 							
       
  2184 						}
       
  2185 					} else {
       
  2186 						$translated_array[] = $id;
       
  2187 					}
       
  2188 				}
       
  2189 				return $translated_array;
   994 			} else {
  2190 			} else {
   995 				$defaultlanguage = ""; /* undefined */
  2191 				return $original_array;
   996 			}	
  2192 			} 
   997 		} else {
  2193 		} else {
   998 			$defaultlanguage = ""; /* undefined */
  2194 			return $original_array;
   999 			$mention = "";
  2195 		}		
  1000 		}	
  2196 	}
  1001 		
  2197 	
  1002 		if(0 != $post_ID){
  2198 	/**
  1003 			$ress = wp_get_object_terms($post_ID, TAXONAME);
  2199 	 * cancel default filtering when page on front
  1004 			
  2200 	 *
  1005 			/*Array ( [0] => stdClass Object ( [term_id] => 18 [name] => [slug] => 18 [term_group] => 0 [term_taxonomy_id] => 19 [taxonomy] => language [description] => [parent] => 0 [count] => 1 ) )*/
  2201 	 *
  1006 			$obj_term = $ress[0];
  2202 	 * @updated 2.6.3
  1007 			if ('' != $obj_term->name) :
  2203 	 */
  1008 				$curlangname = $obj_term->name;
  2204 	function get_option_wo_xili ( $option ) {
  1009 			else :
  2205 		if ( $option == 'page_on_front' && isset( $this->idx['translate_page_on_front_ID'] ) ) { // 2.6.3
  1010 				$curlangname = ""; /* when created before plugin */
  2206 			remove_filter ( 'option_'.$option, $this->idx['translate_page_on_front_ID'] );
  1011 			endif;
  2207 			$value = get_option ( $option ) ;
  1012 			
  2208 			add_filter ( 'option_'.$option, array(&$this, 'translate_page_on_front_ID') );
  1013 		} else {
  2209 		} else {
  1014 			if (isset($_GET['xltgt_lang'])) {
  2210 			$value = get_option (  $option ) ;
  1015 				$curlangname = $_GET['xltgt_lang']; /* since 1.3.0 */
  2211 		}
  1016 				$mention = '<br />('.__('From other post', 'xili-language').': '.$_GET['xlfrom_id'].'&nbsp;'.$_GET['xlfrom_lang'].')';
  2212 		return $value ;
       
  2213 	}
       
  2214 	
       
  2215 	/**
       
  2216 	 * if possible, translate the ID of front_page post
       
  2217 	 *
       
  2218 	 * @since 1.7.0
       
  2219 	 * called by hook option_page_on_front
       
  2220 	 *
       
  2221 	 */
       
  2222 	function translate_page_on_front_ID ( $original_id ) {
       
  2223 		
       
  2224 		if ( $this->lang_perma ) {
       
  2225 			global $wp_query ;
       
  2226 			
       
  2227 			if ( !is_admin() && $this->show_page_on_front ) { 
       
  2228 			 	if ( isset( $wp_query->query_vars[QUETAG] ) && in_array ( $wp_query->query_vars[QUETAG], array_keys ( $this->show_page_on_front_array ) ) && '' != $wp_query->query_vars['page_id'] ) {	
       
  2229 					$curlang = $wp_query->query_vars[QUETAG];
       
  2230 				 
       
  2231 					
       
  2232 				} elseif ( isset( $wp_query->query_vars[QUETAG] ) && in_array ( $wp_query->query_vars[QUETAG], array_keys ( $this->show_page_on_front_array ) ) ){
       
  2233 					
       
  2234 					$curlang = $wp_query->query_vars[QUETAG]; // to verify
       
  2235 				} else {
       
  2236 					//$first_query = get_option('xili_language_settings_test') ;
       
  2237 					//if ( $first_query ) {
       
  2238 						//$curlang = $first_query ;
       
  2239 					//} else {
       
  2240 						$curlang = $this->choice_of_browsing_language(); // rule defined in admin UI
       
  2241 					
       
  2242 					//}
       
  2243 				}				
       
  2244 			 	$trans_id = $this->linked_post_in( $original_id, $curlang ) ; 
       
  2245 				
       
  2246 				if ( '' != $trans_id ) { 
       
  2247 					return $trans_id;
       
  2248 				} else {
       
  2249 					return $original_id;	
       
  2250 				}
  1017 			} else {
  2251 			} else {
  1018 				$curlangname = $defaultlanguage; /* new post */
  2252 				return $original_id;
  1019 			}
  2253 			}
  1020 		}
  2254 		
  1021 		echo __('Selected language', 'xili-language').' : <strong>'.$curlangname.'</strong> '.((0 == $post_ID) ? $mention : "").'<br /><br />' ; /*link to bottom of sidebar*/
       
  1022 		foreach ($listlanguages as $language) { ?> 
       
  1023 		<label for="xili_language_check_<?php echo $language->slug ; ?>" class="selectit"><input id="xili_language_check_<?php echo $language->slug ; ?>" name="xili_language_set" type="radio" value="<?php echo $language->slug ; ?>"  <?php if($curlangname==$language->name) echo 'checked="checked"' ?> /> <?php echo _e($language->description, 'xili-language'); ?></label>
       
  1024 	  
       
  1025 		<?php } /*link to top of sidebar*/?> 
       
  1026 		<label for="xili_language_check" class="selectit"><input id="xili_language_check" name="xili_language_set" type="radio" value="" <?php if($curlangname=="") echo 'checked="checked"' ?> /> <?php _e('undefined','xili-language') ?></label><br />
       
  1027 	  	<br /><small>© xili-language</small>
       
  1028 	<?php 
       
  1029 	}
       
  1030 	
       
  1031 	/**
       
  1032 	 * to display the linked posts in post edit UI
       
  1033 	 *
       
  1034 	 * @since 0.9.8
       
  1035 	 * @updated 1.3.0
       
  1036 	 *
       
  1037 	 */
       
  1038 	function xili_language_linked_posts() { 
       
  1039 		global $post_ID, $post;
       
  1040 		$update_nonce = wp_create_nonce('oklinked');
       
  1041 		$postlang = '';
       
  1042 		if(0 != $post_ID){
       
  1043 			$ress = wp_get_object_terms($post_ID, TAXONAME);
       
  1044 			$obj_term = $ress[0];
       
  1045 			$postlang = ('' != $obj_term->slug) ? $obj_term->slug : ""; /* when created before plugin */
       
  1046 		} else {
  2255 		} else {
  1047 			$postlang = ""; /* new post */
  2256 			//$showpage = get_option('show_on_front');
  1048 		}
  2257 			if ( !is_admin() && $this->show_page_on_front ) {
  1049 		//$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
  2258 				if ( isset( $_GET[QUETAG]) ) {  // $this_curlang is not yet set
  1050 		$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
  2259 					$curlang = $_GET[QUETAG]; 
  1051 		if ($post->post_type == 'post') { ?>
  2260 				} else {
  1052 			<p><em><?php _e('ID of posts in other languages:','xili-language'); ?></em></p>
  2261 					$curlang = $this->choice_of_browsing_language(); // rule defined in admin UI
  1053 		<?php $theid = 'Post ID';
  2262 				}
  1054 			$autosearchmess = __('to auto search linked posts. (read docs)','xili-language');
  2263 			
  1055 			$post_type = 'post';
  2264 				$trans_id = $this-> linked_post_in( $original_id, $curlang ) ; // get_post_meta($original_id, 'lang-'.$curlang, true);
  1056 		} else {
       
  1057 		?>	<p><em><?php _e('ID of pages in other languages:','xili-language'); ?></em></p>
       
  1058 		<?php $theid = 'Page ID';
       
  1059 			$autosearchmess = __('to auto search linked pages. (read docs)','xili-language');
       
  1060 			$post_type = 'page'; 
       
  1061 		}
       
  1062 		?>
       
  1063 		<table width="100%" cellspacing="4" cellpadding="2">
       
  1064 		<thead>
       
  1065 		<tr ><th><?php _e('Language','xili-language'); ?></th><th align="left"><?php _e($theid,'xili-language'); ?></th><th align="left"><?php _e('Display','xili-language'); ?></th><th align="left"><?php _e('Edit'); ?></th></tr>
       
  1066 		</thead>
       
  1067 		<tbody id='the-linked' class='list:linked'>
       
  1068 			<?php
       
  1069 			if (0 != $post_ID) $autosearch = get_post_meta($post_ID,'_xl-search-linked',true);
       
  1070 			foreach ($listlanguages as $language) {
       
  1071 				$output = "";
       
  1072 				$otherpost = "";
       
  1073 				$line = true;
       
  1074 				if ($language->slug == $postlang ) {
       
  1075 					if ($post->post_status == 'publish' || $post->post_status == 'pending') {
       
  1076 						$line = false;
       
  1077 					} else {
       
  1078 						$line = true;
       
  1079 					}	
       
  1080 				} 
       
  1081 				if ($line) {
       
  1082 					if (0 != $post_ID) {
       
  1083 						$otherpost = get_post_meta($post_ID, QUETAG.'-'.$language->slug, true);
       
  1084 						$otherpostr = $otherpost; 
       
  1085 						/* since 1.3.0 - 1.4.1 */
       
  1086 						if ('' != $autosearch && "" != $postlang) { 
       
  1087 							$source_ID = $this->search_pinger_post($post_ID,QUETAG.'-'.$postlang,$language->term_id, $post_type);
       
  1088 						 	if (0 != $source_ID) { 
       
  1089 						 		$otherpost = $source_ID;
       
  1090 						 		$otherpostr = "-1"; /* to be refreshed */
       
  1091 						 	}	
       
  1092 						}
       
  1093 					} else { /* since 1.3.0 */
       
  1094 						if (isset($_GET['xlfrom_id'])) {
       
  1095 							if ($_GET['xlfrom_lang'] == $language->slug) {
       
  1096 								$otherpost = $_GET['xlfrom_id'];
       
  1097 								$otherpostr = "-1";
       
  1098 							} else {
       
  1099 								/* pre-fill linked posts from source post */
       
  1100 								$otherpost = get_post_meta($_GET['xlfrom_id'], QUETAG.'-'.$language->slug, true);
       
  1101 								$otherpostr = "-1";
       
  1102 							}
       
  1103 						}
       
  1104 					}
       
  1105 				
  2265 				
  1106 				?>
  2266 				if ( '' != $trans_id ) { 
  1107 				<tr ><th>
  2267 					return $trans_id;
  1108 				<label for="xili_language_<?php echo QUETAG.'-'.$language->slug ; ?>"><?php _e($language->description,'xili-language') ; ?>&nbsp;</label></th><td align="left"><input id="xili_language_<?php echo QUETAG.'-'.$language->slug ; ?>" name="xili_language_<?php echo QUETAG.'-'.$language->slug ; ?>"  value="<?php echo $otherpost; ?>" size="5" /><input type="hidden" name="xili_language_rec_<?php echo QUETAG.'-'.$language->slug ; ?>" value="<?php echo $otherpostr; ?>"/>
       
  1109 				
       
  1110 				<?php
       
  1111 				if ('' != $otherpost  ) {
       
  1112 					$output = "</td><td><a target='_blank' href='".get_permalink($otherpost)."' >"." ".__($language->description,'xili-language') ."</a></td><td><a target='_blank' href='post.php?action=edit&post=".$otherpost."' >"." ".__('Edit') ."</a></td></tr>";
       
  1113 				} else {
  2268 				} else {
  1114 					$output = $this->newlinkedpost($postlang, $language->name); /* if possible */
  2269 					return $original_id;	
  1115 				}
  2270 				}
  1116 			}
  2271 			} else {
  1117 				echo $output; 
  2272 				return $original_id;
  1118 			} 
  2273 			}
  1119 			/* since 1.4.1 */
  2274 		}
  1120 			if (0 != $post_ID && "" != $postlang) {
  2275 	}
  1121 			?>	
  2276 	
  1122 			<tr ><th><?php _e('Check','xili-language'); ?></th><td><input id="xili_language_search_lang" name="xili_language_search_lang" type="checkbox" value="searchlinked" <?php if('' != $autosearch) echo 'checked="checked"' ?> /></td><td colspan = 2 ><small><?php echo$autosearchmess ; ?></small></td></tr>
  2277 	/**
  1123 			<?php } ?>
  2278 	 * List custom post types
  1124 				</tbody></table>
  2279 	 *
  1125 			<br /><small>© xili-language</small>
  2280 	 * @since 1.8.0
  1126 			<?php if ($this->post_ajax) { ?>
  2281 	 *
  1127 			<div id='formstatus'></div><span id='loading' class='hidden'><?php _e('Saving...','xili-language') ?></span><span id='loading2' class='hidden'><?php _e('Refreshing...','xili-language') ?></span><div class='submit'>
  2282 	 */
  1128 			<input id='updatelink' name='updatelinked' type='submit' tabindex='6' value='Update' /><small>© xili-language</small></div><?php echo wp_nonce_field( 'oklinked', '_ajax_nonce', true, false );/**/ ?><?php /* echo wp_nonce_field( 'customrefresh', '_ajax_nonce', false, false );*/ ?>
  2283 	function get_custom_desc() {
  1129 			<script  type='text/javascript'>
  2284 		$types = get_post_types(array('show_ui'=>1));
  1130 			<!--
  2285 		if ( count($types) > 2 ) {
  1131 	
  2286 			$thecheck = array() ;
  1132 	jQuery(document).ready(function(){
  2287 			$thecustoms = array();
  1133 		jQuery('#updatelink').click(function() { //start function when Random button is clicked
  2288 			
  1134 			jQuery.ajax({
  2289 			foreach ( $types as $type) {
  1135 				type: "post",url: "admin-ajax.php",
  2290 				$true = ( defined ('XDMSG') ) ? ( $type != XDMSG ) : true ;
  1136 				data: {
  2291 				if ( $type != 'page' && $type != 'post' && $true == true ) {
  1137 					action: 'oklinked', 
  2292 					$custom = get_post_type_object ($type);
  1138 					<?php
  2293 					$clabels = $custom->labels;
  1139 					foreach ($listlanguages as $language) {
  2294 					$thecustoms[$type] = array ('name' => $custom->label, 'singular_name' => $clabels->singular_name, 'multilingual'=>''  ) ;
  1140 						echo "xili_language_".$language->slug.": "."escape( jQuery( '#"."xili_language_".QUETAG."-".$language->slug."' ).val()),";	
       
  1141 					}
       
  1142 					echo "post_id: '".$post_ID."',";	
       
  1143 					?>
       
  1144 					_ajax_nonce: '<?php echo $update_nonce; ?>' 
       
  1145 					},
       
  1146 				beforeSend: function() {jQuery("#loading").fadeIn('fast');jQuery("#formstatus").fadeIn("fast");}, //when link is clicked
       
  1147 				success: function(html){ //so, if data is retrieved, store it in html
       
  1148 					jQuery("#loading").fadeOut('slow');
       
  1149 					jQuery("#formstatus").html( html );
       
  1150 					jQuery.ajax({ // refresh custom fields list
       
  1151 						type: "post",url: "admin-ajax.php",
       
  1152 					 	data: {
       
  1153 					 	action: 'customrefresh',
       
  1154 					 	<?php
       
  1155 							echo "post_id: '".$post_ID."',"; ?>
       
  1156 					 	_ajax_nonce: '<?php echo $update_nonce; ?>' 
       
  1157 					 	},
       
  1158 					 	beforeSend: function() {jQuery("#loading2").fadeIn('fast');},
       
  1159 						success: function(html){
       
  1160 					 	jQuery("#the-list").html( html );
       
  1161 					 	jQuery("#loading2").fadeOut('slow');
       
  1162 					 	}		
       
  1163 			 });
       
  1164 				}
  2295 				}
  1165 			}); //close jQuery.ajax
  2296 			}
  1166 			return false;
  2297 			return $thecustoms ;
  1167 		})
  2298 		}
  1168 	})
  2299 	}
  1169 	-->
  2300 	
  1170 	</script><?php }
  2301 	/**
  1171 	}
  2302 	 * unassign a language from a series of objects (post or link)
  1172 	/**
  2303 	 * @since 1.8.8
  1173 	 * to create a linked post in target language
  2304 	 *
  1174 	 *
  2305 	 *
  1175 	 * @since 1.3.0
  2306 	 */
  1176 	 * @updated 1.3.1 - Add New specific for pages
  2307 	function multilingual_links_erase ( $lang_term_id ) {
  1177 	 *
  2308 		$languages = $this -> get_listlanguages();
  1178 	 */
  2309 		
  1179 	function newlinkedpost($postlang = "" , $targetlang = "") {
  2310 		foreach ($languages as $language ) {
  1180 		global $post;
  2311 			if ( $language->term_id == $lang_term_id ) { 
  1181 		$whatnew = ($post->post_type == 'post') ? 'post' : 'page';	
  2312 				$lang_slug = $language->slug ;
  1182 		if ($post->post_status == 'publish' || $post->post_status == 'pending' || $post->post_status == 'draft') {
  2313 				continue ;
  1183 			if ($postlang != strtolower($targetlang)) {
  2314 			}
  1184 			return "</td><td><small>".__('*','xili-language')."</small></td><td><a href='".$whatnew."-new.php?xlfrom_id=".$post->ID."&xlfrom_lang=".$postlang."&xltgt_lang=".$targetlang."' target='_blank' >".__('Add New')."</a></td><tr>";
  2315 		}
  1185 			}
  2316 		foreach ($languages as $language ) {
  1186 		} else {
  2317 			// for other languages as this - delete postmeta linked to post of erased posts
  1187 			return "</td></tr>";
  2318 			if ( $language->term_id != $lang_term_id) {
  1188 		}
  2319 				$post_IDs = get_objects_in_term( array( $language->term_id ), array( TAXONAME ) );
  1189 	}
  2320 				foreach ( $post_IDs as $post_ID ) {
  1190 	
  2321 						delete_post_meta( $post_ID, QUETAG.'-'.$lang_slug ) ;
  1191 	/**
  2322 				}			
  1192 	 * to research post linking current post in the language
  2323 			}
  1193 	 * @since 1.4.1
  2324 		}
  1194 	 * @params ID of post, lang of this post as meta_key, lang of searched pinger post, type of post (page)
  2325 		// posts
  1195 	 *
  2326 		$post_IDs = get_objects_in_term( array( $lang_term_id ), array( TAXONAME ) );
  1196 	 */
  2327 		foreach ( $post_IDs as $post_ID ) {
  1197 	function search_pinger_post ($targetID,$langmeta,$pingerlang,$posttype) {
  2328 			// delete relationships posts
  1198 		global $wpdb;
  2329 	 		wp_delete_object_term_relationships( $post_ID, TAXONAME );
  1199 		
  2330 		}
  1200 		$query = "SELECT ID FROM $wpdb->posts as pp LEFT JOIN $wpdb->postmeta as pm ON (pp.ID = pm.post_id) LEFT JOIN $wpdb->term_relationships as tr ON (pp.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE 1=1 AND pm.meta_key = '$langmeta' AND pm.meta_value = '$targetID' AND pp.post_type = '$posttype' AND (pp.post_status IN ('publish','private','draft','pending')) AND tt.taxonomy = 'language' AND tt.term_id = $pingerlang ORDER BY pp.post_date DESC LIMIT 0, 1";
  2331 		// links of blogroll
  1201 		//echo $query;
  2332 		$links = get_objects_in_term( array( $lang_term_id ), array( 'link_'.TAXONAME ) );
  1202 		$r = @$wpdb->get_col($query);
  2333 		foreach ( $links as $link ) {	   
  1203 		//print_r($r);
  2334 			wp_delete_object_term_relationships( $link, 'link_'.TAXONAME );
  1204 		if (!empty($r)) {
  2335 		}
  1205 			$id = $r[0]; /* if multiple take the most recent */
  2336 	}
  1206 		} else {
  2337 			
  1207 		 	$id = 0;	
  2338 	
  1208 		}
  2339 		
  1209 //echo '->'.$id.$langmeta.$targetID.'</br>'; 
       
  1210 		return $id;
       
  1211 	}
       
  1212 	/* obsolete */
       
  1213 	function custom_refresh() {
       
  1214 		check_ajax_referer( "oklinked" );
       
  1215 		$post_ID = $_POST['post_id'];
       
  1216 		$count = 0;
       
  1217 		$metadata = has_meta($post_ID);
       
  1218 		$list ="";
       
  1219 		$output = '';//<tr><td>Refreshed by xili-language</td></tr>';
       
  1220 		if ($metadata)
       
  1221 			foreach ( $metadata as $entry ) { $list .= _list_meta_row( $entry, $count );}
       
  1222 		$output .= $list;
       
  1223 		echo $output."<!--- end updated by xili-language -->";
       
  1224 		die();
       
  1225 	}
       
  1226 	
       
  1227 	function ok_linked() {
       
  1228 		check_ajax_referer( "oklinked" );
       
  1229 		
       
  1230 		$post_ID = $_POST['post_id'];
       
  1231 				
       
  1232 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
       
  1233 			$linked = array ();
       
  1234 			foreach ($listlanguages as $language) {
       
  1235 				$key = $language->slug;
       
  1236 				$linked[$key] = $_POST['xili_language_'.$key];
       
  1237 				$linkid = $linked[$key];
       
  1238 				//$reclinkid = $_POST[$recinputid]; /* hidden previous value */
       
  1239 				$langslug = QUETAG.'-'.$key ;
       
  1240 				//if ($reclinkid != $linkid) { /* only if changed value */
       
  1241 					if ((is_numeric($linkid) && $linkid == 0) || '' == $linkid ) {
       
  1242 						delete_post_meta($post_ID, $langslug);
       
  1243 					} elseif (is_numeric($linkid) && $linkid > 0) {
       
  1244 						update_post_meta($post_ID, $langslug, $linkid);
       
  1245 						$mess .= " ".$key;	
       
  1246 					}
       
  1247 			}
       
  1248 			echo '<p>All is OK '.$post_id.' ('.$mess.')</p>'; // voir bannière //
       
  1249 			die();
       
  1250 		
       
  1251 	}
       
  1252 		
       
  1253 	/**
       
  1254 	 * to display the languages settings admin UI
       
  1255 	 *
       
  1256 	 * @since 0.9.0
       
  1257 	 * @updated 0.9.6 - only for WP 2.7.X - do new meta boxes and JS
       
  1258 	 *
       
  1259 	 */
       
  1260 	function languages_settings() { 
       
  1261 		$formtitle = 'Add a language'; /* translated in form */
       
  1262 		$submit_text = __('Add &raquo;','xili-language');
       
  1263 		$cancel_text = __('Cancel');
       
  1264 		
       
  1265 		if (isset($_POST['reset'])) {
       
  1266 			$action=$_POST['reset'];
       
  1267 		} elseif (isset($_POST['updateoptions'])) {
       
  1268 			$action='updateoptions';
       
  1269 		} elseif (isset($_POST['updateundefined'])) {
       
  1270 			$action='updateundefined';
       
  1271 			
       
  1272 		} elseif (isset($_POST['action'])) {
       
  1273 			$action=$_POST['action'];
       
  1274 		}
       
  1275 		
       
  1276 		if (isset($_GET['action'])) :
       
  1277 			$action=$_GET['action'];
       
  1278 			$term_id = $_GET['term_id'];
       
  1279 		endif;
       
  1280 		$message = $action ;
       
  1281 		switch($action) {
       
  1282 			case 'updateundefined';
       
  1283 				$targetlang = $_POST['xili_language_toset'];
       
  1284 				$fromcats = $_POST['from_categories'];
       
  1285 				if (""!= $targetlang) {
       
  1286 					$q = xiliml_setlang_of_undefined_posts ($targetlang, $fromcats, 50);
       
  1287 					$message .= " _ $q ".__('posts are set in:','xili-language')." ".$targetlang." ".__("category")." =[$fromcats]";
       
  1288 				} else {
       
  1289 					$q = xiliml_setlang_of_undefined_posts ($targetlang, $fromcats, 50);
       
  1290 					$message .= " _ around $q ".__('posts are undefined in','xili-language')." ".__("category")."  = [$fromcats]";	
       
  1291 				}
       
  1292 				$actiontype = "reset";
       
  1293 				break;
       
  1294 			case 'updateoptions';
       
  1295 				$this->browseroption = $_POST['xili_language_check_option'];
       
  1296 				$this->authorbrowseroption = $_POST['xili_language_check_option_author'];
       
  1297 				$this->functions_enable = $_POST['xili_language_check_functions_enable'];
       
  1298 				$this->xili_settings['browseroption'] = $this->browseroption;
       
  1299 				$this->xili_settings['authorbrowseroption'] = $this->authorbrowseroption;
       
  1300 				$this->xili_settings['functions_enable'] = $this->functions_enable; 
       
  1301 				
       
  1302 				$this->xili_settings['homelang'] = $_POST['xili_language_home_lang']; // 1.3.2 
       
  1303 				
       
  1304 				update_option('xili_language_settings', $this->xili_settings);
       
  1305 				$message .= " - ".__('Option is updated.','xili-language')." (=> ".$this->browseroption.") (".$this->authorbrowseroption.") (".$this->functions_enable.")";
       
  1306 				$this->insert_gold_functions (); 
       
  1307 				$actiontype = "reset";
       
  1308 				break;
       
  1309 		
       
  1310 			case 'add':
       
  1311 				$term = $_POST['language_name'];
       
  1312 				$args = array( 'alias_of' => '', 'description' => $_POST['language_description'], 'parent' => 0, 'slug' =>$_POST['language_nicename']);
       
  1313 			    $theids = wp_insert_term( $term, TAXONAME, $args);
       
  1314 			    wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
  1315 			    update_term_order ($theids['term_id'],$this->langs_group_tt_id,$_POST['language_order']);
       
  1316 			    $actiontype = "add";
       
  1317 			    $message .= " - ".__('A new language was added.','xili-language');
       
  1318 			     break;
       
  1319 			    
       
  1320 			case 'edit';
       
  1321 			    $actiontype = "edited";
       
  1322 			    //echo $term_id;
       
  1323 			    //$language = get_term($term_id,TAXONAME,OBJECT,'edit');
       
  1324 			    $language = get_term_and_order ($term_id,$this->langs_group_tt_id,TAXONAME);
       
  1325 			    $submit_text = __('Update &raquo;');
       
  1326 			    $formtitle = 'Edit language';
       
  1327 			    $message .= " - ".__('Language to update.','xili-language');
       
  1328 			    break;
       
  1329 			    
       
  1330 			case 'edited';
       
  1331 			    $actiontype = "add";
       
  1332 			    $term = $_POST['language_term_id'];
       
  1333 			    
       
  1334 				$args = array( 'alias_of' => '', 'description' => $_POST['language_description'], 'parent' => 0, 'slug' =>$_POST['language_nicename']);
       
  1335 				$theids = wp_update_term( $term, TAXONAME, $args);
       
  1336 				wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
  1337 				update_term_order ($theids['term_id'],$this->langs_group_tt_id,$_POST['language_order']);
       
  1338 				$message .= " - ".__('A language was updated.','xili-language');
       
  1339 				
       
  1340 			    break;
       
  1341 			    
       
  1342 			case 'delete';
       
  1343 			    $actiontype = "deleting";
       
  1344 			    $submit_text = __('Delete &raquo;','xili-language');
       
  1345 			    $formtitle = 'Delete language ?';
       
  1346 			    //$language = get_term($term_id,TAXONAME,OBJECT,'edit');
       
  1347 			    $language = get_term_and_order ($term_id,$this->langs_group_tt_id,TAXONAME);
       
  1348 			    $message .= " - ".__('A language to delete.','xili-language');
       
  1349 			    
       
  1350 			    break;
       
  1351 			    
       
  1352 			case 'deleting';
       
  1353 			    $actiontype = "add";
       
  1354 			    $term = $_POST['language_term_id'];
       
  1355 			    wp_delete_object_term_relationships( $term, TAXOLANGSGROUP );
       
  1356 			    wp_delete_term( $term, TAXONAME, $args);
       
  1357 			    $message .= " - ".__('A language was deleted.','xili-language');
       
  1358 			    break; 
       
  1359 			case 'reset';    
       
  1360 			    $actiontype = "add";
       
  1361 			    break;
       
  1362 			default :
       
  1363 			    $actiontype = "add";
       
  1364 			    $message .= __('Find above the list of languages.','xili-language');
       
  1365 			    
       
  1366 			    
       
  1367 		}
       
  1368 		/* register the main boxes always available */
       
  1369 		add_meta_box('xili-language-normal-1', __('List of languages','xili-language'), array(&$this,'on_normal_1_content'), $this->thehook , 'normal', 'core'); 
       
  1370 		add_meta_box('xili-language-normal-2', __('Language','xili-language'), array(&$this,'on_normal_2_content'), $this->thehook , 'normal', 'core');
       
  1371 		add_meta_box('xili-language-sidebox-3', __('Settings','xili-language'), array(&$this,'on_sidebox_3_content'), $this->thehook , 'side', 'core');
       
  1372 		
       
  1373 		/* form datas in array for do_meta_boxes() */
       
  1374 		$data = array('message'=>$message,'messagepost'=>$messagepost,'action'=>$action, 'formtitle'=>$formtitle, 'language'=>$language,'submit_text'=>$submit_text,'cancel_text'=>$cancel_text,'browseroption'=>$this->browseroption, 'authorbrowseroption'=>$this->authorbrowseroption , 'functions_enable'=>$this->functions_enable);
       
  1375 		?>
       
  1376 		
       
  1377 		<div id="xili-language-settings" class="wrap" style="min-width:750px">
       
  1378 			<?php screen_icon('options-general'); ?>
       
  1379 			<h2><?php _e('Languages','xili-language') ?></h2>
       
  1380 			<form name="add" id="add" method="post" action="options-general.php?page=language_page">
       
  1381 				<input type="hidden" name="action" value="<?php echo $actiontype ?>" />
       
  1382 				<?php wp_nonce_field('xili-language-settings'); ?>
       
  1383 				<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
       
  1384 				<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); 
       
  1385 				/* 0.9.9.2 add has-right-sidebar for next wp 2.8*/ ?>
       
  1386 				<div id="poststuff" class="metabox-holder has-right-sidebar">
       
  1387 					<div id="side-info-column" class="inner-sidebar">
       
  1388 						<?php do_meta_boxes($this->thehook, 'side', $data); ?>
       
  1389 					</div>
       
  1390 				
       
  1391 					<div id="post-body" class="has-sidebar has-right-sidebar">
       
  1392 						<div id="post-body-content" class="has-sidebar-content" style="min-width:360px">
       
  1393 					
       
  1394 	   					<?php do_meta_boxes($this->thehook, 'normal', $data); ?>
       
  1395 						</div>
       
  1396 					<h4><a href="http://dev.xiligroup.com/xili-language" title="Plugin page and docs" target="_blank" style="text-decoration:none" ><img style="vertical-align:middle" src="<?php echo WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)).'/xililang-logo-32.gif'; ?>" alt="xili-language logo"/>  xili-language</a> - © <a href="http://dev.xiligroup.com" target="_blank" title="<?php _e('Author'); ?>" >xiligroup.com</a>™ - msc 2007-9 - v. <?php echo XILILANGUAGE_VER; ?></h4>		
       
  1397 					</div>
       
  1398 				</div>
       
  1399 		</form>
       
  1400 		</div>
       
  1401 		<script type="text/javascript">
       
  1402 			//<![CDATA[
       
  1403 			jQuery(document).ready( function($) {
       
  1404 				// close postboxes that should be closed
       
  1405 				$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
       
  1406 				// postboxes setup
       
  1407 				postboxes.add_postbox_toggles('<?php echo $this->thehook; ?>');
       
  1408 			});
       
  1409 			//]]>
       
  1410 		</script> 
       
  1411 	<?php	//end settings div
       
  1412 		}
       
  1413 	
       
  1414 		//* display xililanguage in lists *//
       
  1415 	function xili_manage_column($name, $id) {
       
  1416 			if($name != TAXONAME)
       
  1417 				return;
       
  1418 			$terms = wp_get_object_terms($id, TAXONAME);
       
  1419 			$first = true;
       
  1420 			foreach($terms AS $term) {
       
  1421 				if($first)
       
  1422 					$first = false;
       
  1423 				else
       
  1424 					echo ', ';
       
  1425 				echo '<a href="' . 'options-general.php?page=language_page'.'">'; /* see more precise link ?*/
       
  1426 				echo $term->name;
       
  1427 				echo '</a>';
       
  1428 			}
       
  1429 		}
       
  1430 	function xili_manage_column_name($cols) {
       
  1431 			$ends = array('comments', 'date', 'rel', 'visible');
       
  1432 			$end = array();
       
  1433 			foreach($cols AS $k=>$v) {
       
  1434 				if(in_array($k, $ends)) {
       
  1435 					$end[$k] = $v;
       
  1436 					unset($cols[$k]);
       
  1437 				}
       
  1438 			}
       
  1439 			$cols[TAXONAME] = __('Language','xili-language');
       
  1440 			$cols = array_merge($cols, $end);
       
  1441 			return $cols;
       
  1442 		}
       
  1443 
       
  1444 	/**
  2340 	/**
  1445 	 * Set language plugin 
  2341 	 * Set language plugin 
  1446 	 * 
  2342 	 * 
  1447 	 *
  2343 	 *
  1448 	 * @updated 1.1.9
  2344 	 * @updated 1.1.9
  1449 	 * also include automatic search of domain and lang subfolder in current theme
  2345 	 * also include automatic search of domain and lang subfolder in current theme
  1450 	 */
  2346 	 */
  1451 	function init_textdomain() {
  2347 	function init_textdomain() {
  1452 	/*multilingual for admin pages and menu*/
  2348 	/*multilingual for admin pages and menu*/
  1453 		load_plugin_textdomain('xili-language',PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
  2349 		load_plugin_textdomain('xili-language', false, 'xili-language/languages' );
  1454 		if (!defined('THEME_TEXTDOMAIN')) { 
  2350 		
  1455 			if ($this->xili_settings['theme_domain'] != "") {
  2351 		/* in wp3 multisite - don't use constant - for backward compatibility keep it in mono*/			
  1456 				define('THEME_TEXTDOMAIN',$this->xili_settings['theme_domain']);
  2352 		if ( '' != $this->xili_settings['theme_domain'] ) { 
       
  2353 			if (!is_multisite() && !defined('THEME_TEXTDOMAIN') ) define('THEME_TEXTDOMAIN',$this->thetextdomain); // for backward compatibility;
       
  2354 			if ( is_admin() ) {
  1457 				
  2355 				
  1458 			} else { /* search it inside theme folder index.php */
  2356 				$this->thetextdomain = $this->xili_settings['theme_domain'] ; 
  1459 				if( is_file( get_template_directory().'/index.php') )  { 
  2357 				update_option('xili_language_settings', $this->xili_settings); 
  1460 					$lines = @file( get_template_directory().'/index.php'); 
  2358 				
  1461 					foreach ($lines as $line) { 
  2359 			}
  1462 						$i = preg_match_all("/_[_e]\('(.*)', ?'(.*)'/Ui", $line, $matches,PREG_PATTERN_ORDER);
  2360 		} else {
  1463 	 					if ($i > 0) { 
  2361 			$this->domaindetectmsg = __('no load_theme_textdomain in functions.php','xili-language');
  1464 							$resultterms = array_merge ($resultterms, $matches[1]);
  2362 		}
  1465 							//print_r($matches[1]);
  2363 		
  1466 							//print_r($matches[2]);
  2364 	}
  1467 							$domain = $matches[2][0];
  2365 	
  1468 							$this->xili_settings['theme_domain'] = $domain;
  2366 	function searchpath( $path, $filename ) {
  1469 							update_option('xili_language_settings', $this->xili_settings);
  2367 		$this->xili_settings['langs_folder'] = str_replace($this->get_template_directory,'',$path);
  1470 							define('THEME_TEXTDOMAIN',$this->xili_settings['theme_domain']);
  2368 	}
  1471 							break; 
  2369 	
  1472 						}
       
  1473 			 		}
       
  1474 			 		if ($domain == "")
       
  1475 			 			_e('no theme domain in index.php','xili-language');
       
  1476 				} else {
       
  1477 					_e('no index.php in theme, domain not set','xili-language');
       
  1478 				}
       
  1479 			}	
       
  1480 		}
       
  1481 		if (!defined('THEME_LANGS_FOLDER')) { /* set or detect */
       
  1482 			if ($this->xili_settings['langs_folder'] == "") {
       
  1483 				$this->find_files(get_template_directory(), '/.mo$/', array(&$this,'searchpath'));
       
  1484 				update_option('xili_language_settings', $this->xili_settings);
       
  1485 			}
       
  1486 			
       
  1487 			define('THEME_LANGS_FOLDER',$this->xili_settings['langs_folder']); // for bkwd compatibility with xili-dictionary
       
  1488 		}
       
  1489 	}
       
  1490 	function searchpath($path, $filename) {
       
  1491 		$this->xili_settings['langs_folder'] = str_replace(get_template_directory(),'',$path);
       
  1492 	}
       
  1493 	/**
  2370 	/**
  1494 	 * Reset values when theme was changed... updated by previous function
  2371 	 * Reset values when theme was changed... updated by previous function
  1495 	 * @since 1.1.9
  2372 	 * @since 1.1.9
  1496 	 */ 
  2373 	 */ 
  1497 	function theme_switched ($theme) {
  2374 	function theme_switched ( $theme ) { 
  1498 		$this->xili_settings['langs_folder'] ="";
  2375 		$this->xili_settings['langs_folder'] ="";
  1499 		$this->xili_settings['theme_domain'] =""; /* to force future search in new theme */
  2376 		$this->xili_settings['theme_domain'] ="";   /* to force future search in new theme */
  1500 		update_option('xili_language_settings', $this->xili_settings);
  2377 		update_option('xili_language_settings', $this->xili_settings); 
  1501 	}
  2378 	}
  1502 	
  2379 	
  1503 	/**
  2380 	/**
  1504 	 * private functions for languages_settings 
  2381 	 * to add links in current menu of twentyten
  1505 	 * @since 0.9.6
  2382 	 *
  1506 	 *
       
  1507 	 * fill the content of the boxes (right side and normal)
       
  1508 	 * 
  2383 	 * 
  1509 	 */
  2384 	 *
  1510 	function  on_sidebox_1_content($data) { 
  2385 	 */
  1511 		extract($data);
  2386 	function add_list_of_language_links_in_wp_menu ( $location ) {
  1512 		?>
  2387 		$defaultarray = array(
  1513 	 	<h4><?php _e('Note:','xili-language') ?></h4>
  2388 			'menu-item-type' => 'custom',
  1514 		<p><?php echo $message;?></p>
  2389 			'menu-item-title' => '',
  1515 		<?php
  2390 			'menu-item-url' => '',
  1516 	}
  2391 			'menu-item-description' => '',
  1517 	
  2392 			'menu-item-status' => 'publish');
  1518 	function  on_sidebox_2_content() { ?>
  2393 		$url = get_bloginfo('url') ;
  1519 	 	
  2394 		$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
  1520 		<p><?php _e("This plugin was developed with the taxonomies, terms tables and tags specifications. <br /> Here a new taxonomy was created and used for languages of posts and pages. <br /> New radiobuttons are available in Post (and Page) write and edit admin pages for selection by author. It is updated for WP 2.9 since 1.1",'xili-language') ?></p>
  2395 		$langdesc_array = array();
  1521 		<?php
  2396 		foreach ($listlanguages as $language){
  1522 	}	
  2397 			$langdesc_array[] = $language->description;
  1523 	
  2398 		}
  1524 	function  on_sidebox_3_content($data) { /* where to choose if browser language preferences is tested or not */
  2399 		/* detect menu inside location */
  1525 		extract($data);
  2400 		$menu_locations =  get_nav_menu_locations();
  1526 		$update_nonce = wp_create_nonce('xilimloptions');
  2401 		$menuid = $menu_locations[$location];
  1527 		/* 1.0 browser - default - languages */
  2402 		$menuitem = wp_get_nav_menu_object($menuid);
  1528 		?>
  2403 		$items = get_objects_in_term( $menuitem->term_id, 'nav_menu' );
  1529 		<fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"><legend><?php echo _e('Select language of the home page', 'xili-language'); ?></legend>
  2404 		$nothere = true;
  1530 			<select name="xili_language_check_option" id="xili_language_check_option" style="width:100%;">
  2405 		if ( ! empty( $items ) ) {
  1531 				<?php  if ($browseroption == 'browser')
  2406 			$founditems = wp_get_nav_menu_items($menuid); //try to see if a previous insert was done
  1532 						$checked = 'selected = "selected"';
  2407 			foreach ($founditems as $item) {
  1533 						else 
  2408 		 		if ($item->title =='|' || in_array($item->title, $langdesc_array)) {
  1534 						$checked = '';
  2409 		 			$nothere = false;
  1535 				?>
  2410 		 			break;
  1536 				<option value="" ><?php _e('Software defined','xili-language'); ?></option>
  2411 		 		}
  1537 				<option value="browser" <?php echo $checked; ?> ><?php _e("Language of visitor's browser",'xili-language'); ?></option>
  2412 		 	}
  1538 				<?php $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
  2413 		}
  1539 			foreach ($listlanguages as $language) {
  2414 		if ($nothere == true) {
  1540 				if ($browseroption == $language->slug) 
  2415 			/* add separator */
  1541 						$checked = 'selected = "selected"';
  2416 				$defaultarray['menu-item-title'] = '|';
  1542 					else 
  2417 				$defaultarray['menu-item-url'] = $url.'/#';
  1543 						$checked = '';
  2418 				wp_update_nav_menu_item($menuid,0,$defaultarray);
  1544 				echo '<option value="'.$language->slug.'" '.$checked.' >'.__($language->description,'xili-language').'</option>';
  2419 			foreach ($listlanguages as $language){
  1545 			}
  2420 				$defaultarray['menu-item-title'] = $language->description ;
  1546 				?>
  2421 				$defaultarray['menu-item-url'] = $url.'/?lang='.$language->slug ;
  1547 			</select>
  2422 				wp_update_nav_menu_item($menuid,0,$defaultarray);
  1548 			<?php  if ('page' != get_settings('show_on_front')) { ?>
  2423 			}
  1549 				<br /> &nbsp;&nbsp;<label for="xili_language_home_lang"><?php _e('Modify home query','xili-language') ?> <input id="xili_language_home_lang" name="xili_language_home_lang" type="checkbox" value="modify" <?php if($this->xili_settings['homelang'] == 'modify') echo 'checked="checked"' ?> /></label>
  2424 			return __("language items added","xili-language");
  1550 				<?php }  ?>
  2425 		} else {
  1551 	
  2426 			return __("seems to be set","xili-language");
  1552 	
  2427 		}
  1553 		</fieldset>
  2428 	}
  1554 		<br /><br />
  2429 	
  1555 		<label for="xili_language_check_option_author" class="selectit"><input id="xili_language_check_option_author" name="xili_language_check_option_author" type="checkbox" value="authorbrowser"  <?php if($authorbrowseroption=='authorbrowser') echo 'checked="checked"' ?> /> <?php echo _e('For new post, pre-select by default: browser language of author', 'xili-language'); ?></label>
  2430 	/**
  1556 		<br /><br />
  2431 	 * ***** Functions to improve bookmarks language filtering *****
  1557 		<?php if (file_exists(XILIFUNCTIONSPATH)) { /* test if folder exists - ready to add functions.php inside - since 1.0 */?>
  2432 	 * 
  1558 		<label for="xili_language_check_functions_enable" class="selectit"><input id="xili_language_check_functions_enable" name="xili_language_check_functions_enable" type="checkbox" value="enable"  <?php if($functions_enable =='enable') echo 'checked="checked"' ?> /> <?php echo _e('Enable gold functions', 'xili-language'); ?></label>
  2433 	 */
  1559 		<?php } else {	
  2434 	
  1560 		echo '<input type="hidden" name="xili_language_check_functions_enable" value="'.$functions_enable.'" />';
  2435 	/**
  1561 		} ?>		
  2436 	 * Filter to widget_links parameter
  1562 	 	<div id='formstatus'></div><span id='loading' class='hidden'><?php _e('Updating...','xili-language') ?></span><div class='submit'>
  2437 	 * @ since 1.8.5
  1563 		<input id='updateoptions' name='updateoptions' type='submit' tabindex='6' value="<?php _e('Update','xili-language') ?>" /></div>
  2438 	 */
  1564 		<?php echo wp_nonce_field( 'xilimloptions', '_ajax_nonce', true, false );/**/ ?>
  2439 	function widget_links_args_and_lang ($widget_args) {
  1565 		<div style="clear:both; height:1px"></div><?php
  2440 		
  1566 	}
  2441 		$cur_lang = $this->curlang;
  1567 	
  2442 		// rules depending category and settings in xili-language
  1568 	function  on_sidebox_4_content() { 
  2443 		$cat_settings = $this->xili_settings['link_categories_settings'] ; //array ( 'all'=> true, 'category' => array ( '2' => false , '811' => true ) );
  1569 	 	$update_nonce = wp_create_nonce('xilimloptions');
  2444 		$sub_select = false; 
  1570 	 	?>
  2445 		if ( $widget_args['category'] ) {
  1571 	 	<fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"><legend><?php echo __("Theme's informations:",'xili-language').' ('.get_option("template").')'; ?></legend>
  2446 			$sub_select = $cat_settings['category'][$widget_args['category']] ;
  1572 	 	<p><?php 
  2447 		} else {
  1573 	 	if (defined('THEME_TEXTDOMAIN')) {
  2448 			$sub_select = $cat_settings['all'];
  1574 	 		echo __('theme_domain:','xili-language').' '.THEME_TEXTDOMAIN.'<br />'.__('as function like:','xili-language').'<i> _e(\'-->\',\''.THEME_TEXTDOMAIN.'\');</i>'; }
  2449 			// if ( $sub_select ) $widget_args['categorize'] = 0;
  1575 	 		else {
  2450 		}
  1576 	 			_e('Theme domain NOT defined','xili-language');
  2451 		
  1577 	 		} ?><br />
  2452 		if ( $sub_select ) {	
  1578 	 	<?php echo __("Languages sub-folder:",'xili-language').' '.$this->xili_settings['langs_folder']; ?><br />
  2453 			$linklang = term_exists($cur_lang,'link_'.TAXONAME) ;
  1579 	 	<?php _e('Available MO files:','xili-language'); echo '<br />';
  2454 			$linklang_ever = term_exists('ev_er','link_'.TAXONAME) ; // the dummy lang - shown ever with selected language
  1580 	 	$this->find_files(get_template_directory(), "/.mo$/", array(&$this,"available_mo_files")) ;?>
  2455 			if ( $cur_lang && $linklang ) {
  1581 	 	</p>
  2456 				if ( $widget_args['category'] ) {
  1582 	 	</fieldset>
  2457 					$cat = get_term( $widget_args['category'], 'link_category' );
  1583 		<p><?php _e("Special Gold Actions",'xili-language') ?></p>
  2458 					$catname = apply_filters( "link_category", $cat->name );
  1584 		
  2459 				}	
  1585 		<?php
  2460 				$the_link_ids = array ();
  1586 		//echo  '---'.$this->functions_enable;
       
  1587 		if ($this->functions_enable !='' && function_exists('xiliml_setlang_of_undefined_posts')) {
       
  1588 			xiliml_special_UI_undefined_posts ($this->langs_group_id);
       
  1589 		}
       
  1590 	}
       
  1591 
       
  1592 	function on_normal_1_content($data) { 
       
  1593 		extract($data); ?>
       
  1594 		<?php //if (!isset($action) || $action=='add' || $action=='edited' || $action=='deleting') :?>
       
  1595 					<table class="widefat">
       
  1596 						<thead>
       
  1597 						<tr>
       
  1598 						<th scope="col" style="text-align: center"><?php _e('ID') ?></th>
       
  1599 	        			<th scope="col"><?php _e('Name','xili-language') ?></th>
       
  1600 	        			<th scope="col"><?php _e('Full name','xili-language') ?></th>
       
  1601 	        			<th scope="col"><?php _e('Language slug','xili-language') ?></th>
       
  1602 	        			<th scope="col"><?php _e('Order','xili-language') ?></th>
       
  1603 	        			<th scope="col" width="90" style="text-align: center"><?php _e('Posts') ?></th>
       
  1604 	        			<th colspan="2" style="text-align: center"><?php _e('Action') ?></th>
       
  1605 						</tr>
       
  1606 						</thead>
       
  1607 						<tbody id="the-list">
       
  1608 							<?php $this->xili_lang_row(); /* the lines */?>
       
  1609 						</tbody>
       
  1610 					</table>
       
  1611 					<?php if ($action=='edit' || $action=='delete') :?>
       
  1612 					<p>(<a href="?action=add&page=language_page"><?php _e('Add a language','xili-language') ?></a>)</p>
       
  1613 	   				<?php endif; ?>	
       
  1614 	<?php	
       
  1615 	}	
       
  1616 	
       
  1617 	function on_normal_2_content($data) { 
       
  1618 		extract($data);
       
  1619 	 /* the create - edit - delete form */ ?>
       
  1620 		
       
  1621 		<h2 id="addlang" <?php if ($action=='delete') echo 'style="color:#FF1111;"'; ?>><?php _e($formtitle,'xili-language') ?></h2>
       
  1622 		<?php if ($action=='edit' || $action=='delete') :?>
       
  1623 			<input type="hidden" name="language_term_id" value="<?php echo $language->term_id ?>" />
       
  1624 		<?php endif; ?>
       
  1625 		<table class="editform" width="100%" cellspacing="2" cellpadding="5">
       
  1626 			<tr>
       
  1627 				<th width="33%" scope="row" valign="top" align="right"><label for="language_name"><?php _e('Name') ?></label>:&nbsp;</th>
       
  1628 				<td width="67%"><input name="language_name" id="language_name" type="text" value="<?php echo attribute_escape($language->name); ?>" size="40" <?php if($action=='delete') echo 'disabled="disabled"' ?> /></td>
       
  1629 			</tr>
       
  1630 			<tr>
       
  1631 				<th scope="row" valign="top" align="right"><label for="language_nicename"><?php _e('Language slug','xili-language') ?></label>:&nbsp;</th>
       
  1632 				<td><input name="language_nicename" id="language_nicename" type="text" value="<?php echo attribute_escape($language->slug); ?>" size="40" <?php if($action=='delete') echo 'disabled="disabled"' ?> /></td>
       
  1633 			</tr>
       
  1634 			<tr>
       
  1635 				<th scope="row" valign="top" align="right"><label for="language_description"><?php _e('Full name','xili-language') ?></label>:&nbsp;</th>
       
  1636 				<td><input name="language_description" id="language_description" size="40" value="<?php echo $language->description; ?>" <?php if($action=='delete') echo 'disabled="disabled"' ?> /></td>
       
  1637 				
  2461 				
  1638 			</tr>
  2462 				$the_link_ids_cat = get_objects_in_term( array( $widget_args['category'] ), 'link_category' ) ; 
  1639 			<tr>
  2463 				$the_link_ids = get_objects_in_term( array( $linklang['term_id'], $linklang_ever['term_id'] ), 'link_'.TAXONAME ) ; // lang + ever
  1640 				<th scope="row" valign="top" align="right"><label for="language_order"><?php _e('Order','xili-language') ?></label>:&nbsp;</th>
  2464 				$the_link_ids_all = array_intersect ($the_link_ids , $the_link_ids_cat ); 
  1641 				<td><input name="language_order" id="language_order" size="3" value="<?php echo $language->term_order; ?>" <?php if($action=='delete') echo 'disabled="disabled"' ?> /></td>
  2465 				if ( $widget_args['category'] ) $widget_args['categorize'] = 0; // no sub list in one cat asked
       
  2466 				$widget_args['include'] = implode (',' , $the_link_ids_all );
       
  2467 				$widget_args['category'] = ''; // because implode of intersect
       
  2468 				$widget_args['title_li'] = $catname ;
  1642 				
  2469 				
  1643 			</tr>
  2470 			}
  1644 			<tr>
       
  1645 			<th><p class="submit"><input type="submit" name="reset" value="<?php echo $cancel_text ?>" /></p></th>
       
  1646 			<td>
       
  1647 			<p class="submit"><input type="submit" name="submit" value="<?php echo $submit_text ?>" /></p>
       
  1648 			</td>
       
  1649 			</tr>
       
  1650 		</table>
       
  1651 	<?php	
       
  1652 	}
       
  1653 
       
  1654 	/**
       
  1655 	 * private functions for admin page : the language list
       
  1656 	 * @since 0.9.0
       
  1657 	 *
       
  1658 	 * @update 0.9.5 : two default languages if taxonomy languages is empty
       
  1659 	 * 
       
  1660 	 */
       
  1661 	function xili_lang_row() { 	
       
  1662 		/*list of languages*/
       
  1663 				//$listlanguages = get_terms_with_order($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
       
  1664 		$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
       
  1665 		
       
  1666 		if (empty($listlanguages)) : /*create two default lines with the default language (as in config)*/
       
  1667 		  	/* language of WP */
       
  1668 			$term = 'en_US';
       
  1669 			$args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'');
       
  1670 			$theids = wp_insert_term( $term, TAXONAME, $args);
       
  1671 			wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
  1672 		 	$term = $this->default_lang;
       
  1673 		 	$desc = $this->default_lang;
       
  1674 		 	if (!defined('WPLANG') || $this->default_lang == 'en_US' ) {$term = 'fr_FR'; $desc = 'french';}
       
  1675 		 	$args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' =>'');
       
  1676 		 	$theids = wp_insert_term( $term, TAXONAME, $args);
       
  1677 			wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); /* create the group */
       
  1678 			$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
       
  1679 		endif;
       
  1680 		foreach ($listlanguages as $language) {	
       
  1681 			$class = ((defined('DOING_AJAX') && DOING_AJAX) || " class='alternate'" == $class ) ? '' : " class='alternate'";
       
  1682 			$language->count = number_format_i18n( $language->count );
       
  1683 			$posts_count = ( $language->count > 0 ) ? "<a href='edit.php?lang=$language->slug'>$language->count</a>" : $language->count;	
       
  1684 		
       
  1685 			$edit = "<a href='?action=edit&amp;page=language_page&amp;term_id=".$language->term_id."' >".__( 'Edit' )."</a></td>";	
       
  1686 			/* delete link*/
       
  1687 			$edit .= "<td><a href='?action=delete&amp;page=language_page&amp;term_id=".$language->term_id."' class='delete'>".__( 'Delete' )."</a>";	
       
  1688 			
       
  1689 		$line="<tr id='cat-$language->term_id'$class>
       
  1690 			<th scope='row' style='text-align: center'>$language->term_id</th>
       
  1691 			<td>" .$language->name. "</td>
       
  1692 			<td>$language->description</td>
       
  1693 			<td>$language->slug</td>
       
  1694 			<td>$language->term_order</td>
       
  1695 			<td align='center'>$posts_count</td> 
       
  1696 			<td>$edit</td>\n\t</tr>\n"; /*to complete - 0.9.8.1 count to post*/
       
  1697 			echo $line;
       
  1698 			//print_r($language);
       
  1699 		}	
  2471 		}	
       
  2472 		return $widget_args ;
       
  2473 	}
       
  2474 	
       
  2475 	/**
       
  2476 	 * only active if 'lang' in template tag wp_list_bookmarks()
       
  2477 	 *
       
  2478 	 * as :  wp_list_bookmarks( array( 'lang'=>the_curlang() ) ) to display only in current language  
       
  2479 	 *
       
  2480 	 * don't interfere with widget_links filter
       
  2481 	 *
       
  2482 	 * @ since 1.8.5
       
  2483 	 */
       
  2484 	function the_get_bookmarks_lang ($links_list, $args) {
       
  2485 		if ( isset( $args[QUETAG] ) ) {
       
  2486 			// get links in selected lang
       
  2487 			$linklang = term_exists($args[QUETAG],'link_'.TAXONAME) ;
       
  2488 			$linklang_ever = term_exists('ev_er','link_'.TAXONAME) ; // the dummy lang - shown ever with selected language
       
  2489 			//global $the_link_ids;
       
  2490 			$this->the_link_ids = get_objects_in_term( array( $linklang['term_id'], $linklang_ever['term_id'] ), 'link_'.TAXONAME ) ;
       
  2491 			
       
  2492 			return array_filter ( $links_list , array(&$this,'_filtering_links') ) ;
       
  2493 			
       
  2494 		}
       
  2495 		return $links_list;
       
  2496 	}
       
  2497 	function _filtering_links ($link) {
       
  2498 		//global $the_link_ids;
       
  2499 		if ( in_array( $link->link_id , $this->the_link_ids ) ) return true ;
       
  2500 	}
       
  2501 
       
  2502 	/**
       
  2503 	 * Register link language taxonomy
       
  2504 	 * @ since 1.8.5
       
  2505 	 */
       
  2506 	function add_link_taxonomy () {
       
  2507 		register_taxonomy( 'link_'.TAXONAME, 'link', array('hierarchical' => false, 'label' => false, 'rewrite' => false, 'update_count_callback' =>  array(&$this,'_update_link_lang_count'), 'show_ui' => false, '_builtin' => false ));
       
  2508 		
       
  2509 	}
       
  2510 	// count update
       
  2511 	function _update_link_lang_count( $terms ) {
       
  2512 		//
       
  2513 		global $wpdb;
       
  2514 			foreach ( (array) $terms as $term ) {
       
  2515 				$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->term_relationships.object_id AND term_taxonomy_id = %d", $term ) );
       
  2516 				$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
       
  2517 			}
       
  2518 	}
       
  2519 
       
  2520 
       
  2521 	/** end of language for bookmarks * @ since 1.8.5 **/
       
  2522 	
       
  2523 	
       
  2524 	/**
       
  2525  	* now active in same file as class xili_language
       
  2526  	* Widgets registration after classes rewritten
       
  2527  	*
       
  2528  	* @since 1.8.8
       
  2529  	*/
       
  2530 	
       
  2531 	function add_new_widgets() {
       
  2532 		load_plugin_textdomain('xili-language-widget',false, 'xili-language/languages'); // 1.8.8.1 fixes translation and red messages
       
  2533  		register_widget('xili_Widget_Recent_Posts'); // since 1.3.2
       
  2534  		register_widget('xili_WP_Widget_Recent_Comments'); // since 1.8.3 
       
  2535  		register_widget('xili_language_Widgets'); // since 1.8.3 
  1700 	}
  2536 	}
  1701 	
  2537 	
  1702 	//********************************************//
  2538 	//********************************************//
  1703 	// Functions for themes (hookable by add_action() in functions.php - 0.9.7
  2539 	// Functions for themes (hookable by add_action() in functions.php - 0.9.7
  1704 	//********************************************//
  2540 	//********************************************//
  1705 
  2541 
  1706 	/**
  2542 	/**
  1707 	 * List of available languages.
  2543 	 * List of available languages.
  1708 	 *
  2544 	 *
  1709 	 * @since 0.9.0
  2545 	 * @since 0.9.0
  1710 	 * @updated 0.9.7.4 - 0.9.8.3 - 0.9.9.6
  2546 	 * @updated 0.9.7.4 - 0.9.8.3 - 0.9.9.6 - 1.5.5 (add class current-lang in <a>)
       
  2547 	 * @updated 1.6.0 - new option for nav menu hook and echoing 4th param - better permalink
       
  2548 	 * @updated 1.8.1 - delete 'in' prefix in list - class if LI
  1711 	 * can be hooked by add_action in functions.php
  2549 	 * can be hooked by add_action in functions.php
  1712 	 * with : add_action('xili_language_list','my_infunc_language_list',10,3);
  2550 	 * with : add_action('xili_language_list','my_infunc_language_list',10,4);
  1713 	 *
  2551 	 *
  1714 	 * for multiple widgets since 0.9.9.6 : incorporate top option (without flag) but with example rules
  2552 	 * for multiple widgets since 0.9.9.6, 1.6.0 : incorporate options
  1715 	 *
  2553 	 *
  1716 	 * @param $before = '<li>', $after ='</li>'.
  2554 	 * @param $before = '<li>', $after ='</li>'.
  1717 	 * @return list of languages of site for sidebar list.
  2555 	 * @return list of languages of site for sidebar list.
  1718 	 */
  2556 	 */
  1719 	function xili_language_list($before = '<li>', $after ='</li>',$option='') {
  2557 	function xili_language_list( $before = '<li>', $after ='</li>', $option='', $echo = true, $hidden = false ) {
  1720 		$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
  2558 		global $post;
       
  2559 		$lang_perma = $this->lang_perma; // since 2.1.1
       
  2560 		
       
  2561 		$before_class = false ;
       
  2562 		if ( substr($before,-2) == '.>' ) { // tips to add dynamic class in before
       
  2563 			$before_class = true ;
       
  2564 			$before = str_replace('.>','>',$before);
       
  2565 		}
       
  2566 		$listlanguages = $this->get_listlanguages();
       
  2567 		$a = ''; // 1.6.1
       
  2568 		
  1721 		if ($option == 'typeone') {
  2569 		if ($option == 'typeone') {
  1722 			/* the rules : don't display the current lang if set and add link of category if is_category()*/
  2570 			/* the rules : don't display the current lang if set and add link of category if is_category()*/
  1723 			if (is_category()) {  
  2571 			$currenturl = $this->current_url ( $lang_perma ); // 2.5	
  1724 				$catcur = xiliml_get_category_link();
  2572 			foreach ($listlanguages as $language) {
  1725 				$currenturl = $catcur.'&amp;'; 
  2573 				$display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ;
       
  2574 				if ($language->slug != the_curlang()   && $display ) {
       
  2575 					$beforee = ( $before_class && $before == '<li>' ) ? '<li class="lang-'.$language->slug.'" >': $before;
       
  2576 					$class = ' class="lang-'.$language->slug.'"';
       
  2577 					
       
  2578 					$link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ;
       
  2579 					
       
  2580 					$a .= $beforee .'<a '.$class.' href="'.$link.'" title="'.__('Posts selected', $this->thetextdomain ).' '.__('in '.$language->description, $this->thetextdomain ).'" >'. __( $language->description, $this->thetextdomain ) .'</a>'.$after;
       
  2581 				}
       
  2582 			}
       
  2583 			
       
  2584 		} elseif ($option == 'typeonenew') {  // 2.1.0
       
  2585 				/* the rules : don't display the current lang if set and add link of category if is_category() but display linked singular */
       
  2586 			$currenturl = $this->current_url ( $lang_perma ); // 2.5
       
  2587 			foreach ($listlanguages as $language) {
       
  2588 				$display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ;
       
  2589 				if ($language->slug != the_curlang()   && $display ) {
       
  2590 					$beforee = ( $before_class && $before == '<li>' ) ? '<li class="lang-'.$language->slug.'" >': $before;
       
  2591 					$class = ' class="lang-'.$language->slug.'"';
       
  2592 					
       
  2593 					if ( ( is_single() || is_page() ) && !is_front_page() ) {	
       
  2594 						$link = $this->link_of_linked_post ( $post->ID, $language->slug ) ;
       
  2595 						$title = sprintf (__('Current post in %s', $this->thetextdomain ), __($language->description, $this->thetextdomain ) ) ;
       
  2596 					} else {
       
  2597 						$link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ;
       
  2598 						$title = sprintf (__('Posts selected in %s', $this->thetextdomain ), __($language->description, $this->thetextdomain ) ) ;
       
  2599 					}
       
  2600 			
       
  2601 					$a .= $beforee .'<a '.$class.' href="'.$link.'" title="'.$title.'" >'. __($language->description, $this->thetextdomain ) .'</a>' . $after;
       
  2602 				}
       
  2603 			}
       
  2604 				
       
  2605 		} elseif ($option == 'navmenu')  {	 /* current list in nav menu 1.6.0 */
       
  2606 			if ( $lang_perma ) {
       
  2607 				$currenturl = get_bloginfo('url').'/%lang%/';
  1726 			} else {
  2608 			} else {
  1727 		 		$currenturl = get_bloginfo('siteurl').'/?';
  2609 	 			$currenturl = get_bloginfo('url').'/?';
  1728 			}
  2610 			}
  1729 			foreach ($listlanguages as $language) {
  2611 				foreach ($listlanguages as $language) { 
  1730 				if ($language->slug != $this->curlang ) {
  2612 					$display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ;
  1731 					$a .= $before ."<a href='".$currenturl.QUETAG."=".$language->slug."' title='".__('Website',THEME_TEXTDOMAIN)." ".__('in '.$language->description,THEME_TEXTDOMAIN)."'>". __('in '.$language->description,THEME_TEXTDOMAIN) ."</a>".$after;
  2613 					if ( $display ) { 
       
  2614 						if ($language->slug != the_curlang() ) {
       
  2615 							$class = " class='menu-item menu-item-type-custom lang-".$language->slug."'";
       
  2616 						} else {
       
  2617 							$class = " class='menu-item menu-item-type-custom lang-".$language->slug." current-lang current-menu-item'";
       
  2618 						}
       
  2619 						$beforee = (substr($before,-1) == '>') ? str_replace('>',' '.$class.' >' , $before ) : $before ;
       
  2620 						
       
  2621 						
       
  2622 						$link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ;
       
  2623 						
       
  2624 						$a .= $beforee .'<a href="'.$link.'" title="'.__('Posts selected', $this->thetextdomain ).' '.__('in '.$language->description, $this->thetextdomain ).'" >'. __( $language->description, $this->thetextdomain ) . '</a>' . $after;
       
  2625 					}
  1732 				}
  2626 				}
  1733 			}
  2627 				
  1734 			echo $a;
  2628 		} elseif ($option == 'navmenu-1')  {	// 2.1.0  and single
  1735 		} else {	/* current list */
  2629 				$currenturl = $this->current_url ( $lang_perma ); // 2.5
  1736 			foreach ($listlanguages as $language) {
  2630 				
  1737 				$a .= $before ."<a href='".get_bloginfo('siteurl')."/?".QUETAG."=".$language->slug."' title='".__('Website',THEME_TEXTDOMAIN)." ".__('in '.$language->description,THEME_TEXTDOMAIN)."'>". __('in '.$language->description,THEME_TEXTDOMAIN) ."</a>".$after;
  2631 				foreach ($listlanguages as $language) { 
  1738 			}
  2632 					$display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ;
  1739 			echo $a;
  2633 					if ( $display ) { 
  1740 		}	
  2634 						
  1741 	}
  2635 						if ($language->slug != the_curlang() ) {
       
  2636 							$class = " class='menu-item menu-item-type-custom lang-".$language->slug."'";
       
  2637 						} else {
       
  2638 							$class = " class='menu-item menu-item-type-custom lang-".$language->slug." current-lang current-menu-item'";
       
  2639 						}
       
  2640 						
       
  2641 						if ( ( is_single() || is_page() ) && !is_front_page() ) {	
       
  2642 							$link = $this->link_of_linked_post ( $post->ID, $language->slug ) ;
       
  2643 							$title = sprintf (__('Current post in %s',the_theme_domain()), __($language->description, $this->thetextdomain) ) ;
       
  2644 						} else {
       
  2645 							$link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ;
       
  2646 							$title = sprintf ( __('Posts selected in %s',the_theme_domain()), __($language->description, $this->thetextdomain ) ) ;
       
  2647 						}
       
  2648 						
       
  2649 						$beforee = (substr($before,-1) == '>') ? str_replace('>',' '.$class.' >' , $before ) : $before ;
       
  2650 						$a .= $beforee .'<a href="'.$link.'" title="'.$title.'" >'. __($language->description, $this->thetextdomain ) .'</a>'.$after;
       
  2651 					}
       
  2652 				}
       
  2653 			
       
  2654 				
       
  2655 			} else {	/* current list only root */
       
  2656 				if ( $lang_perma ) {
       
  2657 					$currenturl = get_bloginfo('url').'/%lang%/';
       
  2658 				} else {
       
  2659 	 				$currenturl = get_bloginfo('url').'/?';
       
  2660 				}	
       
  2661 				foreach ($listlanguages as $language) {
       
  2662 					$display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ;
       
  2663 					
       
  2664 					if ( $display ) {
       
  2665 						if ( $language->slug != the_curlang() ) {
       
  2666 							$class = " class='lang-".$language->slug."'";
       
  2667 						} else {
       
  2668 							$class = " class='lang-".$language->slug." current-lang'";
       
  2669 						}
       
  2670 						
       
  2671 						$link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ;
       
  2672 						
       
  2673 						$beforee = ( $before_class && $before == '<li>' ) ? '<li class="lang-'.$language->slug.'" >': $before;
       
  2674 						$a .= $beforee .'<a '.$class.' href="'.$link.'" title="'.__('Posts selected', $this->thetextdomain ).' '.__('in '.$language->description, $this->thetextdomain).'" >'. __( $language->description, $this->thetextdomain ) .'</a>' . $after;
       
  2675 					}
       
  2676 				}
       
  2677 			}
       
  2678 			if ($echo) 
       
  2679 				echo $a;
       
  2680 			else
       
  2681 				return $a;
       
  2682 	}
       
  2683 	
       
  2684 	/**
       
  2685 	 * link of linked post
       
  2686 	 *
       
  2687 	 * @since 2.1.0
       
  2688 	 *
       
  2689 	 * @updated 2.1.1
       
  2690 	 */
       
  2691 	function link_of_linked_post ( $fromID, $lang_slug ) { 
       
  2692 	 	$targetpost = $this->linked_post_in ( $fromID, $lang_slug ) ;
       
  2693 	 	if ( $targetpost ) {
       
  2694 	 		return get_permalink($targetpost);
       
  2695 	 	} else {
       
  2696 	 		if ( $this->lang_perma ) {
       
  2697 	 			$currenturl = get_bloginfo('url').'/%lang%/';
       
  2698 	 		} else	{
       
  2699 	 			$currenturl = get_bloginfo('url')."/?";
       
  2700 	 		} 
       
  2701 	 		$link = ( $this->lang_perma ) ? str_replace ( '%lang%', $lang_slug, $currenturl ) : $currenturl.QUETAG."=".$lang_slug ;
       
  2702 	 	    return $link ; 
       
  2703 	 	}
       
  2704 	}
       
  2705 	
       
  2706 	/**
       
  2707 	 * For widget - the list of options above
       
  2708 	 * @since 1.6.0
       
  2709 	 */
       
  2710 	function xili_language_list_options () {
       
  2711 		$this->langs_list_options = array( array('','default'), array('typeone','Type n°1'), array('typeonenew','Type for single') );
       
  2712 	}
       
  2713 	
  1742 	
  2714 	
  1743 	/**
  2715 	/**
  1744 	 * language of current post used in loop
  2716 	 * language of current post used in loop
  1745 	 * @since 0.9.0
  2717 	 * @since 0.9.0
  1746 	 * 
  2718 	 * 
       
  2719 	 * @updated 2.5.1
  1747 	 *
  2720 	 *
  1748 	 * @param $before = '<span class"xili-lang">(', $after =')</span>'.
  2721 	 * @param $before = '<span class"xili-lang">(', $after =')</span>'.
  1749 	 * @return language of post.
  2722 	 * @return language of post.
  1750 	 */
  2723 	 */
  1751 	function xili_post_language($before = '<span class="xili-lang">(', $after =')</span>') {
  2724 	function xili_post_language( $before = '<span class="xili-lang">(', $after =')</span>', $type = 'iso' ) {
  1752 		global $post;
  2725 		global $post ;
  1753 		$ress = wp_get_object_terms($post->ID, TAXONAME);
  2726 		$langpost = $this->get_post_language ( $post->ID, $type );
  1754 		$obj_term = $ress[0];
  2727 		
  1755 		if ('' != $obj_term->name) :
  2728 		if ( '' != $langpost ) :
  1756 				$curlangname = $obj_term->name;
  2729 				$curlangname = $langpost;
  1757 		else :
  2730 		else :
  1758 				$curlangname = __('undefined',THEME_TEXTDOMAIN);
  2731 				$curlangname = __('undefined',$this->thetextdomain);
  1759 		endif;
  2732 		endif;
  1760 		$a = $before . $curlangname .$after.'';  
  2733 		$a = $before . $curlangname .$after.'';  
  1761 		echo $a;
  2734 		echo $a;
  1762 	}
  2735 	}
  1763 		
  2736 		
  1769 	 * @updated 1.1 - see hookable same name function outside class
  2742 	 * @updated 1.1 - see hookable same name function outside class
  1770 	 * can be hooked by add_action in functions.php
  2743 	 * can be hooked by add_action in functions.php
  1771 	 *
  2744 	 *
  1772 	 *
  2745 	 *
  1773 	 */
  2746 	 */
  1774 	function xiliml_the_other_posts ($post_ID, $before = "This post in", $separator = ", ", $type = "display") {
  2747 	function the_other_posts ( $post_ID, $before = "This post in", $separator = ", ", $type = "display" ) {
  1775 		/* default here*/
  2748 		/* default here*/
  1776 			$outputarr = array();
  2749 			$outputarr = array();
  1777 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
  2750 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
  1778 			$langpost = $this->get_cur_language($post_ID); // to be used in multilingual loop since 1.1
  2751 			$langpost = $this->get_cur_language($post_ID); // to be used in multilingual loop since 1.1
  1779 			$post_lang = $langpost['lang'];
  2752 			$post_lang = $langpost[QUETAG];
  1780 			foreach ($listlanguages as $language) {
  2753 			foreach ($listlanguages as $language) {
  1781 				$otherpost = get_post_meta($post_ID, 'lang-'.$language->slug, true);
  2754 				$otherpost = $this->linked_post_in( $post_ID, $language->slug ) ; //get_post_meta($post_ID, 'lang-'.$language->slug, true);
  1782 				
  2755 				
  1783 				if ($type == "display") {
  2756 				if ($type == "display") {
  1784 					if ('' != $otherpost && $language->slug != $post_lang ) {
  2757 					if ('' != $otherpost && $language->slug != $post_lang ) {
  1785 						$outputarr[] = "<a href='".get_permalink($otherpost)."' >".__($language->description,THEME_TEXTDOMAIN) ."</a>";
  2758 						$outputarr[] = "<a href='".get_permalink($otherpost)."' >".__($language->description,$this->thetextdomain) ."</a>";
  1786 					}
  2759 					}
  1787 				} elseif ($type == "array") { // here don't exclude cur lang
  2760 				} elseif ($type == "array") { // here don't exclude cur lang
  1788 					if ('' != $otherpost)
  2761 					if ('' != $otherpost)
  1789 						$outputarr[$language->slug] = $otherpost;
  2762 						$outputarr[$language->slug] = $otherpost;
  1790 				}
  2763 				}
  1791 			}
  2764 			}
  1792 			if ($type == "display") {
  2765 			if ($type == "display") {
  1793 				if (!empty($outputarr))
  2766 				if (!empty($outputarr))
  1794 					$output =  (($before !="") ? __($before,THEME_TEXTDOMAIN)." " : "" ).implode ($separator, $outputarr);
  2767 					$output =  (($before !="") ? __($before,$this->thetextdomain)." " : "" ).implode ($separator, $outputarr);
  1795 				if ('' != $output) { echo $output;}	
  2768 				if ('' != $output) { echo $output;}	
  1796 			} elseif ($type == "array") {
  2769 			} elseif ($type == "array") {
  1797 				if (!empty($outputarr)) {
  2770 				if (!empty($outputarr)) {
  1798 					$outputarr[$post_ID] = $post_lang; 
  2771 					$outputarr[$post_ID] = $post_lang; 
  1799 					// add a key with curid to give his lang (empty if undefined)
  2772 					// add a key with curid to give his lang (empty if undefined)
  1806 	
  2779 	
  1807 	/**
  2780 	/**
  1808 	 * the_category() rewritten to keep new features of multilingual (and amp & pbs in link)
  2781 	 * the_category() rewritten to keep new features of multilingual (and amp & pbs in link)
  1809 	 *
  2782 	 *
  1810 	 * @since 0.9.0
  2783 	 * @since 0.9.0
  1811 	 * @updated 0.9.9.4
  2784 	 * @updated 0.9.9.4 
  1812 	 * can be hooked by add_action xiliml_the_category in functions.php
  2785 	 * can be hooked by add_action xiliml_the_category in functions.php
  1813 	 *
  2786 	 *
  1814 	 */
  2787 	 */
  1815 	function xiliml_the_category($post_ID, $separator = ', ' ,$echo = true) {
  2788 	function the_category( $post_ID, $separator = ', ' ,$echo = true ) {
  1816 		/* default here*/
  2789 		/* default here*/
  1817 		$the_cats_list = wp_get_object_terms($post_ID, 'category');
  2790 		$the_cats_list = wp_get_object_terms($post_ID, 'category');
  1818 		$i = 0;
  2791 		$i = 0;
  1819 		foreach ($the_cats_list as $the_cat) {
  2792 		foreach ($the_cats_list as $the_cat) {
  1820 			if ( 0 < $i )
  2793 			if ( 0 < $i )
  1821 				$thelist .= $separator . ' ';
  2794 				$thelist .= $separator . ' ';
  1822 			$desc4title = trim(attribute_escape(apply_filters( 'category_description', $the_cat->description, $the_cat->term_id )));
  2795 			$desc4title = trim(attribute_escape(apply_filters( 'category_description', $the_cat->description, $the_cat->term_id )));
  1823 			
  2796 			
  1824 			$title = ('' == $desc4title) ? __($the_cat->name,THEME_TEXTDOMAIN) : $desc4title;
  2797 			$title = ('' == $desc4title) ? __($the_cat->name,$this->thetextdomain) : $desc4title;
  1825 			$the_catlink = '<a href="' . get_category_link($the_cat->term_id) . '" title="' . $title . '" ' . $rel . '>';
  2798 			$the_catlink = '<a href="' . get_category_link($the_cat->term_id) . '" title="' . $title . '" ' . $rel . '>';
  1826 			//if ($curlang != DEFAULTSLUG) :
  2799 			//if ($curlang != DEFAULTSLUG) :
  1827 	      	$the_catlink .=  __($the_cat->name,THEME_TEXTDOMAIN).'</a>';;
  2800 	      	$the_catlink .=  __($the_cat->name,$this->thetextdomain).'</a>';;
  1828 	      	//else :
  2801 	      	//else :
  1829 	      		 //$the_catlink .=  $the_cat->name.'</a>';;
  2802 	      		 //$the_catlink .=  $the_cat->name.'</a>';;
  1830 	      	//endif;
  2803 	      	//endif;
  1831 			$thelist .= $the_catlink;
  2804 			$thelist .= $the_catlink;
  1832 			++$i;
  2805 			++$i;
  1843 	 * Add list of languages in radio input - for search form.
  2816 	 * Add list of languages in radio input - for search form.
  1844 	 *
  2817 	 *
  1845 	 * @since 0.9.7
  2818 	 * @since 0.9.7
  1846 	 * can be hooked by add_action in functions.php
  2819 	 * can be hooked by add_action in functions.php
  1847 	 *
  2820 	 *
  1848 	 * @updated 0.9.9.5
  2821 	 * @updated 0.9.9.5, 1.8.2, 2.2.0 , 2.2.2
  1849 	 *
  2822 	 *
  1850 	 * $before, $after each line of radio input
  2823 	 * $before, $after each line of radio input
  1851 	 *
  2824 	 *
  1852 	 * @param $before, $after. 
  2825 	 * @param $before, $after. 
  1853 	 * @return echo the form.
  2826 	 * @return echo the form.
  1854 	 */
  2827 	 */
  1855 	function xiliml_langinsearchform ($before='',$after='') {
  2828 	function xiliml_langinsearchform ( $before='', $after='', $echo = true ) {
  1856 			/* default here*/
  2829 			/* default here*/
       
  2830 			global $wp_query;
  1857 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
  2831 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
       
  2832 			$a = '';
  1858 			foreach ($listlanguages as $language) {
  2833 			foreach ($listlanguages as $language) {
  1859 				$a = $before.'<input type="radio" name="'.QUETAG.'" value="'.$language->slug.'" id="'.$language->slug.'" />&nbsp;'.__($language->description,THEME_TEXTDOMAIN).' '.$after;
  2834 				if ( is_search() ) {
  1860 			echo $a;
  2835 					if ( isset( $wp_query->query_vars[QUETAG] ) ) { // to rebuilt form after search query
  1861 			}			
  2836 						$selected = ( ( $language->slug == $wp_query->query_vars[QUETAG] ) ) ? 'checked="checked"' : "" ; //2.2.2
  1862 		    echo $before.'<input type="radio" name="alllang" value="yes" /> '.__('All',THEME_TEXTDOMAIN).' '.$after;	 // this query alllang is unused -		
  2837 					} else {
       
  2838 						$selected = "";
       
  2839 					}
       
  2840 				} else {
       
  2841 					$selected =  ( ( $language->slug == $this->curlang ) ) ? 'checked="checked"' : "" ; 
       
  2842 				}
       
  2843 				$a .= $before.'<input type="radio" name="'.QUETAG.'" value="'.$language->slug.'" id="'.QUETAG.'" '.$selected.' />&nbsp;'.__( $language->description, $this->thetextdomain ).' '.$after;
       
  2844 			}
       
  2845 			// new javascript to uncheck radio buttons	on form named searchform
       
  2846 		    $a .= $before.'<input type="button" name="clear" onClick="var form = document.forms[\'searchform\'];
       
  2847 for (var i=0; i < form.'.QUETAG.'.length; i++) {
       
  2848 if(form.'.QUETAG.'[i].checked) {
       
  2849 form.'.QUETAG.'[i].checked = false; } }" value="'.__('All', $this->thetextdomain ).'" /> '.$after;	 // this to all lang query -
       
  2850 		    
       
  2851 		    
       
  2852 		    if ( $echo )  
       
  2853 		    	echo $a;
       
  2854 		    else
       
  2855 		    	return $a;
       
  2856 		    		
  1863 	}
  2857 	}
  1864 	
  2858 	
  1865 	/**
  2859 	/**
  1866 	 * Select latest comments in current lang.
  2860 	 * Select latest comments in current lang.
  1867 	 *
  2861 	 *
  1868 	 * @since 0.9.9.4
  2862 	 * @since 0.9.9.4
  1869 	 * used by widget xili-recent-comments
  2863 	 * used by widget xili-recent-comments
  1870 	 *
  2864 	 *
  1871 	 * $before, $after each line of radio input
  2865 	 * @param $number. 
  1872 	 *
  2866 	 * @return $comments.
  1873 	 * @param $before, $after. 
  2867 	 */
  1874 	 * @return echo the form.
  2868 	function xiliml_recent_comments ( $number = 5 ) {
  1875 	 */
       
  1876 	function xiliml_recent_comments ($number = 5) {
       
  1877 		global $comments, $wpdb ;
  2869 		global $comments, $wpdb ;
  1878 		if ( !$comments = wp_cache_get( 'xili_language_recent_comments', 'widget' ) ) {
  2870 		if ( !$comments = wp_cache_get( 'xili_language_recent_comments', 'widget' ) ) {
  1879 				$join = "";
  2871 				$join = "";
  1880 				$where = "";
  2872 				$where = "";
  1881 				$reqtag = is_term( $this->curlang, TAXONAME );
  2873 				$reqtag = term_exists( $this->curlang, TAXONAME );
  1882 					if (''!= $reqtag) {
  2874 					if (''!= $reqtag) {
  1883 						$wherereqtag = $reqtag['term_id'];
  2875 						$wherereqtag = $reqtag['term_id'];
  1884 						$join = " LEFT JOIN $wpdb->term_relationships as tr ON ($wpdb->comments.comment_post_ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) ";
  2876 						$join = " LEFT JOIN $wpdb->term_relationships as tr ON ($wpdb->comments.comment_post_ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) ";
  1885 					    $where = " AND tt.taxonomy = '".TAXONAME."' ";
  2877 					    $where = " AND tt.taxonomy = '".TAXONAME."' ";
  1886 					    $where .= " AND tt.term_id = $wherereqtag ";
  2878 					    $where .= " AND tt.term_id = $wherereqtag ";
  1887 					}
  2879 					}
  1888 				$query = "SELECT * FROM $wpdb->comments".$join." WHERE comment_approved = '1' ".$where." ORDER BY comment_date_gmt DESC LIMIT $number"; 
  2880 				$query = "SELECT * FROM $wpdb->comments".$join." WHERE comment_approved = '1' ".$where." ORDER BY comment_date_gmt DESC LIMIT $number"; 
  1889 				echo $query;
  2881 				
  1890 				$comments = $wpdb->get_results($query);
  2882 				$comments = $wpdb->get_results($query);
  1891 				wp_cache_add( 'xili_language_recent_comments', $comments, 'widget' );
  2883 				wp_cache_add( 'xili_language_recent_comments', $comments, 'widget' );
  1892 		}
  2884 		}
  1893 		return $comments;
  2885 		return $comments;
  1894 	}
       
  1895 	
       
  1896 	/**
       
  1897 	 * Recursive search of files in a path
       
  1898 	 * @since 1.1.9 
       
  1899 	 * @update 1.2.1
       
  1900 	 *
       
  1901 	 */
       
  1902 	 function find_files($path, $pattern, $callback) {
       
  1903  		//$path = rtrim(str_replace("\\", "/", $path), '/') . '/';
       
  1904 		  $matches = Array();
       
  1905 		  $entries = Array();
       
  1906 		  $dir = dir($path);
       
  1907 		  
       
  1908 		  while (false !== ($entry = $dir->read())) {
       
  1909 		    $entries[] = $entry;
       
  1910 		  }
       
  1911 		  $dir->close();
       
  1912 		  foreach ($entries as $entry) {
       
  1913 		    $fullname = $path .$this->ossep. $entry;
       
  1914 		    if ($entry != '.' && $entry != '..' && is_dir($fullname)) {
       
  1915 		      $this->find_files($fullname, $pattern, $callback);
       
  1916 		    } else if (is_file($fullname) && preg_match($pattern, $entry)) {
       
  1917 		      call_user_func($callback, $path , $entry);
       
  1918 		    }
       
  1919 		  }
       
  1920 	}
       
  1921 	/**
       
  1922 	 * display lines of files in special sidebox
       
  1923 	 * @since 1.1.9
       
  1924 	 */
       
  1925 	function available_mo_files($path , $filename) {
       
  1926   		//echo $filename . " in : " . "/".str_replace("/","",str_replace(get_template_directory(),'',$path)) . "<br />";
       
  1927   		echo str_replace(".mo","",$filename ). " (".$this->ossep.str_replace($this->ossep,"",str_replace(get_template_directory(),'',$path)).")<br />";
       
  1928 	}
  2886 	}
  1929 	
  2887 	
  1930 	/**
  2888 	/**
  1931  	* Enable to add functions and filters that are not in theme's functions.php
  2889  	* Enable to add functions and filters that are not in theme's functions.php
  1932  	* These filters are common even if you change default theme...
  2890  	* These filters are common even if you change default theme...
  1933  	* Place your functions.php in folder plugins/xilidev-libraries/
  2891  	* Place your functions.php in folder plugins/xilidev-libraries/
  1934  	* if you have a filter in this file, avoid to have similar one in functions.php of the theme !!!
  2892  	* if you have a filter in this file, avoid to have similar one in functions.php of the theme !!!
  1935 	*
  2893 	*
  1936  	*/
  2894  	*/
  1937 	function insert_gold_functions () {
  2895 	function insert_gold_functions () {
  1938 		if ($this->functions_enable !='' && file_exists(XILIFUNCTIONSPATH . '/functions.php') )
  2896 		$gold_path = WP_PLUGIN_DIR . $this->xilidev_folder ; /* since 1.0 to add xili-libraries */
  1939 			include_once (XILIFUNCTIONSPATH . '/functions.php');
  2897 		if ( $this->xili_settings['functions_enable'] !='' && file_exists( $gold_path . '/functions.php') )
  1940 	}
  2898 			include_once ( $gold_path . '/functions.php');
  1941 
  2899 	}
  1942 			
  2900 	
  1943 } /* end of xili-language class */
  2901 	/**
  1944 
  2902 	 * Retrieve category list in either HTML list or custom format - as in category-template - rewritten for multilingual - filter the_category only frontend
       
  2903 	 *
       
  2904 	 * @since 1.7.0
       
  2905 	 *
       
  2906 	 * @param string $separator Optional, default is empty string. Separator for between the categories.
       
  2907 	 * @param string $parents Optional. How to display the parents.
       
  2908 	 * no third param because call by end filter
       
  2909 	 * @return string
       
  2910 	 */
       
  2911 	function xl_get_the_category_list( $thelist, $separator = '', $parents='' ) {
       
  2912 		global $wp_rewrite, $post;
       
  2913 		$categories = get_the_category( $post->ID );
       
  2914 		//if ( !is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) )
       
  2915 			//return apply_filters( 'the_category', '', $separator, $parents );
       
  2916 	
       
  2917 		if ( empty( $categories ) ) {
       
  2918 			return  __( 'Uncategorized', $this->thetextdomain ) ; // fixed - avoid a previous recursive filter with custom @since 1.8.0
       
  2919 		}
       
  2920 		$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
       
  2921 	
       
  2922 		$thelist = '';
       
  2923 		if ( '' == $separator ) {
       
  2924 			$thelist .= '<ul class="post-categories">';
       
  2925 			foreach ( $categories as $category ) {
       
  2926 				$thelist .= "\n\t<li>";
       
  2927 				switch ( strtolower( $parents ) ) {
       
  2928 					case 'multiple':
       
  2929 						if ( $category->parent )
       
  2930 							$thelist .= get_category_parents( $category->parent, true, $separator );
       
  2931 						$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", $this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>' . __($category->name, $this->thetextdomain).'</a></li>';
       
  2932 						break;
       
  2933 					case 'single':
       
  2934 						$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", $this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>';
       
  2935 						if ( $category->parent )
       
  2936 							$thelist .= get_category_parents( $category->parent, false, $separator );
       
  2937 						$thelist .= __($category->name, $this->thetextdomain).'</a></li>';
       
  2938 						break;
       
  2939 					case '':
       
  2940 					default:
       
  2941 						$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", $this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>' . __($category->cat_name, $this->thetextdomain).'</a></li>';
       
  2942 				}
       
  2943 			}
       
  2944 			$thelist .= '</ul>';
       
  2945 		} else {
       
  2946 			$i = 0;
       
  2947 			foreach ( $categories as $category ) {
       
  2948 				if ( 0 < $i )
       
  2949 					$thelist .= $separator;
       
  2950 				switch ( strtolower( $parents ) ) {
       
  2951 					case 'multiple':
       
  2952 						if ( $category->parent )
       
  2953 							$thelist .= get_category_parents( $category->parent, true, $separator );
       
  2954 						$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s",$this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>' . __($category->name, $this->thetextdomain).'</a>';
       
  2955 						break;
       
  2956 					case 'single':
       
  2957 						$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s",$this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>';
       
  2958 						if ( $category->parent )
       
  2959 							$thelist .= get_category_parents( $category->parent, false, $separator );
       
  2960 						$thelist .= __($category->name, $this->thetextdomain)."</a>";
       
  2961 						break;
       
  2962 					case '':
       
  2963 					default:
       
  2964 						$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s",$this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>' . __($category->name, $this->thetextdomain).'</a>';
       
  2965 				}
       
  2966 				++$i;
       
  2967 			}
       
  2968 		}
       
  2969 		return $thelist;
       
  2970 	}
       
  2971 
       
  2972 
       
  2973 			
       
  2974 } /* **************** end of xili-language class ******************* */
       
  2975 
       
  2976 /**
       
  2977  * called when wp_locale is declared when plugin_loaded
       
  2978  *
       
  2979  * @since 2.4
       
  2980  *
       
  2981  */
       
  2982  
       
  2983 function xiliml_declare_xl_wp_locale () { 
       
  2984 	/**
       
  2985 	 * special class extending wp_locale only for theme locale
       
  2986 	 * 
       
  2987 	 * to work needs that locale datas and translation (a copy of those in core languages) will be in theme's po,mo files
       
  2988 	 * 
       
  2989 	 * @since 2.4.0
       
  2990 	 */
       
  2991 	if ( ! class_exists ( 'xl_WP_Locale'  ) ) { 
       
  2992 	class xl_WP_Locale extends WP_locale {
       
  2993 		
       
  2994 			function __construct() {
       
  2995 				parent::__construct();
       
  2996 			}
       
  2997 		
       
  2998 			function init() {
       
  2999 			
       
  3000 			$theme_domain = the_theme_domain();	
       
  3001 				
       
  3002 			// The Weekdays
       
  3003 			$this->weekday[0] = /* translators: weekday */ __('Sunday', $theme_domain);
       
  3004 			$this->weekday[1] = /* translators: weekday */ __('Monday', $theme_domain);
       
  3005 			$this->weekday[2] = /* translators: weekday */ __('Tuesday', $theme_domain);
       
  3006 			$this->weekday[3] = /* translators: weekday */ __('Wednesday', $theme_domain);
       
  3007 			$this->weekday[4] = /* translators: weekday */ __('Thursday', $theme_domain);
       
  3008 			$this->weekday[5] = /* translators: weekday */ __('Friday', $theme_domain);
       
  3009 			$this->weekday[6] = /* translators: weekday */ __('Saturday', $theme_domain);
       
  3010 	
       
  3011 			// The first letter of each day.  The _%day%_initial suffix is a hack to make
       
  3012 			// sure the day initials are unique.
       
  3013 			$this->weekday_initial[__('Sunday', $theme_domain)]    = /* translators: one-letter abbreviation of the weekday */ __('S_Sunday_initial', $theme_domain);
       
  3014 			$this->weekday_initial[__('Monday', $theme_domain)]    = /* translators: one-letter abbreviation of the weekday */ __('M_Monday_initial', $theme_domain);
       
  3015 			$this->weekday_initial[__('Tuesday', $theme_domain)]   = /* translators: one-letter abbreviation of the weekday */ __('T_Tuesday_initial', $theme_domain);
       
  3016 			$this->weekday_initial[__('Wednesday', $theme_domain)] = /* translators: one-letter abbreviation of the weekday */ __('W_Wednesday_initial', $theme_domain);
       
  3017 			$this->weekday_initial[__('Thursday', $theme_domain)]  = /* translators: one-letter abbreviation of the weekday */ __('T_Thursday_initial', $theme_domain);
       
  3018 			$this->weekday_initial[__('Friday', $theme_domain)]    = /* translators: one-letter abbreviation of the weekday */ __('F_Friday_initial', $theme_domain);
       
  3019 			$this->weekday_initial[__('Saturday', $theme_domain)]  = /* translators: one-letter abbreviation of the weekday */ __('S_Saturday_initial', $theme_domain);
       
  3020 	
       
  3021 			foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) {
       
  3022 				$this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_);
       
  3023 			}
       
  3024 	
       
  3025 			// Abbreviations for each day.
       
  3026 			$this->weekday_abbrev[__('Sunday', $theme_domain)]    = /* translators: three-letter abbreviation of the weekday */ __('Sun', $theme_domain);
       
  3027 			$this->weekday_abbrev[__('Monday', $theme_domain)]    = /* translators: three-letter abbreviation of the weekday */ __('Mon', $theme_domain);
       
  3028 			$this->weekday_abbrev[__('Tuesday', $theme_domain)]   = /* translators: three-letter abbreviation of the weekday */ __('Tue', $theme_domain);
       
  3029 			$this->weekday_abbrev[__('Wednesday', $theme_domain)] = /* translators: three-letter abbreviation of the weekday */ __('Wed', $theme_domain);
       
  3030 			$this->weekday_abbrev[__('Thursday', $theme_domain)]  = /* translators: three-letter abbreviation of the weekday */ __('Thu', $theme_domain);
       
  3031 			$this->weekday_abbrev[__('Friday', $theme_domain)]    = /* translators: three-letter abbreviation of the weekday */ __('Fri', $theme_domain);
       
  3032 			$this->weekday_abbrev[__('Saturday', $theme_domain)]  = /* translators: three-letter abbreviation of the weekday */ __('Sat', $theme_domain);
       
  3033 	
       
  3034 			// The Months
       
  3035 			$this->month['01'] = /* translators: month name */ __('January', $theme_domain);
       
  3036 			$this->month['02'] = /* translators: month name */ __('February', $theme_domain);
       
  3037 			$this->month['03'] = /* translators: month name */ __('March', $theme_domain);
       
  3038 			$this->month['04'] = /* translators: month name */ __('April', $theme_domain);
       
  3039 			$this->month['05'] = /* translators: month name */ __('May', $theme_domain);
       
  3040 			$this->month['06'] = /* translators: month name */ __('June', $theme_domain);
       
  3041 			$this->month['07'] = /* translators: month name */ __('July', $theme_domain);
       
  3042 			$this->month['08'] = /* translators: month name */ __('August', $theme_domain);
       
  3043 			$this->month['09'] = /* translators: month name */ __('September', $theme_domain);
       
  3044 			$this->month['10'] = /* translators: month name */ __('October', $theme_domain);
       
  3045 			$this->month['11'] = /* translators: month name */ __('November', $theme_domain);
       
  3046 			$this->month['12'] = /* translators: month name */ __('December', $theme_domain );  
       
  3047 	
       
  3048 			// Abbreviations for each month. Uses the same hack as above to get around the
       
  3049 			// 'May' duplication.
       
  3050 			$this->month_abbrev[__('January', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Jan_January_abbreviation', $theme_domain);
       
  3051 			$this->month_abbrev[__('February', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Feb_February_abbreviation', $theme_domain);
       
  3052 			$this->month_abbrev[__('March', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Mar_March_abbreviation', $theme_domain);
       
  3053 			$this->month_abbrev[__('April', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Apr_April_abbreviation', $theme_domain);
       
  3054 			$this->month_abbrev[__('May', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('May_May_abbreviation', $theme_domain);
       
  3055 			$this->month_abbrev[__('June', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Jun_June_abbreviation', $theme_domain);
       
  3056 			$this->month_abbrev[__('July', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Jul_July_abbreviation', $theme_domain);
       
  3057 			$this->month_abbrev[__('August', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Aug_August_abbreviation', $theme_domain);
       
  3058 			$this->month_abbrev[__('September', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Sep_September_abbreviation', $theme_domain);
       
  3059 			$this->month_abbrev[__('October', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Oct_October_abbreviation', $theme_domain);
       
  3060 			$this->month_abbrev[__('November', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Nov_November_abbreviation', $theme_domain);
       
  3061 			$this->month_abbrev[__('December',$theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Dec_December_abbreviation', $theme_domain);
       
  3062 	
       
  3063 			foreach ($this->month_abbrev as $month_ => $month_abbrev_) {
       
  3064 				$this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_);
       
  3065 			}
       
  3066 	
       
  3067 			// The Meridiems
       
  3068 			$this->meridiem['am'] = __('am', $theme_domain);
       
  3069 			$this->meridiem['pm'] = __('pm', $theme_domain);
       
  3070 			$this->meridiem['AM'] = __('AM', $theme_domain);
       
  3071 			$this->meridiem['PM'] = __('PM', $theme_domain);
       
  3072 	
       
  3073 			// Numbers formatting
       
  3074 			// See http://php.net/number_format
       
  3075 	
       
  3076 			/* translators: $thousands_sep argument for http://php.net/number_format, default is , */
       
  3077 			$trans = __('number_format_thousands_sep', $theme_domain);
       
  3078 			$this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
       
  3079 	
       
  3080 			/* translators: $dec_point argument for http://php.net/number_format, default is . */
       
  3081 			$trans = __('number_format_decimal_point', $theme_domain);
       
  3082 			$this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans;
       
  3083 			
       
  3084 			// test version // 2.7.1
       
  3085 			global $wp_version;
       
  3086 			if ( version_compare($wp_version, '3.4', '<') ) {
       
  3087 				// Import global locale vars set during inclusion of $locale.php.
       
  3088 				foreach ( (array) $this->locale_vars as $var ) {
       
  3089 					if ( isset($GLOBALS[$var]) )
       
  3090 						$this->$var = $GLOBALS[$var];
       
  3091 				}
       
  3092 			} else {
       
  3093 			// Set text direction.
       
  3094 				if ( isset( $GLOBALS['text_direction'] ) )
       
  3095 					$this->text_direction = $GLOBALS['text_direction'];
       
  3096 				/* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */
       
  3097 				elseif ( 'rtl' == _x( 'ltr', 'text direction', $theme_domain ) )
       
  3098 					$this->text_direction = 'rtl';
       
  3099 			
       
  3100 			}
       
  3101 		}	
       
  3102 	} }
       
  3103 }
  1945 
  3104 
  1946 /**** Functions that improve taxinomy.php ****/
  3105 /**** Functions that improve taxinomy.php ****/
  1947 
  3106 
  1948 /**
  3107 /**
  1949  * get terms and add order in term's series that are in a taxonomy 
  3108  * get terms and add order in term's series that are in a taxonomy 
  1969 	if ( ! $listterms )
  3128 	if ( ! $listterms )
  1970 		return array();
  3129 		return array();
  1971 
  3130 
  1972 	return $listterms;
  3131 	return $listterms;
  1973 }
  3132 }
  1974 /* for backward compatibility - soon obsolete - please modify your theme's function.php */
  3133 
  1975 function get_terms_with_order ($group_ids, $taxonomy, $taxonomy_child, $order = 'ASC') {
  3134 /** 
       
  3135  * for backward compatibility - soon obsolete - please modify your theme's function.php 
       
  3136  */
       
  3137 function get_terms_with_order ( $group_ids, $taxonomy, $taxonomy_child, $order = 'ASC' ) {
  1976 	return get_terms_of_groups_lite ($group_ids, $taxonomy, $taxonomy_child, $order);
  3138 	return get_terms_of_groups_lite ($group_ids, $taxonomy, $taxonomy_child, $order);
  1977 }	
  3139 }	
  1978 
  3140 
  1979 /**
  3141 /**
  1980  * function that improve taxinomy.php 
  3142  * function that improve taxinomy.php 
  1983  * update term order in relationships (for terms of langs group defined by his taxonomy_id)
  3145  * update term order in relationships (for terms of langs group defined by his taxonomy_id)
  1984  *
  3146  *
  1985  * @param $object_id, $taxonomy_id, $term_order
  3147  * @param $object_id, $taxonomy_id, $term_order
  1986  * 
  3148  * 
  1987  */
  3149  */
  1988 function update_term_order ($object_id,$term_taxonomy_id,$term_order) {
  3150 function update_term_order ( $object_id,$term_taxonomy_id,$term_order ) {
  1989 	global $wpdb;
  3151 	global $wpdb;
  1990 	$wpdb->update( $wpdb->term_relationships, compact( 'term_order' ), array( 'term_taxonomy_id' => $term_taxonomy_id,'object_id' => $object_id ) );
  3152 	$wpdb->update( $wpdb->term_relationships, compact( 'term_order' ), array( 'term_taxonomy_id' => $term_taxonomy_id,'object_id' => $object_id ) );
  1991 }
  3153 }
  1992 
  3154 
  1993 /**
  3155 /**
  1997  * get one term and order of it in relationships
  3159  * get one term and order of it in relationships
  1998  *
  3160  *
  1999  * @param term_id and $group_ttid (taxonomy id of group)
  3161  * @param term_id and $group_ttid (taxonomy id of group)
  2000  * @return object with term_order
  3162  * @return object with term_order
  2001  */
  3163  */
  2002 function get_term_and_order ($term_id,$group_ttid,$taxonomy) {
  3164 function get_term_and_order ( $term_id, $group_ttid, $taxonomy ) {
  2003 	global $wpdb;
  3165 	global $wpdb;
  2004 	$term = get_term($term_id,$taxonomy,OBJECT,'edit');
  3166 	$term = get_term($term_id,$taxonomy,OBJECT,'edit');
  2005 	$term->term_order = $wpdb->get_var("SELECT term_order FROM $wpdb->term_relationships WHERE object_id =  $term_id AND term_taxonomy_id = $group_ttid ");
  3167 	$term->term_order = $wpdb->get_var("SELECT term_order FROM $wpdb->term_relationships WHERE object_id =  $term_id AND term_taxonomy_id = $group_ttid ");
  2006 	return $term;
  3168 	return $term;
  2007 }
  3169 }
  2008 
  3170 
  2009 /**** Functions using the class ****/
  3171 /* *** Functions using the xili-language class *** */
       
  3172 
       
  3173 /**
       
  3174  * function to progressively replace the previous constant THEME_TEXTDOMAIN only usable in mono site
       
  3175  *
       
  3176  * @since 1.5.2
       
  3177  */
       
  3178 function the_theme_domain() {
       
  3179 	global $xili_language;
       
  3180 	return $xili_language->thetextdomain;	
       
  3181 } 
       
  3182 
       
  3183 
  2010 /**
  3184 /**
  2011  * Return the current language of theme.
  3185  * Return the current language of theme.
  2012  *
  3186  *
  2013  * @since 0.9.7
  3187  * @since 0.9.7
  2014  * use for other function elsewhere
  3188  * use for other function elsewhere
  2028  *
  3202  *
  2029  * @return array with slug of language (used in query) and dir (ltr or rtl).
  3203  * @return array with slug of language (used in query) and dir (ltr or rtl).
  2030  */
  3204  */
  2031 function the_cur_lang_dir() {
  3205 function the_cur_lang_dir() {
  2032 	global $xili_language;
  3206 	global $xili_language;
  2033 	return array('lang'=>$xili_language->curlang, 'direction'=>$xili_language->curlang_dir);
  3207 	return array( QUETAG=>$xili_language->curlang, 'direction'=>$xili_language->curlang_dir );
  2034 }
  3208 }
  2035 
  3209 
  2036 /**
  3210 /**
  2037  * Return the current group of languages
  3211  * Return the current group of languages
  2038  *
  3212  *
  2042 	global $xili_language;
  3216 	global $xili_language;
  2043 	return $xili_language->langs_group_id;
  3217 	return $xili_language->langs_group_id;
  2044 } 
  3218 } 
  2045 
  3219 
  2046 /**
  3220 /**
       
  3221  * Return the feature of language
       
  3222  * Used by xili_language_list hook to hidden checked language
       
  3223  *
       
  3224  * @since 1.8.9.1
       
  3225  */
       
  3226 function xl_lang_features ( $slug, $param ) {
       
  3227 	global $xili_language;
       
  3228 	return $xili_language->xili_settings['lang_features'][$slug][$param];
       
  3229 }
       
  3230 
       
  3231 /**
  2047  * Return the current date or a date formatted with strftime.
  3232  * Return the current date or a date formatted with strftime.
  2048  *
  3233  *
  2049  * @since 0.9.7.1
  3234  * @since 0.9.7.1
       
  3235  * @updated 1.6.0 - timezone offset - http://core.trac.wordpress.org/ticket/11672
  2050  * can be used in theme for multilingual date
  3236  * can be used in theme for multilingual date
  2051  * @param format and time (if no time = current date-time)
  3237  * @param format and time (if no time = current date-time)
  2052  * @return the formatted date.
  3238  * @return the formatted date.
  2053  */
  3239  */
  2054 function the_xili_local_time($format='%B %d, %Y',$time = null) {
  3240 function the_xili_local_time( $format='%B %d, %Y',$time = null ) {
  2055 	global $xili_language;
  3241 	global $xili_language;
  2056 	if ($time == null ) $time = time();
  3242 	if ($time == null ) {
  2057 	$curlang = $xili_language->curlang;
  3243 		$time = current_time('timestamp'); //to get the Unix timestamp with a timezone offset - 
  2058 	$curlang = substr($curlang,0,3).strtoupper(substr($curlang,-2));
  3244 	}
       
  3245 	$curslug = $xili_language->curlang;
       
  3246 	$curlang = ( strlen($curslug) == 5 ) ? substr($curslug,0,3).strtoupper(substr($curslug,-2)) : $curslug ;
  2059 	setlocale(LC_TIME, $curlang); /* work if server is ready */
  3247 	setlocale(LC_TIME, $curlang); /* work if server is ready */
  2060 	return htmlentities(strftime(__($format,THEME_TEXTDOMAIN),$time),ENT_COMPAT); /* ,'UTF-8' entities for some server */
  3248 	$charset = ( $xili_language->xili_settings['lang_features'][$curslug]['charset'] != '' ) ? $xili_language->xili_settings['lang_features'][$curslug]['charset'] : "" ; // 1.8.9.1
       
  3249 	if ( "" != $charset  ) {
       
  3250 	  return htmlentities( strftime(__( $format, the_theme_domain() ),$time), ENT_COMPAT, $charset ); /* ,'UTF-8' entities for some server */
       
  3251 	} else {
       
  3252 	 	return htmlentities( strftime(__( $format, the_theme_domain() ),$time), ENT_COMPAT );
       
  3253 	}
       
  3254 }
       
  3255 
       
  3256 /**
       
  3257  * Return the current date or a date formatted with strftime according get_option php date format.
       
  3258  *
       
  3259  * @since 1.6.0, 1.8.9.1, 2.2.2
       
  3260  * 
       
  3261  * can be used in theme for multilingual date 
       
  3262  * @param format and time (if no time = current date-time)
       
  3263  * @return the formatted date.
       
  3264  */
       
  3265 function the_xili_wp_local_time( $wp_format='F j, Y', $time = null ) {
       
  3266 	global $xili_language;
       
  3267 	if ($time == null ) {
       
  3268 		$time = current_time('timestamp'); //to get the Unix timestamp with a timezone offset - 
       
  3269 	}
       
  3270 	$curslug = $xili_language->curlang; 
       
  3271 	if ( $xili_language->xili_settings['lang_features'][$curslug]['charset'] == 'no_locale' ) { // need to be inside charset input
       
  3272 		$date_formatted = date ( __($wp_format, the_theme_domain(), $time ) );
       
  3273 		if ( function_exists ( 'xili_translate_date' ) ) 
       
  3274 			return xili_translate_date ( $curslug, $date_formatted );
       
  3275 		else
       
  3276 			return $date_formatted ;
       
  3277 	} else {
       
  3278 		$curlang = ( strlen($curslug) == 5 ) ? substr($curslug,0,3).strtoupper(substr($curslug,-2)) : $curslug ;
       
  3279 		setlocale(LC_TIME, $curlang); /* work if server is ready */
       
  3280 		$format = xiliml_php2loc_time_format_translator (__($wp_format, the_theme_domain())); /* translated by theme mo*/
       
  3281 		
       
  3282 		$charset = ( $xili_language->xili_settings['lang_features'][$curslug]['charset'] != '' ) ? $xili_language->xili_settings['lang_features'][$curslug]['charset'] : "" ; // 1.8.9.1
       
  3283 		if ( "" != $charset  ) {
       
  3284 			return htmlentities(strftime($format, $time),ENT_COMPAT, $charset  ); /* ,'UTF-8' entities for some server - ja char */
       
  3285 		} else {
       
  3286 			return htmlentities(strftime($format, $time),ENT_COMPAT  );
       
  3287 		}
       
  3288 	}
       
  3289 }
       
  3290 
       
  3291 /**
       
  3292  * Return translated format from php time to loc time used in strftime.
       
  3293  *
       
  3294  * @since 1.6.0 
       
  3295  * @updated 1.8.1 - add T -> %z, e -> %Z - 1.8.7 T -> %Z (stephen)
       
  3296  * @ 1.8.9.1 - add n -> %m (japanese)
       
  3297  * (was formerly in xilidev-libraries)
       
  3298  * can be used in theme for multilingual date 
       
  3299  * @param phpformat
       
  3300  * @return locale format.
       
  3301  */
       
  3302 function xiliml_php2loc_time_format_translator ( $phpformat = 'm/d/Y H:i' ) {
       
  3303 	/* order left to right to avoid over replacing DON'T MODIFY */
       
  3304 	$phpformchar = array('A' ,'a' ,'D' ,'l' ,'g' ,'d' ,'e' ,'j' ,'z' ,'T' ,'N' ,'w ','W' ,'M' ,'F' ,'h' ,'M ','m' ,'y' ,'Y' ,'H' ,'G' ,'i' ,'S' ,'s' ,'O','n');
       
  3305 	/* doc here: http://fr2.php.net/manual/en/function.date.php */
       
  3306 	$locformchar = array('%p','%P','%a','%A','%l','%d','%Z','%e','%j','%Z','%U','%w','%W','%b','%B','%I', '%h', '%m','%y','%Y','%H','%l','%M', '','%S','%z','%m');
       
  3307 	/* doc here: http://fr.php.net/manual/en/function.strftime.php */
       
  3308 	
       
  3309    if ('' == $phpformat) $phpformat = 'm/d/Y H:i';
       
  3310    // use to detect escape char that illustrate date or hour... \h or \m
       
  3311    	$ars = explode('\\', $phpformat ); $i=0;
       
  3312 	if ($ars[0] == $phpformat) {
       
  3313 		$locform = str_replace($phpformchar, $locformchar,$phpformat);
       
  3314 	} else {
       
  3315 		$locform = "";
       
  3316 		foreach ($ars as $a) {
       
  3317 			if (""!= $a) {
       
  3318 			$locform = $locform.((0 == $i) ? str_replace($phpformchar, $locformchar,$a) : substr($a,0,1).str_replace($phpformchar, $locformchar, substr($a,1)) );
       
  3319 			}
       
  3320 			$i++;
       
  3321 		}
       
  3322 	
       
  3323 	}
       
  3324    	return $locform ; 
  2061 }
  3325 }
  2062 
  3326 
  2063 /**
  3327 /**
  2064  * Return the language of current post in loop.
  3328  * Return the language of current post in loop.
  2065  *
  3329  *
  2066  * @since 0.9.7.0
  3330  * @since 0.9.7.0
  2067  * @updated 0.9.9
  3331  * @updated 0.9.9, 2.6
  2068  * useful for functions in functions.php or other plugins
  3332  * useful for functions in functions.php or other plugins
  2069  * 
  3333  * 
  2070  * @param ID of the post
  3334  * @param ID of the post, $type 
  2071  * @return the name of language as ISO code (en_US).
  3335  * @return the slug (en_us) or iso (en_US) or name ( english )...
  2072  */
  3336  */
  2073 function get_cur_language($post_ID) {
  3337 function get_cur_language( $post_ID, $type = 'slug' ) {
  2074 	global $xili_language;
  3338 	global $xili_language;
  2075 	$langpost = $xili_language->get_cur_language($post_ID);
  3339 	return $xili_language->get_post_language( $post_ID, $type );
  2076 	return $langpost['lang'];
       
  2077 }
  3340 }
  2078 
  3341 
  2079 /**
  3342 /**
  2080  * Return the lang and dir of language of current post in loop.
  3343  * Return the lang and dir of language of current post in loop.
  2081  *
  3344  *
  2082  * @since 0.9.9
  3345  * @since 0.9.9
  2083  * useful for functions in functions.php or other plugins
  3346  * useful for functions in functions.php or other plugins
  2084  * 
  3347  * 
  2085  * @param ID of the post
  3348  * @param ID of the post
  2086  * @return array two params : lang and direction of lang (ltr or rtl).
  3349  * @return array two params : lang (as slug) and direction of lang (ltr or rtl).
  2087  */
  3350  */
  2088 function get_cur_post_lang_dir($post_ID) {
  3351 function get_cur_post_lang_dir( $post_ID ) {
  2089 	global $xili_language;
  3352 	global $xili_language;
  2090 	return $xili_language->get_cur_language($post_ID);
  3353 	return $xili_language->get_cur_language($post_ID);
  2091 }
  3354 }
       
  3355 
       
  3356 /**
       
  3357  * Return languages objects in taxinomy. Useful for hooks as in functions.php of theme
       
  3358  *
       
  3359  * @since 1.6.0
       
  3360  * @param $force to avoid buffer
       
  3361  */
       
  3362  function xili_get_listlanguages( $force = false ) {
       
  3363  	global $xili_language;
       
  3364  	return $xili_language->get_listlanguages( $force );
       
  3365  }
  2092 
  3366 
  2093 /**
  3367 /**
  2094  * Return language object of a post.
  3368  * Return language object of a post.
  2095  *
  3369  *
  2096  * @since 1.1.8
  3370  * @since 1.1.8
  2097  * useful for functions in functions.php or other plugins
  3371  * useful for functions in functions.php or other plugins
  2098  * 
  3372  * 
  2099  * @param ID of the post
  3373  * @param ID of the post
  2100  * @return false or object with params as in current term (->description = full name of lang, ->count = number of posts in this language,...
  3374  * @return false or object with params as in current term (->description = full name of lang, ->count = number of posts in this language,...
  2101  */
  3375  */
  2102 function xiliml_get_lang_object_of_post($post_ID) {
  3376 function xiliml_get_lang_object_of_post( $post_ID ) {
  2103 	
  3377 	
  2104 	$ress = wp_get_object_terms($post_ID, TAXONAME); /* lang of target post */
  3378 	$ress = wp_get_object_terms( $post_ID, TAXONAME ); /* lang of target post */
  2105 	if ($ress == array()) {
  3379 	if ( $ress == array() ) {
  2106 		return false;
  3380 		return false;
  2107 	} else {
  3381 	} else {
  2108 		//print_r($ress[0]);
       
  2109 		return $ress[0];
  3382 		return $ress[0];
  2110 	}
  3383 	}
  2111 }
  3384 }
  2112 
  3385 
  2113 /**
  3386 /**
  2136  */
  3409  */
  2137 function choice_of_browsing_lang_dir() {
  3410 function choice_of_browsing_lang_dir() {
  2138 	global $xili_language;
  3411 	global $xili_language;
  2139 	$lang = $xili_language->choice_of_browsing_language();
  3412 	$lang = $xili_language->choice_of_browsing_language();
  2140 	$dir = $xili_language->get_dir_of_cur_language($lang);
  3413 	$dir = $xili_language->get_dir_of_cur_language($lang);
  2141 	return array('lang'=>$lang,'direction'=>$dir);
  3414 	return array( QUETAG => $lang,' direction' => $dir );
  2142 }
  3415 }
  2143 
  3416 
  2144 /**
  3417 /**
  2145  * Activate hooks of plugin in class.
  3418  * Activate hooks of plugin in class.
  2146  *
  3419  *
  2148  * can be used in functions.php for special action
  3421  * can be used in functions.php for special action
  2149  *
  3422  *
  2150  * @param filter name and function
  3423  * @param filter name and function
  2151  * 
  3424  * 
  2152  */
  3425  */
  2153 function add_again_filter($filtername,$filterfunction) {
  3426 function add_again_filter( $filtername, $filterfunction ) {
  2154 	global $xili_language;
  3427 	global $xili_language;
  2155 	$xili_language->add_filter($filtername,$filterfunction);
  3428 	$xili_language->add_filter( $filtername, $filterfunction );
  2156 }
  3429 }
  2157 
  3430 
  2158 /**
  3431 /**
  2159  * Replace get_category_link to bypass hook from xili_language
  3432  * Replace get_category_link to bypass hook from xili_language
  2160  *
  3433  *
  2163  * can be used in functions.php for special action needing permalink
  3436  * can be used in functions.php for special action needing permalink
  2164  
  3437  
  2165  * @param category ID 
  3438  * @param category ID 
  2166  * @return the permalink of passed cat_id.
  3439  * @return the permalink of passed cat_id.
  2167  */
  3440  */
  2168 function xiliml_get_category_link($catid = 0) {
  3441 function xiliml_get_category_link( $catid = 0 ) {
  2169 			global $xili_language;
  3442 			global $xili_language;
  2170 			if ($catid == 0) {
  3443 			if ($catid == 0) {
  2171 				global $wp_query;
  3444 				global $wp_query;
  2172 				$catid = $wp_query->query_vars['cat'];
  3445 				$catid = $wp_query->query_vars['cat'];
  2173 			}
  3446 			}
  2174 			remove_filter('category_link', $xili_language->idx['xiliml_link_append_lang']);
  3447 			remove_filter('category_link', $xili_language->idx['xiliml_link_append_lang']);
  2175 				$catcur = get_category_link($catid); 
  3448 				$catcur = get_category_link($catid); 
  2176 			add_again_filter('category_link', 'xiliml_link_append_lang');
  3449 			add_again_filter('category_link', 'xiliml_link_append_lang');
  2177 	return $catcur;
  3450 	return $catcur;
  2178 }
  3451 }
  2179 /* used by xili widget - usable if you need to create your own template tag 
  3452 
       
  3453 /** used by xili widget - usable if you need to create your own template tag 
  2180  *
  3454  *
  2181  * @since 0.9.9.4
  3455  * @since 0.9.9.4
  2182  * @param quantity of comments
  3456  * @param quantity of comments
  2183  *
  3457  *
  2184  * @return comments objects...
  3458  * @return comments objects...
  2185  */
  3459  */
  2186 function xiliml_recent_comments($number = 5) {
  3460 function xiliml_recent_comments( $number = 5 ) {
  2187 	global $xili_language;
  3461 	global $xili_language;
  2188 	return $xili_language->xiliml_recent_comments($number);
  3462 	return $xili_language->xiliml_recent_comments( $number );
  2189 }
  3463 }
  2190 
  3464 
  2191 /**
  3465 /**
  2192  * Return full object of a language
  3466  * Return full object of a language
  2193  * @since 1.1.8
  3467  * @since 1.1.8
  2194  * @param name (fr_FR) or slug (fr_fr)
  3468  * @param name (fr_FR) or slug (fr_fr)
  2195  * @return false or full language object (example ->description = full as set in admin UI)
  3469  * @return false or full language object (example ->description = full as set in admin UI)
  2196  */
  3470  */
  2197 function xiliml_get_language($lang_nameorslug="") {
  3471 function xiliml_get_language( $lang_nameorslug="" ) {
  2198 	$language = is_term( $lang_nameorslug, TAXONAME );
  3472 	$language = term_exists( $lang_nameorslug, TAXONAME );
  2199 	if ($language) {
  3473 	if ($language) {
  2200 		return get_term($language['term_id'],TAXONAME,OBJECT,'edit');
  3474 		return get_term( $language['term_id'], TAXONAME,OBJECT, 'edit' );
  2201 	} else {
  3475 	} else {
  2202 		return false;	
  3476 		return false;	
  2203 	}
  3477 	}
  2204 }
  3478 }
  2205  
  3479  
  2211 	 
  3485 	 
  2212 /**
  3486 /**
  2213  * Template Tag insertable in search form for sub-selection of a language
  3487  * Template Tag insertable in search form for sub-selection of a language
  2214  *
  3488  *
  2215  * @since 0.9.7
  3489  * @since 0.9.7
       
  3490  * @updated 1.8.2
  2216  * can be used in theme template
  3491  * can be used in theme template
  2217  * example: if(class_exists('xili_language')) xiliml_langinsearchform()
  3492  * example: if(class_exists('xili_language')) xiliml_langinsearchform()
  2218  *
  3493  *
  2219  * hook: add_action('xiliml_langinsearchform','your_xiliml_langinsearchform',10,2) to change its behaviour elsewhere
  3494  * hook: add_action('xiliml_langinsearchform','your_xiliml_langinsearchform',10,2) to change its behaviour elsewhere
  2220  * @param html tags 
  3495  * @param html tags 
  2221  * @return echo the list as radio-button
  3496  * @return echo the list as radio-button
  2222  */	 
  3497  */	 
  2223 function xiliml_langinsearchform ($before='',$after='') { /* list of radio buttons for search form*/
  3498 function xiliml_langinsearchform ( $before='', $after='', $echo = true ) { /* list of radio buttons for search form*/
  2224 	global $xili_language;
  3499 	global $xili_language;
  2225 	if ($xili_language->this_has_filter('xiliml_langinsearchform')){ 
  3500 	if ($xili_language->this_has_filter('xiliml_langinsearchform')){ 
  2226 		remove_filter('xiliml_langinsearchform',$xili_language->idx['xiliml_langinsearchform']); /*no default from class*/
  3501 		remove_filter('xiliml_langinsearchform',$xili_language->idx['xiliml_langinsearchform']); /*no default from class*/
  2227 	}
  3502 	}
  2228 	do_action('xiliml_langinsearchform',$before,$after);	
  3503 	if ( $echo ) {
       
  3504 		echo apply_filters( 'xiliml_langinsearchform', $before, $after, $echo);	
       
  3505 	} else {
       
  3506 		return apply_filters( 'xiliml_langinsearchform', $before, $after, $echo);
       
  3507 	}
  2229 }
  3508 }
  2230 
  3509 
  2231 /**
  3510 /**
  2232  * Template Tag - replace the_category() tag of WP Core
  3511  * Template Tag - replace the_category() tag of WP Core
  2233  *
  3512  *
  2234  * @since 0.9.0
  3513  * @since 0.9.0
       
  3514  * @updated 1.4.2 - default value to post_ID
  2235  * can be used in theme template in each post in loop
  3515  * can be used in theme template in each post in loop
  2236  * example: if(class_exists('xili_language')) xiliml_the_category($post->ID)
  3516  * example: if(class_exists('xili_language')) xiliml_the_category($post->ID)
  2237  *
  3517  *
  2238  * hook: add_action('xiliml_the_category','your_xiliml_the_category',10,3) to change its behaviour elsewhere
  3518  * hook: add_action('xiliml_the_category','your_xiliml_the_category',10,3) to change its behaviour elsewhere
  2239  * @param post_id separator echo (true by default) 
  3519  * @param post_id separator echo (true by default) 
  2240  * @return echo (by default) the list of cats with comma separated...
  3520  * @return echo (by default) the list of cats with comma separated...
  2241  */
  3521  */
  2242 function xiliml_the_category($post_ID, $separator = ', ' ,$echo = true) { /* replace the_category() */
  3522 function xiliml_the_category( $post_ID = 0, $separator = ', ' , $echo = true ) { /* replace the_category() */
  2243 	global $xili_language;
  3523 	global $xili_language, $post;
       
  3524 	if ($post_ID == 0) $post_ID = $post->ID;
  2244 	if ($xili_language->this_has_filter('xiliml_the_category')){ 
  3525 	if ($xili_language->this_has_filter('xiliml_the_category')){ 
  2245 		remove_filter('xiliml_the_category',$xili_language->idx['xiliml_the_category']); /*no default from class*/
  3526 		remove_filter('xiliml_the_category',$xili_language->idx['xiliml_the_category']); /*no default from class*/
  2246 	}
  3527 	}
  2247 	do_action('xiliml_the_category',$post_ID,$separator,$echo);
  3528 	do_action('xiliml_the_category',$post_ID,$separator,$echo);
  2248 }
  3529 }
  2250 /**
  3531 /**
  2251  * Template Tag - in loop display the link of other posts defined as in other languages
  3532  * Template Tag - in loop display the link of other posts defined as in other languages
  2252  *
  3533  *
  2253  * @since 0.9.0
  3534  * @since 0.9.0
  2254  * @updated 0.9.9.2, 1.1 (can return an array of lang + id)
  3535  * @updated 0.9.9.2, 1.1 (can return an array of lang + id)
       
  3536  * @updated 1.4.2 - default value to post_ID
  2255  * can be used in theme template in single.php under the title
  3537  * can be used in theme template in single.php under the title
  2256  * example: if(class_exists('xili_language')) xiliml_the_other_posts($post->ID)
  3538  * example: if(class_exists('xili_language')) xiliml_the_other_posts($post->ID)
  2257  *
  3539  *
  2258  * hook: add_action('xiliml_the_other_posts','your_xiliml_the_other_posts',10,3) to change its behaviour elsewhere
  3540  * hook: add_action('xiliml_the_other_posts','your_xiliml_the_other_posts',10,3) to change its behaviour elsewhere
  2259  * @param post_id before separator type (echo, array)
  3541  * @param post_id, before, separator, type (echo, array).
  2260  * @return echo (by default) the list 
  3542  * @return echo (by default) the list 
  2261  */
  3543  */
  2262 function xiliml_the_other_posts ($post_ID,$before = "This post in", $separator = ", ", $type = "display") { /* display the other posts defined as in other lang */
  3544 function xiliml_the_other_posts ( $post_ID = 0, $before = "This post in", $separator = ", ", $type = "display" ) { /* display the other posts defined as in other lang */
  2263 	global $xili_language;
  3545 	global $xili_language, $post;
       
  3546 	if ($post_ID == 0) $post_ID = $post->ID;
  2264 	if ($xili_language->this_has_filter('xiliml_the_other_posts')){ 
  3547 	if ($xili_language->this_has_filter('xiliml_the_other_posts')){ 
  2265 		remove_filter('xiliml_the_other_posts',$xili_language->idx['xiliml_the_other_posts']); /*no default from class*/
  3548 		remove_filter('xiliml_the_other_posts',$xili_language->idx['xiliml_the_other_posts']); /*no default from class*/
  2266 	}
  3549 	}
  2267 	return apply_filters('xiliml_the_other_posts',$post_ID, $before, $separator,$type);
  3550 	return apply_filters('xiliml_the_other_posts',$post_ID, $before, $separator,$type);
  2268 }
  3551 }
  2276  *
  3559  *
  2277  * hook: add_action('xili_post_language','your_xili_post_language',10,2) to change its behaviour elsewhere
  3560  * hook: add_action('xili_post_language','your_xili_post_language',10,2) to change its behaviour elsewhere
  2278  * @param before after 
  3561  * @param before after 
  2279  * @return echo (by default) the language 
  3562  * @return echo (by default) the language 
  2280  */
  3563  */
  2281 function xili_post_language($before = '<span class="xili-lang">(', $after =')</span>') { /* post language in loop*/
  3564 function xili_post_language( $before = '<span class="xili-lang">(', $after =')</span>' ) { /* post language in loop*/
  2282 	do_action('xili_post_language',$before, $after);
  3565 	do_action( 'xili_post_language',$before, $after );
  2283 }
  3566 }
  2284 
  3567 
  2285 /**
  3568 /**
  2286  * Template Tag - outside loop (sidebar) display the languages of the site (used also by widget)
  3569  * Template Tag - outside loop (sidebar) display the languages of the site (used also by widget)
  2287  *
  3570  *
  2288  * @since 0.9.0
  3571  * @since 0.9.0
  2289  * @updated 0.9.7.4
  3572  * @updated 0.9.7.4
       
  3573  * @udpated 1.8.9.1 
  2290  * can be used in theme template in sidebar menu or header menu
  3574  * can be used in theme template in sidebar menu or header menu
  2291  * example: if(class_exists('xili_language')) xili_language_list()
  3575  * example: if(class_exists('xili_language')) xili_language_list()
  2292  * theoption param is used to define type of display according places (sidebar / header) in theme (see dev.xiligroup.com)
  3576  * theoption param is used to define type of display according places (sidebar / header) in theme (see dev.xiligroup.com)
  2293  *
  3577  *
  2294  * hook: add_action('xili_language_list','your_xili_language_list',10,3) to change its behaviour elsewhere
  3578  * hook: add_action('xili_language_list','your_xili_language_list',10,5) to change its behaviour elsewhere
  2295  * @param before after theoption
  3579  * @param before after theoption
  2296  * @return echo the list of languages
  3580  * @return echo the list of languages
       
  3581  * @hidden don't list hidden languages
  2297  */
  3582  */
  2298 function xili_language_list($before = '<li>', $after ='</li>', $theoption='') { /* list of languages i.e. in sidebar */
  3583 function xili_language_list( $before = '<li>', $after ='</li>', $theoption='', $echo = true, $hidden = false ) { 
       
  3584 	
  2299 	global $xili_language;
  3585 	global $xili_language;
  2300 	if ($xili_language->this_has_filter('xili_language_list')){ 
  3586 	if ($xili_language->this_has_filter('xili_language_list')){ 
  2301 		remove_filter('xili_language_list',$xili_language->idx['xili_language_list']); /*no default from class*/
  3587 		remove_filter('xili_language_list',$xili_language->idx['xili_language_list']); /*no default from class*/
  2302 	}	
  3588 	}	
  2303 	do_action('xili_language_list',$before,$after,$theoption); 
  3589 	return apply_filters('xili_language_list', $before, $after, $theoption, $echo, $hidden ); 
  2304 }
  3590 }
       
  3591 
       
  3592 /** 
       
  3593  * function to get id, link or permalink of linked post in target lang
       
  3594  * to replace get_post_meta($post->ID, 'lang-'.$language->slug, true) soon obsolete
       
  3595  * @since 1.8.9.1
       
  3596  *
       
  3597  * @updated 2.1.0 - permalink as 
       
  3598  */
       
  3599 function xl_get_linked_post_in ( $fromID, $lang, $info = 'id' ) {
       
  3600 	global $xili_language;
       
  3601 	
       
  3602 	$language = xiliml_get_language( $lang ); /* test if lang is available */
       
  3603 	
       
  3604 	if ( $language !== false ) {
       
  3605 		$otherpost = get_post_meta( $fromID, QUETAG.'-'.$language->slug, true ); // will be soon changed
       
  3606 		if ( $info == 'permalinknav') return  $xili_language ->link_of_linked_post ( $fromID, $language->slug );
       
  3607 	
       
  3608 		if ( $otherpost ) { 
       
  3609 			switch ( $info ) {
       
  3610 				case 'id';
       
  3611 					$output = $otherpost;
       
  3612 					break;
       
  3613 				case 'link';
       
  3614 					$post = get_post($otherpost);
       
  3615 			        if ( isset($post->post_type) ){
       
  3616 			         	if ( 'post' == $post->post_type ) {
       
  3617 							$output = home_url('?p=' . $otherpost);
       
  3618 			         	} elseif ( 'post' == $post->post_type ) {
       
  3619 			         		$output = home_url('?page_id=' . $otherpost);
       
  3620 			         	}
       
  3621 			        }
       
  3622 					break;
       
  3623 				case 'permalink';
       
  3624 					$output = get_permalink( $otherpost );
       
  3625 					break;	
       
  3626 			}
       
  3627 		} else {
       
  3628 			switch ( $info ) {
       
  3629 				case 'id';
       
  3630 					$output = 0; // false
       
  3631 					break;
       
  3632 				case 'link';
       
  3633 					$output = '#';
       
  3634 					break;
       
  3635 				case 'permalink';
       
  3636 					$output = '#';
       
  3637 					break;	
       
  3638 			}
       
  3639 			
       
  3640 		}
       
  3641 		return $output;
       
  3642 	}
       
  3643 }
       
  3644 
       
  3645 /** 
       
  3646  * Insert automatically some languages items at end in menu
       
  3647  * @since 1.6.0
       
  3648  * @updated 1.7.1 - add optionally wp_page_list result
       
  3649  * @updated 1.8.1 - choose good menu location
       
  3650  * @updated 1.8.9 - add filter (example: add_filter ('xili_nav_lang_list', 'my_xili_nav_lang_list', 10, 3);)
       
  3651  *					 and class for separator  ( example: li.menu-separator a {display:none;})
       
  3652  *
       
  3653  * updated 2.1.0 - for multiple navmenu locations - CAUTION new filter: xili_nav_lang_lists (with s at end)
       
  3654  */
       
  3655 function xili_nav_lang_list( $items, $args ) {
       
  3656 	global $xili_language;
       
  3657 	
       
  3658 	if ( isset ( $xili_language->xili_settings['navmenu_check_options'] ) ) {
       
  3659 		$navmenu_check_options = $xili_language->xili_settings['navmenu_check_options']; 
       
  3660 		
       
  3661 		if ( has_filter( 'xili_nav_lang_lists' ) ) return apply_filters ( 'xili_nav_lang_lists',  $items, $args, $navmenu_check_options );
       
  3662 			
       
  3663 		if ( isset ( $navmenu_check_options[$args->theme_location] ) && $navmenu_check_options[$args->theme_location]['navenable'] == 'enable' ) { 
       
  3664 			
       
  3665 			$navmenu = ( '' != $navmenu_check_options[$args->theme_location]['navtype'] ) ? $navmenu_check_options[$args->theme_location]['navtype'] : "navmenu-1";
       
  3666 			
       
  3667 			$end = xili_language_list( '<li>', '</li>', $navmenu, false, true ) ; // don't display hidden languages
       
  3668 			
       
  3669 	   		return $items.'<li class="menu-item menu-separator" ><a>|</a></li>'.$end; // class for display none... 
       
  3670 	   	
       
  3671 		} else {
       
  3672 			return $items;
       
  3673 		}
       
  3674 		
       
  3675 	} else { // if settings not updated since updated by admin user
       
  3676 		$navmenu_check_option = $xili_language->xili_settings['navmenu_check_option'];
       
  3677 		if ( has_filter( 'xili_nav_lang_list' ) ) return apply_filters ( 'xili_nav_lang_list',  $items, $args, $navmenu_check_option );
       
  3678 		if ( $args->theme_location  ==  $navmenu_check_option ) { 
       
  3679 		
       
  3680 			$end = xili_language_list( '<li>', '</li>', 'navmenu', false, true ) ; // don't display hidden languages 1.8.9.1
       
  3681 			
       
  3682    			return $items.'<li class="menu-item menu-separator" ><a>|</a></li>'.$end; // class for display none... 1.8.9 no ID for instantiations
       
  3683    	
       
  3684 		} else {
       
  3685 			return $items;
       
  3686 		}
       
  3687 	}
       
  3688 }
       
  3689 
       
  3690 /** 
       
  3691  * Insert automatically some pages items at end in menu
       
  3692  * @since 1.7.1 - add optionally wp_page_list result
       
  3693  * @updated 1.8.1 - choose good menu location
       
  3694  * @updated 1.8.9 - add filter (example: add_filter ('xili_nav_page_list', 'my_xili_nav_page_list', 10, 3);)
       
  3695  *
       
  3696  */ 
       
  3697 function xili_nav_page_list( $items, $args ) {
       
  3698 	global $xili_language;
       
  3699 	$navmenu_check_option = $xili_language->xili_settings['navmenu_check_optionp'];
       
  3700 	if ( has_filter( 'xili_nav_page_list' ) ) return apply_filters ( 'xili_nav_page_list',  $items, $args, $navmenu_check_option );
       
  3701 	if ( $navmenu_check_option == $args->theme_location ) {
       
  3702 		$pagelist = ''; 
       
  3703 		$pagelist_args = $xili_language->xili_settings['args_page_in_nav_menu'].'&';
       
  3704 		// sub-selection
       
  3705 		$pagelist = wp_list_pages($pagelist_args."title_li=&echo=0&".QUETAG."=".$xili_language->curlang);
       
  3706 	
       
  3707    		return $items.$pagelist;
       
  3708    	} else {
       
  3709 		return $items;
       
  3710 	}
       
  3711 }
       
  3712 
       
  3713 /** 
       
  3714  * modify automatically home page item in nav menu - exemple for twentyten child menu
       
  3715  * @since 1.8.9.2 
       
  3716  *  
       
  3717  * filter (example: add_filter ('xili_nav_page_home_item', 'my_xili_nav_page_home_item', 10, 5);)
       
  3718  *
       
  3719  */ 
       
  3720 function xili_nav_page_home_item( $item_output, $item, $depth, $args ) {
       
  3721 	global $xili_language;
       
  3722 	$homemenu_check_option = $xili_language->xili_settings['home_item_nav_menu'];
       
  3723 	if ( has_filter( 'xili_nav_page_home_item' ) ) return apply_filters ( 'xili_nav_page_home_item',  $item_output, $item, $depth, $args, $homemenu_check_option ); // fixed 2.8
       
  3724 	
       
  3725 	if ( $item->url == get_option('siteurl').'/'  ) { // page or list
       
  3726 		$curlang = $xili_language->curlang ;
       
  3727 		
       
  3728 		$attributes  = ! empty( $item->attr_title ) ? ' title="'  . __( esc_attr( $item->attr_title ), $xili_language->thetextdomain ) .'"' : ''; //
       
  3729 		$attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
       
  3730 		$attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
       
  3731 		$attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'?'.QUETAG.'='.$curlang.'"' : ''; //
       
  3732 
       
  3733 		$item_output = $args->before;
       
  3734 		$item_output .= '<a'. $attributes .'>';
       
  3735 		$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
       
  3736 		$item_output .= '</a>';
       
  3737 		$item_output .= $args->after;
       
  3738 		return $item_output;
       
  3739    	} else {
       
  3740 		return $item_output;
       
  3741 	}
       
  3742 }
       
  3743 
  2305 
  3744 
  2306 /*
  3745 /*
  2307  * sub selection of pages for wp_list_pages()
  3746  * sub selection of pages for wp_list_pages()
  2308  * @ since 090504 - exemple of new function add here or addable in functions.php
  3747  * @ since 090504 - exemple of new function add here or addable in functions.php
  2309  * © xiligroup.dev
  3748  * © xiligroup.dev
  2311  * only called if xili-language plugin is active and query tag 'lang' is in wp_list_pages template tag
  3750  * only called if xili-language plugin is active and query tag 'lang' is in wp_list_pages template tag
  2312  *
  3751  *
  2313  * example 1 : wp_list_pages('title_li=&lang='.the_curlang() ); will display only pages of current lang
  3752  * example 1 : wp_list_pages('title_li=&lang='.the_curlang() ); will display only pages of current lang
  2314  *
  3753  *
  2315  * example 2 : wp_list_pages('title_li=&setlang=0&lang='.the_curlang() ); will display pages of current lang AND pages with lang undefined (polyglot pages).
  3754  * example 2 : wp_list_pages('title_li=&setlang=0&lang='.the_curlang() ); will display pages of current lang AND pages with lang undefined (polyglot pages).
       
  3755  * example 3 : wp_list_pages('title_li=&echo=0&include=2,10&lang='); will display pages of current lang (new since 2.2.2) useful with xili-widget plugin
  2316  *
  3756  *
  2317  */
  3757  */
  2318 function ex_pages_by_lang ($pages, $r) {
  3758 function ex_pages_by_lang ( $pages, $r ) {
  2319 	if (isset($r['lang']) && !empty($pages) && function_exists('get_cur_post_lang_dir')) {
  3759 	if (isset($r[QUETAG]) && !empty($pages) && function_exists('get_cur_post_lang_dir')) {
  2320 		$keepundefined = null;
  3760 		$keepundefined = null;
  2321 		if (isset($r['setlang'])) { 
  3761 		if (isset($r['setlang'])) { 
  2322 			if ($r['setlang'] == 0 || $r['setlang'] == 'false') $keepundefined = false;
  3762 			if ($r['setlang'] == 0 || $r['setlang'] == 'false') $keepundefined = false;
  2323 			if ($r['setlang'] == 1 || $r['setlang'] == 'true') $keepundefined = true;
  3763 			if ($r['setlang'] == 1 || $r['setlang'] == 'true') $keepundefined = true;
  2324 		}	
  3764 		}	
  2325 		$resultingpages = array();
  3765 		$resultingpages = array(); 
       
  3766 		if ( $r[QUETAG] == "" ) $r[QUETAG] = the_curlang(); // when param is here but empty = cur lang of page - 2.2.2 
  2326 		foreach ($pages as $page) {
  3767 		foreach ($pages as $page) {
  2327 			$post_lang_dir = get_cur_post_lang_dir($page->ID);
  3768 			$post_lang_dir = get_cur_post_lang_dir($page->ID);
  2328 			if ($post_lang_dir === $keepundefined) {
  3769 			if ($post_lang_dir === $keepundefined) {
  2329 					$resultingpages[] = $page;
  3770 					$resultingpages[] = $page;
  2330 			} elseif ($post_lang_dir['lang'] == $r['lang'] ) {
  3771 			} elseif ($post_lang_dir[QUETAG] == $r[QUETAG] ) {
  2331 					$resultingpages[] = $page;
  3772 					$resultingpages[] = $page;
  2332 			}
  3773 			}
  2333 		}
  3774 		}
  2334 		return $resultingpages;	
  3775 		return $resultingpages;	
  2335 	} else {	
  3776 	} else {	
  2343  * (useful for sidebar widget - see functions table)
  3784  * (useful for sidebar widget - see functions table)
  2344  * @since 1.3.0
  3785  * @since 1.3.0
  2345  * @param  lang to modify query_tag - 
  3786  * @param  lang to modify query_tag - 
  2346  *
  3787  *
  2347  */
  3788  */
  2348 
  3789 function xiliml_force_loop_lang ( $lang_query_tag ){
  2349 function xiliml_force_loop_lang ($lang_query_tag){
       
  2350 	global $xili_language, $wp_query;
  3790 	global $xili_language, $wp_query;
  2351 	$xili_language->temp_lang_query_tag = $wp_query->query_vars[QUETAG];
  3791 	$xili_language->temp_lang_query_tag = $wp_query->query_vars[QUETAG];
  2352 	$wp_query->query_vars[QUETAG] = $lang_query_tag;
  3792 	$wp_query->query_vars[QUETAG] = $lang_query_tag;
  2353 	$xili_language->current_lang_query_tag = $wp_query->query_vars[QUETAG];
  3793 	$xili_language->current_lang_query_tag = $wp_query->query_vars[QUETAG];
  2354 }
  3794 }
  2356 function xiliml_restore_loop_lang (){
  3796 function xiliml_restore_loop_lang (){
  2357 	global $xili_language, $wp_query;
  3797 	global $xili_language, $wp_query;
  2358 	$wp_query->query_vars[QUETAG] = $xili_language->temp_lang_query_tag;
  3798 	$wp_query->query_vars[QUETAG] = $xili_language->temp_lang_query_tag;
  2359 	$xili_language->current_lang_query_tag = $wp_query->query_vars[QUETAG];
  3799 	$xili_language->current_lang_query_tag = $wp_query->query_vars[QUETAG];
  2360 }
  3800 }
       
  3801 
  2361 /**
  3802 /**
  2362  * functions to permit lang query tag
  3803  * functions to permit lang query tag
  2363  * (useful for WP_Query)
  3804  * (useful for WP_Query)
  2364  * @since 1.3.2
  3805  * @since 1.3.2
  2365  * example: add_action('parse_query','xiliml_add_lang_to_parsed_query');
  3806  * example: add_action('parse_query','xiliml_add_lang_to_parsed_query');
  2376 			parse_str($query, $r); 	
  3817 			parse_str($query, $r); 	
  2377 		}
  3818 		}
  2378 		if (array_key_exists(QUETAG,$r)) $wp_query->query_vars[QUETAG] = $r[QUETAG];
  3819 		if (array_key_exists(QUETAG,$r)) $wp_query->query_vars[QUETAG] = $r[QUETAG];
  2379 }
  3820 }
  2380 
  3821 
       
  3822 /* ****** functions and filter added for new default theme named twentyten and twenty-eleven (since WP 3.0) ******* */
       
  3823 
       
  3824 /** 
       
  3825  * in twentyten theme: display the time of current post when mouse is on date 
       
  3826  */
       
  3827 function xiliml_get_the_translated_time( $thetime, $format = '' ) {
       
  3828 	global $xili_language;
       
  3829 	if ( $xili_language->xili_settings['wp_locale'] == 'db_locale' ) {
       
  3830 		$theformat = (''== $format) ? get_option('time_format') : $format ;
       
  3831 		return the_xili_wp_local_time( $theformat, strtotime(xiliml_get_the_time('m/d/Y H:i'))); // old method locale
       
  3832 	} else {
       
  3833 		return $thetime; // new mode wp_locale ;
       
  3834 	}
       
  3835 }
       
  3836 
       
  3837 /** 
       
  3838  * Clone w/o filter 
       
  3839  */
       
  3840 function xiliml_get_the_time( $d = '', $post = null ) {
       
  3841 	$post = get_post($post);
       
  3842 
       
  3843 	if ( '' == $d )
       
  3844 		$the_time = get_post_time(get_option('time_format'), false, $post, true);
       
  3845 	else
       
  3846 		$the_time = get_post_time($d, false, $post, true);
       
  3847 	return $the_time; /* without filter */
       
  3848 }
       
  3849 
       
  3850 /** 
       
  3851  * in twentyten theme: display the date of current post 
       
  3852  */
       
  3853 function xiliml_get_translated_date( $thedate, $format = '' ) {
       
  3854 	global $xili_language;
       
  3855 	$theformat = (''== $format) ? get_option('date_format') : $format ;
       
  3856 	if ( $xili_language->xili_settings['wp_locale'] == 'db_locale' ) {
       
  3857 		
       
  3858 		return the_xili_wp_local_time( $theformat, strtotime(xiliml_get_the_date('m/d/Y H:i')));
       
  3859 	} else { 
       
  3860 		//echo $theformat ;
       
  3861 		return $thedate ;
       
  3862 	}
       
  3863 }
       
  3864 
       
  3865 if ( !is_admin() ) {
       
  3866 	add_filter( 'get_the_time', 'xiliml_get_the_translated_time', 10, 3);
       
  3867 	add_filter( 'get_the_date', 'xiliml_get_translated_date', 10, 2);
       
  3868 }
       
  3869 
       
  3870 /** 
       
  3871  * Clone w/o filter 
       
  3872  */
       
  3873 function xiliml_get_the_date( $d = '' ) {
       
  3874 	global $post;
       
  3875 	$the_date = '';
       
  3876 
       
  3877 	if ( '' == $d )
       
  3878 		$the_date .= mysql2date(get_option('date_format'), $post->post_date);
       
  3879 	else
       
  3880 		$the_date .= mysql2date($d, $post->post_date);
       
  3881 
       
  3882 	return $the_date; /* without filter */
       
  3883 }
       
  3884 
       
  3885 /** 
       
  3886  * filter for template tag: get_comment_date() 
       
  3887  */
       
  3888 function xiliml3_comment_date( $comment_time, $format = '' ) {
       
  3889   $theformat = ( ''== $format ) ? get_option( 'date_format' ) : $format ;
       
  3890   return the_xili_wp_local_time( $theformat, strtotime(get_comment_time ( 'm/d/Y H:i' ) ) ); 
       
  3891   /* impossible to use get_comment_date as it is itself filtered*/
       
  3892 }
       
  3893 if ( !is_admin() ) {
       
  3894 	add_filter( 'get_comment_date', 'xiliml3_comment_date',10 ,2 );
       
  3895 }
       
  3896 
       
  3897 
       
  3898 /****************** instantiation Class *****************/
  2381 
  3899 
  2382 
  3900 
  2383 /**
  3901 /**
  2384  * instantiation of xili_language class
  3902  * instantiation of xili_language class
  2385  *
  3903  *
  2386  * @since 0.9.7 - 0.9.9.4 =& for vintage server with php4 !!!! - 1.1.9
  3904  * @since 1.8.8 to verify that WP 3.0 is installed
  2387  *
  3905  * @updated for 1.8.9, 2.3.1, 2.7.1 (function)
  2388  * @param 1st metabox (for other posts in post edit UI - to replace custom fields - beta tests)
  3906  *
  2389  * @param 2nd ajax ( true if ajax is activated for post edit admin UI - alpha tests )
       
  2390  * 1.1.9
       
  2391  * @param 3rd locale_method (true for cache compatibility... in current tests with johan.eenfeldt@kostdoktorn.se)
       
  2392  */
  3907  */
  2393 $xili_language =& new xili_language(true,false,false); 
  3908 function xili_language_start () {
  2394 
  3909 	global $wp_version, $xili_language;
  2395 /**
  3910 	if ( version_compare(PHP_VERSION, XILILANGUAGE_PHP_VER, '<') ){
  2396  * Enable to add functions and filters that are not in theme's functions.php
  3911 		add_action( 'admin_notices', 'xili_language_need_php5' );
  2397  * These filters are common even if you change default theme...
  3912 		return;
  2398  * Place your functions.php in folder plugins/xilidev-libraries/
  3913 	} elseif ( version_compare($wp_version, XILILANGUAGE_WP_VER, '<') && XILILANGUAGE_VER > XILILANGUAGE_PREV_VER ) {
  2399  * if you have a filter in this file, avoid to have similar one in functions.php of the theme !!!
  3914 		add_action( 'admin_notices', 'xili_language_need_31' );
  2400  * 
  3915 		return;
  2401  * (for tests, check / uncheck 'enable gold functions' in settings UI)
  3916 	} else {
  2402  * @since 1.0
  3917 		
  2403  * @updated 1.4.0
  3918 		// new sub-folder since 2.6
       
  3919 	    require_once ( plugin_dir_path( __FILE__ ) . 'xili-includes/xili-language-widgets.php' );
       
  3920 	
       
  3921 	
       
  3922 		
       
  3923 		/**
       
  3924 	 	 * instantiation of xili_language class
       
  3925 	 	 *
       
  3926 	 	 * @since 0.9.7 
       
  3927 	 	 * @updated 2.6 
       
  3928 	 	 *
       
  3929 	 	 * 
       
  3930 	 	 * @param locale_method (true for cache compatibility... in current tests with johan.eenfeldt@kostdoktorn.se)
       
  3931 	 	 * @param future version
       
  3932 	 	 */
       
  3933 		
       
  3934 		$xili_language = new xili_language( false , false ); 
       
  3935 		
       
  3936 		if ( is_admin() ) {
       
  3937 			$plugin_path = dirname(__FILE__) ;
       
  3938 			require( $plugin_path . '/xili-includes/xl-class-admin.php' );
       
  3939 			$xili_language_admin = new xili_language_admin( $xili_language );
       
  3940 		}
       
  3941 		
       
  3942 		/**
       
  3943 		 * Enable to add functions and filters that are not in theme's functions.php
       
  3944 		 * These filters are common even if you change default theme...
       
  3945 		 * Place your functions.php in folder plugins/xilidev-libraries/
       
  3946 		 * if you have a filter in this file, avoid to have similar one in functions.php of the theme !!!
       
  3947 		 * 
       
  3948 		 * (for tests, check / uncheck 'enable gold functions' in settings UI)
       
  3949 		 * @since 1.0
       
  3950 		 * @updated 1.4.0
       
  3951 		 */
       
  3952 		$xili_language->insert_gold_functions ();
       
  3953 	}
       
  3954 }
       
  3955 
       
  3956 add_action( 'plugins_loaded', 'xili_language_start', 13 ); // before xili-dictionary (20) and xili_tidy_tags (15) - 2.7.1
       
  3957 
       
  3958 // to fixe event in WP 3.4 - 2.7.1
       
  3959 function xili_test_lang_perma () {
       
  3960 	global $xili_language ; 
       
  3961 	$xili_language->lang_perma = ( has_filter ( 'term_link', 'insert_lang_4cat' ) ) ? true : false ;	// 1.4.1 
       
  3962 }
       
  3963 add_action( 'wp', 'xili_test_lang_perma', 1 );
       
  3964 
       
  3965 
       
  3966 
       
  3967 /** 
       
  3968  * errors messages 
  2404  */
  3969  */
  2405 $xili_language->insert_gold_functions ();
  3970  
       
  3971 function xili_language_need_php5() {
       
  3972 		global $wp_version;
       
  3973 		load_plugin_textdomain( 'xili_language_errors', false, 'xili-language/languages' );
       
  3974 		echo '<div id="message" class="error fade"><p>';
       
  3975 		echo '<strong>'.__( 'Installation of xili-language is not completed.', 'xili_language_errors' ) . '</strong>';
       
  3976 		echo '<br />';
       
  3977 		printf( __( 'This xili-language version (%s) need PHP Version more than %s; installed release is %s.', 'xili_language_errors' ), XILILANGUAGE_VER , XILILANGUAGE_PHP_VER, PHP_VERSION ) ;
       
  3978 		echo '<br />';
       
  3979 		printf( __( 'Find a server with PHP Version to more %s or use xili-language version less or equal to %s', 'xili_language_errors' ), XILILANGUAGE_PHP_VER, XILILANGUAGE_PREV_VER );
       
  3980 		echo '</p></div>';
       
  3981 } 
       
  3982  
       
  3983 function xili_language_need_31() {
       
  3984 		global $wp_version;
       
  3985 		load_plugin_textdomain( 'xili_language_errors', false, 'xili-language/languages' );
       
  3986 		echo '<div id="message" class="error fade"><p>';
       
  3987 		echo '<strong>'.__( 'Installation of xili-language is not completed.', 'xili_language_errors' ) . '</strong>';
       
  3988 		echo '<br />';
       
  3989 		printf( __( 'This xili-language version (%s) need WordPress Version more than %s; installed release is %s.', 'xili_language_errors' ), XILILANGUAGE_VER , XILILANGUAGE_WP_VER, $wp_version) ;
       
  3990 		echo '<br />';
       
  3991 		printf( __( 'Upgrade WordPress Version to more %s or use xili-language version less than %s', 'xili_language_errors' ), XILILANGUAGE_WP_VER, XILILANGUAGE_PREV_VER );
       
  3992 		echo '</p></div>';
       
  3993 }
       
  3994 
  2406 ?>
  3995 ?>