web/wp-content/plugins/xili-language/xili-includes/xl-class-admin.php
changeset 194 32102edaa81b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
       
     1 <?php
       
     2 /**
       
     3  * class xili_language_admin - 2.6.3 - 2.7.1 - 2.8.0 - 2.8.1
       
     4  *
       
     5  */
       
     6  
       
     7 class xili_language_admin extends xili_language {
       
     8 	
       
     9 	// 2.5
       
    10 	var $authorbrowserlanguage = ''; // author default browser language
       
    11 	
       
    12 	var $exists_style_ext = false; // test if external style exists in theme
       
    13 	var $style_folder = ''; // where is xl-style.css
       
    14 	var $style_flag_folder_path = ''; // where are flags
       
    15 	var $style_message = '';
       
    16 	var $wikilink = 'http://wiki.xiligroup.org';
       
    17 	var $parent = null;
       
    18 	var $news_id = 0; //for multi pointers
       
    19 	var $news_case = array();
       
    20 	var $admin_messages = array(); //set in #491
       
    21 	
       
    22 	/**
       
    23 	 * PHP 5 Constructor
       
    24 	 */		
       
    25 	function __construct( $xl_parent ){
       
    26 		
       
    27 		$this->parent = $xl_parent; // to keep values built in parent filters...
       
    28 		
       
    29 		parent::__construct( false, false, true );  // need parent constructed values (third param - tell coming admin-class //2.6
       
    30 		
       
    31 		// since 2.2.0
       
    32 		add_action( 'admin_bar_init', array( &$this, 'admin_bar_init') ); // add button in toolbar
       
    33 		
       
    34 		// 2.8.0 dashboard language - inspired from Takayuki Miyoshi works
       
    35 		add_filter( 'locale', array( &$this, 'admin_side_locale') ); 
       
    36 		
       
    37 		add_action( 'admin_init', array( &$this, 'switch_user_locale') );
       
    38 		add_action( 'personal_options_update', array( &$this, 'update_user_dashboard_lang_option') );
       
    39 		add_action( 'personal_options', array( &$this, 'select_user_dashboard_locale') );
       
    40 		
       
    41 		// plugins list infos
       
    42 		add_filter( 'plugin_row_meta', array( &$this, 'more_infos_in_plugin_list' ), 10, 2);  // class WP_Plugins_List_Table
       
    43 		add_filter( 'plugin_action_links', array( &$this, 'more_plugin_actions' ), 10, 2); // class WP_Plugins_List_Table
       
    44 		add_action( 'after_plugin_row', array( &$this, 'more_plugin_row' ), 10, 3); // class WP_Plugins_List_Table
       
    45 		
       
    46 		// Dashboard menu and settings pages
       
    47 		
       
    48 		add_action( 'admin_menu', array(&$this, 'add_menu_settings_pages') );
       
    49 		add_action( 'admin_print_styles-settings_page_language_page', array(&$this, 'print_styles_options_language_page'), 20 );
       
    50 		add_action( 'admin_print_styles-settings_page_language_front_set', array(&$this, 'print_styles_options_language_tabs'), 20 );
       
    51 		add_action( 'admin_print_styles-settings_page_language_expert', array(&$this, 'print_styles_options_language_tabs'), 20 );
       
    52 		add_action( 'admin_print_styles-settings_page_language_support', array(&$this, 'print_styles_options_language_support'), 20 );
       
    53 		
       
    54 		// Edit Post Page
       
    55 		add_action( 'admin_init', array(&$this,'admin_init') ); // styles registering
       
    56 		
       
    57 		add_action( 'admin_menu', array(&$this, 'add_custom_box_in_post_edit') );
       
    58 		
       
    59 		add_action( 'admin_print_scripts-post.php', array(&$this,'find_post_script')); // 2.2.2
       
    60 		add_action( 'admin_print_scripts-post-new.php', array(&$this,'find_post_script'));
       
    61 			
       
    62 		add_action( 'admin_print_styles-post.php', array(&$this, 'print_styles_cpt_edit') );
       
    63 		add_action( 'admin_print_styles-post-new.php', array(&$this, 'print_styles_cpt_edit') );
       
    64 		
       
    65 		//add_filter( 'is_protected_meta', array(&$this,'hide_lang_post_meta'), 10, 3 ); // 2.5
       
    66 		//add_filter( 'post_meta_key_subselect', array(&$this,'hide_lang_post_meta_popup'), 10, 2); // 2.5
       
    67 						
       
    68 		/* actions for edit post page */
       
    69 		add_action( 'save_post', array(&$this,'xili_language_add'), 10, 2 );
       
    70 		add_action( 'save_post', array(&$this, 'fixes_post_slug'), 11, 2 ); // 2.5
       
    71 		
       
    72 		// Edit Attachment Media
       
    73 		add_filter( 'attachment_fields_to_edit', array(&$this,'add_language_attachment_fields'), 10, 2 ); // 2.6.3
       
    74 		add_filter( 'attachment_fields_to_save', array(&$this,'set_attachment_fields_to_save'), 10, 2 ); // 2.6.3
       
    75 		add_action( 'delete_attachment', array(&$this,'if_cloned_attachment') ); // 2.6.3
       
    76 		add_filter( 'wp_delete_file', array(&$this,'if_file_cloned_attachment') ); // 2.6.3
       
    77 						
       
    78 		// posts edit table
       
    79 		add_filter( 'manage_post_posts_columns', array(&$this,'xili_manage_column_name')); // 2.8.1
       
    80 		add_filter( 'manage_page_posts_columns', array(&$this,'xili_manage_column_name'));
       
    81 		add_filter( 'manage_media_columns', array(&$this,'xili_manage_column_name')); // 2.6.3
       
    82 		
       
    83 		$custompoststype = $this->xili_settings['multilingual_custom_post'] ; // 2.8.1
       
    84  		if ( $custompoststype != array()) {
       
    85 			foreach ( $custompoststype as $key => $customtype ) {
       
    86  				if ( ( !class_exists( 'bbPress') && $customtype['multilingual'] == 'enable' ) || ( class_exists( 'bbPress')  && ! in_array( $key, array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) && $customtype['multilingual'] == 'enable' ) ) {
       
    87  					add_filter( 'manage_'.$key.'_posts_columns', array(&$this,'xili_manage_column_name'));
       
    88  				}
       
    89 			}
       
    90  		}
       
    91 		
       
    92 		if ( class_exists( 'bbPress' ) ) {
       
    93 			add_filter( 'bbp_admin_forums_column_headers', array(&$this,'xili_manage_column_name'));
       
    94 			add_filter( 'bbp_admin_topics_column_headers', array(&$this,'xili_manage_column_name'));
       
    95 			add_filter( 'bbp_admin_replies_column_headers', array(&$this,'xili_manage_column_name')); //2.8.1
       
    96 		}
       
    97 		
       
    98 		add_action( 'manage_posts_custom_column', array(&$this,'xili_manage_column'), 10, 2);
       
    99 		add_action( 'manage_pages_custom_column', array(&$this,'xili_manage_column'), 10, 2);
       
   100 		add_action( 'manage_media_custom_column', array(&$this,'xili_manage_column'), 10, 2); // 2.6.3
       
   101 		
       
   102 		add_action( 'admin_print_styles-edit.php', array(&$this, 'print_styles_posts_list'), 20 );
       
   103 		add_action( 'admin_print_styles-upload.php', array(&$this, 'print_styles_posts_list'), 20 );// 2.6.3
       
   104 		
       
   105 		// quick edit languages in list - 1.8.9 
       
   106 		add_action( 'quick_edit_custom_box', array(&$this,'languages_custom_box'), 10, 2);
       
   107 		add_action( 'admin_head-edit.php', array(&$this,'quick_edit_add_script') );
       
   108 		add_action( 'bulk_edit_custom_box', array(&$this,'hidden_languages_custom_box'), 10, 2); // 1.8.9.3
       
   109 	
       
   110 		// sub-select in admin/edit.php 1.8.9
       
   111 		add_action( 'restrict_manage_posts', array(&$this,'restrict_manage_languages_posts') );
       
   112 		
       
   113 		/* categories edit-tags table */
       
   114 		add_filter( 'manage_edit-category_columns', array(&$this,'xili_manage_tax_column_name'));
       
   115 		add_filter( 'manage_category_custom_column', array(&$this,'xili_manage_tax_column'), 10, 3); // 2.6
       
   116 		add_filter( 'category_row_actions', array(&$this,'xili_manage_tax_action'), 10, 2); // 2.6
       
   117 		
       
   118 		add_action( 'admin_print_styles-edit-tags.php', array(&$this, 'print_styles_posts_list'), 20 );
       
   119 		add_action( 'category_edit_form_fields', array(&$this, 'show_translation_msgstr'), 10, 2 );
       
   120 		
       
   121 		add_action( 'category_add_form', array(&$this, 'update_xd_msgid_list') ); //do_action($taxonomy . '_add_form', $taxonomy);
       
   122 		
       
   123 		/* actions for edit link page */	
       
   124 		add_action( 'admin_menu', array(&$this, 'add_custom_box_in_link') );
       
   125 		
       
   126 		add_filter( 'manage_link-manager_columns', array(&$this,'xili_manage_link_column_name') ); // 1.8.5
       
   127 		add_action( 'manage_link_custom_column', array(&$this,'manage_link_lang_column'),10,2);
       
   128 		add_action( 'admin_print_styles-link.php', array(&$this, 'print_styles_link_edit'), 20 );
       
   129 		
       
   130 		// set or update term for this link taxonomy
       
   131 		add_action( 'edit_link', array(&$this,'edit_link_set_lang') );
       
   132 		add_action( 'add_link', array(&$this,'edit_link_set_lang') );
       
   133 		
       
   134 	
       
   135 		//display contextual help
       
   136 	    add_action( 'contextual_help', array( &$this,'add_help_text' ), 10, 3 ); /* 1.7.0 */
       
   137 		
       
   138 	}
       
   139 	
       
   140 	
       
   141 	/**
       
   142  	 * Checks if we should add links to the admin bar.
       
   143  	 *
       
   144  	 * @since 2.2.0
       
   145  	 */
       
   146 	function admin_bar_init() {
       
   147 	// Is the user sufficiently leveled, or has the bar been disabled? !is_super_admin() || 
       
   148 		if ( !is_admin_bar_showing() )
       
   149 			return;
       
   150  
       
   151 	 // editor rights
       
   152 		if ( current_user_can ( 'xili_language_menu' ) )
       
   153 			add_action( 'admin_bar_menu', array( &$this,'xili_tool_bar_links' ), 500 );
       
   154 		
       
   155 			add_action( 'admin_bar_menu', array( &$this,'lang_admin_bar_menu' ), 500 );
       
   156 		
       
   157 	}
       
   158 	
       
   159 	/**
       
   160  	 * Checks if we should add links to the bar. 
       
   161  	 *
       
   162  	 * @since 2.2 
       
   163  	 * updated and renamed 2.4.2 (node)
       
   164  	 */
       
   165 	function xili_tool_bar_links() {
       
   166 		
       
   167 		
       
   168 		
       
   169 		$link = plugins_url( 'images/xililang-logo-24.png', $this->file_file ) ;
       
   170 		$alt = __( 'Languages by ©xiligroup' ,'xili-language');
       
   171 		$title = __( 'Languages menu by ©xiligroup' ,'xili-language');
       
   172 		// Add the Parent link. 
       
   173 		$this->add_node_if_version( array(
       
   174 			'title' => sprintf("<img src=\"%s\" alt=\"%s\" title=\"%s\" />", $link, $alt, $title ), 
       
   175 			'href' => false,
       
   176 			'id' => 'xili_links',
       
   177 		));
       
   178 		if ( current_user_can ( 'xili_language_set' ) )
       
   179 			$this->add_node_if_version( array(
       
   180 				'title' => __('Languages settings','xili-language'),
       
   181 				'href' => admin_url('options-general.php?page=language_page'),
       
   182 				'id' => 'xl-set',
       
   183 				'parent' => 'xili_links',
       
   184 				'meta' => array('title' => __('Languages settings','xili-language') )
       
   185 			));
       
   186 			
       
   187 		if ( class_exists('xili_tidy_tags' ) && current_user_can ('xili_tidy_editor_set') ) 
       
   188 			$this->add_node_if_version( array(
       
   189 				'title' => sprintf(__("Tidy %s settings","xili_tidy_tags"), __('Tags') ),
       
   190 				'href' => admin_url( 'admin.php?page=xili_tidy_tags_settings' ),
       
   191 				'id' => 'xtt-set',
       
   192 				'parent' => 'xili_links',
       
   193 				'meta' => array('title' => sprintf(__("Tidy %s settings","xili_tidy_tags"), __('Tags') ) )
       
   194 			));
       
   195 		if ( class_exists('xili_tidy_tags' ) && current_user_can ('xili_tidy_editor_group') ) 
       
   196 			$this->add_node_if_version( array(
       
   197 				'title' => sprintf( __('%s groups','xili_tidy_tags'), __('Tags')),
       
   198 				'href' => admin_url( 'admin.php?page=xili_tidy_tags_assign' ),
       
   199 				'id' => 'xtt-group',
       
   200 				'parent' => 'xili_links',
       
   201 				'meta' => array('title' => sprintf( __('%s groups','xili_tidy_tags'), __('Tags') ) )
       
   202 			));	
       
   203 			
       
   204 		if ( class_exists('xili_dictionary' ) && current_user_can ('xili_dictionary_set')) {
       
   205 			if ( XILIDICTIONARY_VER > '1.5' ) {
       
   206 				global $xili_dictionary;
       
   207 				$link = $xili_dictionary->xd_settings_page ;  // XD 2.0
       
   208 			} else {
       
   209 				$link = 'tools.php?page=dictionary_page';
       
   210 			}
       
   211 			
       
   212 			$this->add_node_if_version( array(
       
   213 				'title' => 'xili-dictionary',
       
   214 				'href' => admin_url( $link ),
       
   215 				'id' => 'xd-set',
       
   216 				'parent' => 'xili_links',
       
   217 				'meta' => array('title' => sprintf( __('Translation with %s tools','xili-language'), 'xili-dictionary' ) )
       
   218 			));		
       
   219 		}
       
   220 		$this->add_node_if_version( array(
       
   221 			'title' => __('xili-language : how to','xili-language'),
       
   222 			'href' => 'http://multilingual.wpmu.xilione.com',
       
   223 			'id' => 'xilione-multi',
       
   224 			'parent' => 'xili_links',
       
   225 			'meta' => array('target' => '_blank')
       
   226 		));
       
   227 		$this->add_node_if_version( array(
       
   228 			'title' => __('About ©xiligroup plugins','xili-language'),
       
   229 			'href' => 'http://dev.xiligroup.com',
       
   230 			'id' => 'xili-about',
       
   231 			'parent' => 'xili_links',
       
   232 			'meta' => array('target' => '_blank')
       
   233 		));
       
   234 		
       
   235 	}
       
   236 	
       
   237 	function add_node_if_version ( $args ) {
       
   238 		global $wp_admin_bar, $wp_version;
       
   239 		if ( version_compare($wp_version, '3.3', '<') ) {
       
   240 			$wp_admin_bar->add_menu( $args );
       
   241 		} else {
       
   242 			$wp_admin_bar->add_node( $args );	
       
   243 		}
       
   244 	}
       
   245 	
       
   246 	/**
       
   247 	 * Admin side localization - user's dashboard
       
   248 	 *
       
   249 	 * @since 2.8.0
       
   250 	 *
       
   251 	 */
       
   252 	function admin_side_locale( $locale = 'en_US' ) {
       
   253 		
       
   254 		$locale = get_user_option( 'user_locale' ); 
       
   255 
       
   256 		if ( empty( $locale ) )
       
   257 			$locale = $this->get_default_locale();
       
   258 		
       
   259 		return $locale;
       
   260 	}
       
   261 	
       
   262 	
       
   263 	/**
       
   264 	 * Admin side localization - available languages inside WP core installation
       
   265 	 *
       
   266 	 * @since 2.8.0
       
   267 	 *
       
   268 	 */
       
   269 	function get_default_locale() {
       
   270 		
       
   271 		$locale = ( defined( 'WPLANG' ) ) ? WPLANG : 'en_US';
       
   272 
       
   273 		if ( is_multisite() ) {
       
   274 			if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) )
       
   275 				$ms_locale = get_site_option( 'WPLANG' );
       
   276 
       
   277 			if ( $ms_locale !== false )
       
   278 				$locale = $ms_locale;
       
   279 		}
       
   280 		
       
   281 		return $locale;
       
   282 	
       
   283 	}
       
   284 	
       
   285 	// Admin Bar at top right
       
   286 	
       
   287 	function lang_admin_bar_menu( ) {
       
   288 		
       
   289 		$screen = get_current_screen();  // to limit unwanted side effects (form)
       
   290 		if ( in_array ( $screen->id , array (
       
   291 		'dashboard', 'users', 'profile',
       
   292 		'edit-post', 'edit-page', 'link-manager', 'upload',
       
   293 		'settings_page_language_page', 'settings_page_language_front_set',  
       
   294 		'settings_page_language_expert','settings_page_language_support',
       
   295 		'xdmsg', 'edit-xdmsg', 'xdmsg_page_dictionary_page'
       
   296 		) ) 
       
   297 		|| ( false !== strpos ( $screen->id , '_page_xili_tidy_tags_assign' ) ) 
       
   298 		) {
       
   299 		
       
   300 			$current_locale = $this->admin_side_locale();
       
   301 			$current_language = (isset ( $this->examples_list[$current_locale]) ) ? $this->examples_list[$current_locale] : '';
       
   302 		
       
   303 			if ( ! $current_language )
       
   304 				$current_language = $current_locale;
       
   305 		
       
   306 			$this->add_node_if_version( array(
       
   307 				'parent' => 'top-secondary',
       
   308 				'id' => 'xili-user-locale',
       
   309 				'title' => __('Language','xili-language').': '. $this->lang_to_show( $current_language ) ) ); // '&#10004; '
       
   310 		
       
   311 			$available_languages = $this->available_languages(
       
   312 				array( 'exclude' => array( $current_locale ) ) );
       
   313 		
       
   314 			foreach ( $available_languages as $locale => $lang ) {
       
   315 				$url = admin_url( 'profile.php?action=lang-switch-locale&locale=' . $locale );
       
   316 		
       
   317 				$url = add_query_arg(
       
   318 					array( 'redirect_to' => urlencode( $_SERVER['REQUEST_URI'] ) ),
       
   319 					$url );
       
   320 		
       
   321 				$url = wp_nonce_url( $url, 'lang-switch-locale' );
       
   322 		
       
   323 				$this->add_node_if_version( array(
       
   324 					'parent' => 'xili-user-locale',
       
   325 					'id' => 'xili-user-locale-' . $locale,
       
   326 					'title' => $this->lang_to_show( $lang ),
       
   327 					'href' => $url ) );
       
   328 			}
       
   329 		}
       
   330 	}
       
   331 
       
   332 	function switch_user_locale() {
       
   333 		if ( empty( $_REQUEST['action'] ) || 'lang-switch-locale' != $_REQUEST['action'] )
       
   334 			return;
       
   335 	
       
   336 		check_admin_referer( 'lang-switch-locale' );
       
   337 	
       
   338 		$locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : '';
       
   339 	
       
   340 		if ( ! $this->is_available_locale( $locale ) || $locale == $this->admin_side_locale() )
       
   341 			return;
       
   342 	
       
   343 		update_user_option( get_current_user_id(), 'user_locale', $locale, true );
       
   344 	
       
   345 		if ( ! empty( $_REQUEST['redirect_to'] ) ) {
       
   346 			wp_safe_redirect( $_REQUEST['redirect_to'] );
       
   347 			exit();
       
   348 		}
       
   349 	}
       
   350 
       
   351 	function  is_available_locale( $locale ) {
       
   352 		return ! empty( $locale ) && array_key_exists( $locale, (array) $this->available_languages() );
       
   353 	}
       
   354 	
       
   355 	function available_languages( $args = '' ) {
       
   356 		$defaults = array(
       
   357 			'exclude' => array(),
       
   358 			'orderby' => 'key',
       
   359 			'order' => 'ASC' );
       
   360 	
       
   361 		$args = wp_parse_args( $args, $defaults );
       
   362 	
       
   363 		$langs = array();
       
   364 	
       
   365 		$installed_locales = get_available_languages();
       
   366 		$installed_locales[] = $this->get_default_locale();
       
   367 		$installed_locales[] = 'en_US';
       
   368 		$installed_locales = array_unique( $installed_locales );
       
   369 		$installed_locales = array_filter( $installed_locales );
       
   370 	
       
   371 		foreach ( $installed_locales as $locale ) {
       
   372 			if ( in_array( $locale, (array) $args['exclude'] ) )
       
   373 				continue;
       
   374 	
       
   375 			$lang = ( isset ( $this->examples_list[$locale]) ) ? $this->examples_list[$locale] : '';
       
   376 	
       
   377 			if ( empty( $lang ) )
       
   378 				$lang = "[$locale]";
       
   379 	
       
   380 			$langs[$locale] = $lang;
       
   381 		}
       
   382 	
       
   383 		if ( 'value' == $args['orderby'] ) {
       
   384 			natcasesort( $langs );
       
   385 	
       
   386 			if ( 'DESC' == $args['order'] )
       
   387 				$langs = array_reverse( $langs );
       
   388 		} else {
       
   389 			if ( 'DESC' == $args['order'] )
       
   390 				krsort( $langs );
       
   391 			else
       
   392 				ksort( $langs );
       
   393 		}
       
   394 	
       
   395 		$langs = apply_filters( 'xili_available_languages', $langs, $args );
       
   396 	
       
   397 		return $langs;
       
   398 	}
       
   399 	
       
   400 	/**
       
   401 	 * Adds option in user profile to set and update his dashboard language
       
   402 	 * 
       
   403 	 * 'user_locale' saved as iso (en_US or fr_FR ….)
       
   404 	 * @since 2.8.0
       
   405 	 * 
       
   406 	 */
       
   407 	function update_user_dashboard_lang_option() {
       
   408 		if ( ! isset( $_POST['user_locale'] ) || empty( $_POST['user_locale'] ) )
       
   409 			$locale = null;
       
   410 		else
       
   411 			$locale = $_POST['user_locale'];
       
   412 
       
   413 		update_user_option( get_current_user_id(), 'user_locale', $locale, true );
       
   414 	}
       
   415 
       
   416 	function select_user_dashboard_locale() {
       
   417 		$available_languages = $this->available_languages( 'orderby=value' );
       
   418 		$selected = $this->admin_side_locale();
       
   419 
       
   420 		?>
       
   421 		<tr>
       
   422 			<th scope="row"><?php echo esc_html( __( 'Your dashboard language', 'xili-language' ) ); ?></th>
       
   423 			<td>
       
   424 				<select name="user_locale">
       
   425 				<?php foreach ( $available_languages as $locale => $lang ) : ?>
       
   426 					<option value="<?php echo esc_attr( $locale ); ?>" <?php selected( $locale, $selected ); ?>><?php echo esc_html( $this->lang_to_show( $lang ) ); ?></option>
       
   427 				<?php endforeach; ?>
       
   428 				</select>
       
   429 				<p><em><?php _e('System’s default language is', 'xili-language'); echo ": " . $this->get_default_locale(); ?></em></p>
       
   430 			</td>
       
   431 		</tr>
       
   432 		<?php
       
   433 	}
       
   434 	
       
   435 	function lang_to_show ( $lang = 'english' ) {
       
   436 		return ucwords( $lang ); // uppercase each word
       
   437 	}
       
   438 	
       
   439 	/** end dashboard user's language functions **/
       
   440 	
       
   441 	/**
       
   442 	 * Adds links to the plugin row on the plugins page.
       
   443 	 * Thanks to Zappone et WP engineer.com
       
   444 	 *
       
   445 	 * @param mixed $links
       
   446 	 * @param mixed $file
       
   447 	 */
       
   448 	function more_infos_in_plugin_list( $links, $file ) {
       
   449 		$base = $this->plugin_basename ;
       
   450 		if ( $file == $base ) {
       
   451 			$links[] = '<a href="options-general.php?page=language_page">' . __('Settings') . '</a>';
       
   452 			$links[] = __('Informations and Getting started:', 'xili-language') . ' <a href="'. $this->wikilink . '">' . __('Xili Wiki', 'xili-language') . '</a>';
       
   453 			$links[] = '<a href="http://forum2.dev.xiligroup.com">' . __('Forum and Support', 'xili-language') . '</a>';
       
   454 			$links[] = '<a href="http://dev.xiligroup.com/donate/">' . __('Donate', 'xili-language') . '</a>';
       
   455 		}
       
   456 		return $links;
       
   457 	}
       
   458 	
       
   459 	/**
       
   460 	 * Adds a row to comment situation for multilingual context !
       
   461 	 *
       
   462 	 */
       
   463 	function more_plugin_row ( $plugin_file, $plugin_data, $status ) {
       
   464 		$base = $this->plugin_basename ;
       
   465 		if ( $plugin_file == $base ) {
       
   466 			$statusXili =  array ();
       
   467 			
       
   468 			$statusXili[] = __('Congratulations for choosing xili-language to built a multilingual website. To work optimally, 2 other plugins are recommended', 'xili-language');
       
   469 			
       
   470 			$statusXili[] = $this->plugin_status ( 'xili-dictionary', 'xili-dictionary/xili-dictionary.php', $status ) ;
       
   471 			
       
   472 			$statusXili[] = $this->plugin_status ( 'xili-tidy-tags', 'xili-tidy-tags/xili-tidy-tags.php' , $status) ;
       
   473 			
       
   474 			if ( is_child_theme() ) { 
       
   475 				$theme_name = get_option("stylesheet").' '.__('child of','xili-language').' '.get_option("template"); 
       
   476 			} else {
       
   477 				$theme_name = get_option("template"); 
       
   478 			}
       
   479 			
       
   480 			$statusXili[] = sprintf ( __('For Appearance the current active theme is <em>%s</em>', 'xili-language'), $theme_name );
       
   481 			
       
   482 			if ( $this->parent->xili_settings['theme_domain'] == '' ) {	
       
   483 				$statusXili[] = sprintf (__('This theme <em>%s</em> seems to not contain localization function (load_theme_textdomain) to be used for a multilingual website', 'xili-language'), $theme_name );
       
   484 			} else {
       
   485 				$statusXili[] = sprintf (__('This theme <em>%s</em> seems to contain localization function to be used for a multilingual website', 'xili-language'), $theme_name );
       
   486 			}
       
   487 			
       
   488 			$cb_col = '<img src="'.plugins_url( 'images/xililang-logo-24.png', $this->file_file ).'" alt="xili-language trilogy"/>';
       
   489 			$action_col = __('More infos about', 'xili-language') . '<br />&nbsp;&nbsp;' . $plugin_data['Name'] ;
       
   490 			$description_col = implode ( '. ', $statusXili ).'.';
       
   491 			echo "<tr><th>$cb_col</th><td>$action_col</td><td>$description_col</td></tr>";
       
   492 		}
       
   493 	}
       
   494 	
       
   495 	function plugin_status ( $plugin_name, $plugin_file, $status ) {
       
   496 			
       
   497 			if ( is_plugin_active( $plugin_file ) ){
       
   498 				$plug_status = __('active', 'xili-language');
       
   499 			} else {
       
   500 				$plugins = get_plugins();
       
   501 				if ( isset( $plugins[ $plugin_file ] ) ) {	
       
   502 					$plug_status = __('inactive', 'xili-language');
       
   503 				} else {
       
   504 					$plug_status = __('not installed', 'xili-language');
       
   505 				}
       
   506 			}
       
   507 			
       
   508 		return sprintf ( __('Plugin %s is %s', 'xili-language'), $plugin_name, $plug_status ); 			
       
   509 	}
       
   510 	
       
   511 	/**
       
   512 	 * Add action link(s) to plugins page
       
   513 	 * 
       
   514 	 * @since 0.9.3
       
   515 	 * @author MS
       
   516 	 * @copyright Dion Hulse, http://dd32.id.au/wordpress-plugins/?configure-link and scripts@schloebe.de
       
   517 	 */
       
   518 	function more_plugin_actions( $links, $file ){
       
   519 		$this_plugin = $this->plugin_basename ;
       
   520 		if( $file == $this_plugin ){
       
   521 			$settings_link = '<a href="options-general.php?page=language_page">' . __('Settings') . '</a>';
       
   522 			$links = array_merge( array($settings_link), $links); // before other links
       
   523 		}
       
   524 		return $links;
       
   525 	}
       
   526 	
       
   527 	
       
   528 	
       
   529 	
       
   530 	/********************************** SETTINGS ADMIN UI ***********************************/
       
   531 			
       
   532 	/**
       
   533 	 * add admin menu and associated pages of admin UI
       
   534 	 *
       
   535 	 * @since 0.9.0
       
   536 	 * @updated 0.9.6 - only for WP 2.7.X - do registering of new meta boxes and JS __(' -','xili-language')
       
   537 	 * @updated 2.4.1 - sub-pages and tab
       
   538 	 *
       
   539 	 */
       
   540 	function add_menu_settings_pages() {
       
   541 		/* browser title and menu title - if empty no menu */
       
   542 		 $this->thehook = add_options_page(__('xili-language plugin','xili-language'). ' - 1', __('Languages ©xili','xili-language'), 'manage_options', 'language_page', array( &$this, 'languages_settings' ) );
       
   543 		 
       
   544 		 add_action('load-'.$this->thehook, array(&$this,'on_load_page'));
       
   545 		 
       
   546 		 
       
   547 		 $this->thehook2 = add_options_page(__('xili-language plugin','xili-language'). ' - 2', '', 'manage_options', 'language_front_set', array( &$this, 'languages_frontend_settings' ) );
       
   548 		 add_action('load-'.$this->thehook2, array(&$this,'on_load_page_set'));
       
   549 		 
       
   550 		 $this->thehook4 = add_options_page(__('xili-language plugin','xili-language'). ' - 3', '', 'manage_options', 'language_expert', array( &$this, 'languages_expert' ) );
       
   551 		 add_action('load-'.$this->thehook4, array(&$this,'on_load_page_expert'));
       
   552 		 
       
   553 		 $this->thehook3 = add_options_page(__('xili-language plugin','xili-language'). ' - 4', '', 'manage_options', 'language_support', array( &$this, 'languages_support' ) );
       
   554 		 add_action('load-'.$this->thehook3, array(&$this,'on_load_page_support'));
       
   555 		 
       
   556 		 $this->insert_news_pointer ( 'xl_new_version' ); // pointer in menu for updated version
       
   557 		 
       
   558 		 
       
   559 		 
       
   560 		 add_action( 'admin_print_footer_scripts', array(&$this, 'print_the_pointers_js') );
       
   561 		 
       
   562 		 // create library of alert messages
       
   563 		 
       
   564 		 $this->create_library_of_alert_messages ();
       
   565 		 
       
   566 		 
       
   567 	}
       
   568 	
       
   569 	// called by each pointer
       
   570 	function insert_news_pointer ( $case_news ) {
       
   571 			wp_enqueue_style( 'wp-pointer' );
       
   572 			wp_enqueue_script( 'wp-pointer', false, array('jquery') );
       
   573 			++$this->news_id;
       
   574 			$this->news_case[$this->news_id] = $case_news;	
       
   575 	}
       
   576 	// insert the pointers registered before
       
   577 	function print_the_pointers_js (  ) { 
       
   578 		if ( $this->news_id != 0 ) {
       
   579 			for ($i = 1; $i <= $this->news_id; $i++) {
       
   580 				$this->print_pointer_js ( $i );
       
   581 			}
       
   582 		}
       
   583 		
       
   584 		
       
   585 	}
       
   586 	
       
   587 	function print_pointer_js ( $indice  ) {  ;
       
   588 		
       
   589 		$args = $this->localize_admin_js( $this->news_case[$indice], $indice );
       
   590 		if ( $args['pointerText'] != '' ) { // only if user don't read it before
       
   591 		?>
       
   592 		<script type="text/javascript">
       
   593 		//<![CDATA[
       
   594 		jQuery(document).ready( function() {
       
   595  	
       
   596  	var strings<?php echo $indice; ?> = <?php echo json_encode( $args ); ?>;
       
   597  	
       
   598 	<?php /** Check that pointer support exists AND that text is not empty - inspired www.generalthreat.com */ ?>
       
   599 	
       
   600 	if(typeof(jQuery().pointer) != 'undefined' && strings<?php echo $indice; ?>.pointerText != '') {
       
   601 		jQuery( strings<?php echo $indice; ?>.pointerDiv ).pointer({
       
   602 			content    : strings<?php echo $indice; ?>.pointerText,
       
   603 			position: { edge: strings<?php echo $indice; ?>.pointerEdge,
       
   604 				at: strings<?php echo $indice; ?>.pointerAt,
       
   605 				my: strings<?php echo $indice; ?>.pointerMy,
       
   606 				offset: strings<?php echo $indice; ?>.pointerOffset
       
   607 			},       
       
   608 			close  : function() {
       
   609 				jQuery.post( ajaxurl, {
       
   610 					pointer: strings<?php echo $indice; ?>.pointerDismiss,
       
   611 					action: 'dismiss-wp-pointer'
       
   612 				});
       
   613 			}
       
   614 		}).pointer('open');
       
   615 	}
       
   616 });
       
   617 		//]]>
       
   618 		</script>
       
   619 		<?php
       
   620 		}
       
   621 	}
       
   622 	
       
   623 	
       
   624 	/**
       
   625 	 * News pointer for tabs
       
   626 	 *
       
   627 	 * @since 2.6.2
       
   628 	 *
       
   629 	 */
       
   630 	function localize_admin_js( $case_news, $news_id ) {
       
   631  			$about = __('Docs about xili-language', 'xili-language');
       
   632  			$pointer_Offset = '';
       
   633  			$pointer_edge = '';
       
   634  			$pointer_at = '';
       
   635  			$pointer_my = '';
       
   636  		switch ( $case_news ) {
       
   637  			
       
   638  			case 'xl_new_version' :
       
   639  				$pointer_text = '<h3>' . esc_js( __( 'xili-language updated', 'xili-language') ) . '</h3>';
       
   640 				$pointer_text .= '<p>' . esc_js( sprintf( __( 'xili-language was updated to version %s', 'xili-language' ) , XILILANGUAGE_VER) ). '</p>';
       
   641 				$pointer_text .= '<p>' . esc_js( __( 'See settings submenu', 'xili-language' ).' “<a href="options-general.php?page=language_page">'. __('Languages ©xili','xili-language')."</a>”" ). '</p>';
       
   642 				$pointer_text .= '<p>' . esc_js( sprintf(__( 'Before to question dev.xiligroup support, do not forget to visit %s documentation', 'xili-language' ), '<a href="http://wiki.xiligroup.org" title="'.$about.'" >wiki</a>' ) ). '</p>';
       
   643  				$pointer_dismiss = 'xl-new-version-'.str_replace('.', '-', XILILANGUAGE_VER); 
       
   644  				$pointer_div = '#menu-settings';
       
   645  				$pointer_Offset = '0 0';
       
   646  				$pointer_edge = 'left';
       
   647  				$pointer_my = 'left';
       
   648  				$pointer_at = 'right';
       
   649 				break;
       
   650  			
       
   651  			
       
   652 			case 'languages_settings':
       
   653 				$pointer_text = '<h3>' . esc_js( __( 'To define languages', 'xili-language') ) . '</h3>';
       
   654 				$pointer_text .= '<p>' . esc_js( __( 'This screen is designed to define the list of languages assigned to this website. Use the form below to add a new language with the help of preset list (popup) or by input your own ISO code.', 'xili-language' ) ). '</p>';
       
   655 				$pointer_text .= '<p>' . esc_js( sprintf(__( 'Before to question dev.xiligroup support, do not forget to visit %s documentation', 'xili-language' ), '<a href="http://wiki.xiligroup.org" title="'.$about.'" >wiki</a>' ) ). '</p>';
       
   656  				$pointer_dismiss = 'xl-settings-news';
       
   657  				$pointer_div = '#xili-language-lang-list';
       
   658  				$pointer_Offset = '120 13';
       
   659 				break;
       
   660 				
       
   661 			case 'languages_frontend_settings':
       
   662 				$pointer_text = '<h3>' . esc_js( __( 'To define front-page', 'xili-language') ) . '</h3>';
       
   663 				$pointer_text .= '<p>' . esc_js( __( 'This screen contains selectors to define the behaviour of frontpage according languages and visitors browser.', 'xili-language' ) ). '</p>';
       
   664 				$pointer_text .= '<p>' . esc_js( sprintf(__( 'Before to question dev.xiligroup support, do not forget to visit %s documentation', 'xili-language' ), '<a href="http://wiki.xiligroup.org" title="'.$about.'" >wiki</a>' ) ). '</p>';
       
   665  				$pointer_dismiss = 'xl-frontend-news'; 
       
   666  				$pointer_div = '#post-body-content';
       
   667  				$pointer_Offset = '100 13';
       
   668 				break;
       
   669 			case 'languages_theme_infos':
       
   670 				$pointer_text = '<h3>' . esc_js( __( 'Infos about current theme', 'xili-language') ) . '</h3>';
       
   671 				$pointer_text .= '<p>' . esc_js( __( 'This metabox contains infos about the theme and the joined available language files (.mo).', 'xili-language' ) ). '</p>';
       
   672 				$pointer_text .= '<p>' . esc_js( sprintf(__( 'Before to question dev.xiligroup support, do not forget to visit %s documentation', 'xili-language' ), '<a href="http://wiki.xiligroup.org" title="'.$about.'" >wiki</a>' ) ). '</p>';
       
   673  				$pointer_dismiss = 'xl-frontend-theme-news'; 
       
   674  				$pointer_div = '#xili-language-sidebox-theme';
       
   675  				$pointer_Offset = '-330 0';
       
   676  				$pointer_edge = 'right';
       
   677  				$pointer_my = 'left';
       
   678  				$pointer_at = 'left';
       
   679 				break;	
       
   680 				
       
   681 			case 'languages_expert':
       
   682 				$pointer_text = '<h3>' . esc_js( __( 'For documented webmaster', 'xili-language') ) . '</h3>';
       
   683 				$pointer_text .= '<p>' . esc_js( __( 'This screen contains nice selectors and features to customize menus and other objects for your CMS multilingual website.', 'xili-language' ) ). '</p>';
       
   684 				$pointer_text .= '<p>' . esc_js( sprintf(__( 'Before to question dev.xiligroup support, do not forget to visit %s documentation', 'xili-language' ), '<a href="http://wiki.xiligroup.org" title="'.$about.'" >wiki</a>' ) ). '</p>';
       
   685  				$pointer_dismiss = 'xl-expert-news';
       
   686  				$pointer_div = '#post-body-content';
       
   687  				$pointer_Offset = '130 13';
       
   688 				break;
       
   689 			case 'languages_expert_special':
       
   690 				$pointer_text = '<h3>' . esc_js( __( 'For documented webmaster', 'xili-language') ) . '</h3>';
       
   691 				$pointer_text .= '<p>' . esc_js( __( 'This metabox contains advanced selectors and features to customize behaviours, style and other objects like widgets for your CMS multilingual website.', 'xili-language' ) ). '</p>';
       
   692 				$pointer_text .= '<p>' . esc_js( sprintf(__( 'Before to question dev.xiligroup support, do not forget to visit %s documentation', 'xili-language' ), '<a href="http://wiki.xiligroup.org" title="'.$about.'" >wiki</a>' ) ). '</p>';
       
   693  				$pointer_dismiss = 'xl-expert-special-news';
       
   694  				$pointer_div = '#xili-language-sidebox-special';
       
   695  				$pointer_Offset = '-10 0';
       
   696  				$pointer_edge = 'right';
       
   697  				$pointer_my = 'right top';
       
   698  				$pointer_at = 'left top';
       
   699 				break;
       
   700 				
       
   701 			case 'languages_support':
       
   702 				$pointer_text = '<h3>' . esc_js( __( 'In direct with support', 'xili-language') ) . '</h3>';
       
   703 				$pointer_text .= '<p>' . esc_js( sprintf(__( 'Before to question dev.xiligroup support, do not forget to check needed website infos and to visit %s documentation', 'xili-language' ), '<a href="http://wiki.xiligroup.org" title="'.$about.'" >wiki</a>' ) ). '</p>';
       
   704  				$pointer_dismiss = 'xl-support-news';
       
   705  				$pointer_div = '#post-body-content';
       
   706  				$pointer_Offset = '400 13';
       
   707 				break;
       
   708 				
       
   709 			case 'media_language':
       
   710 				$pointer_text = '<h3>' . esc_js( __( 'Language of media', 'xili-language') ) . '</h3>';
       
   711 				$pointer_text .= '<p>' . esc_js( sprintf(__( 'Language concern title, caption and description of media. With clonage approach, the file is shared between version for each language. When modifying a media, new fields are available at end of form. Before to assign language to media, do not forget to visit %s documentation', 'xili-language' ), '<a href="http://wiki.xiligroup.org" title="'.$about.'" >wiki</a>' ) ). '</p>';
       
   712  				$pointer_dismiss = 'xl-media-upload';
       
   713  				$pointer_div = '#language';
       
   714  				$pointer_edge = 'right';
       
   715  				$pointer_my = 'right top';
       
   716  				$pointer_at = 'left top';
       
   717  				$pointer_Offset = '-10 -10';
       
   718 				break;	
       
   719 					
       
   720 			default: // nothing 
       
   721 				$pointer_text = ''; 
       
   722 			}
       
   723 
       
   724  			// inspired from www.generalthreat.com
       
   725 		// Get the list of dismissed pointers for the user
       
   726 		$dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
       
   727 		if ( in_array( $pointer_dismiss, $dismissed ) && $pointer_dismiss == 'xl-new-version-'.str_replace('.', '-', XILILANGUAGE_VER) ) {
       
   728 			$pointer_text = '';
       
   729 		// Check whether our pointer has been dismissed two times
       
   730 		} elseif ( in_array( $pointer_dismiss, $dismissed ) && in_array( $pointer_dismiss.'-1', $dismissed ) ) {
       
   731 			$pointer_text = '';
       
   732 		} elseif ( in_array( $pointer_dismiss, $dismissed ) ) {
       
   733 			$pointer_dismiss = $pointer_dismiss.'-1';
       
   734 		}
       
   735 
       
   736 		return array(
       
   737 			'pointerText' => html_entity_decode( (string) $pointer_text, ENT_QUOTES, 'UTF-8'),
       
   738 			'pointerDismiss' => $pointer_dismiss,
       
   739 			'pointerDiv' => $pointer_div,
       
   740 			'pointerEdge' => ( '' == $pointer_edge ) ? 'top' : $pointer_edge ,
       
   741 			'pointerAt' => ( '' == $pointer_at ) ? 'left top' : $pointer_at ,
       
   742 			'pointerMy' => ( '' == $pointer_my ) ? 'left top' : $pointer_my ,
       
   743 			'pointerOffset' => $pointer_Offset,
       
   744 			'newsID' => $news_id
       
   745 		);
       
   746     }
       
   747 	
       
   748 	/**
       
   749 	 * Create list of messages 
       
   750 	 * @since 2.6.3
       
   751 	 *
       
   752 	 */
       
   753 	function create_library_of_alert_messages() {
       
   754 		
       
   755 		$this->admin_messages['alert']['default'] = sprintf(__('See %sWiki%s for more details','xili-language'),'<a href="'.$this->wikilink.'">' ,'</a>');
       
   756 		$this->admin_messages['alert']['no_load_function'] = sprintf(__('CAUTION: no load_theme_textdomain() in functions.php - review the content of file in the current theme or choose another canonical theme. %s','xili-language'), $this->admin_messages['alert']['default'] ) ;
       
   757 		$this->admin_messages['alert']['no_domain_defined'] = __('Theme domain NOT defined','xili-language');
       
   758 		
       
   759 		$this->admin_messages['alert']['menu_auto_inserted'] = sprintf(__('Be aware that language list is already automatically inserted (see above) and %s','xili-language'), $this->admin_messages['alert']['default'] ) ;
       
   760 	
       
   761 		$this->admin_messages['alert']['plugin_deinstalling'] = sprintf(__('CAUTION: When checking below, after deactivating xili-language plugin, if delete it through plugins list, ALL the xili-language datas in database will be definitively ERASED !!! (only multilingual features). %s', 'xili-language'), $this->admin_messages['alert']['default'] ) ;
       
   762 		
       
   763 		$this->admin_messages['alert']['erasing_language'] = __('Erase (only) multilingual features of concerned posts when this language will be erased !','xili-language');
       
   764 		
       
   765 	}
       
   766 	
       
   767 	/**
       
   768 	 * Manage list of languages 
       
   769 	 * @since 0.9.0
       
   770 	 */
       
   771 	function on_load_page() {
       
   772 			wp_enqueue_script('common');
       
   773 			wp_enqueue_script('wp-lists');
       
   774 			wp_enqueue_script('postbox');
       
   775 			add_meta_box('xili-language-sidebox-msg', __('Message','xili-language'), array(&$this,'on_sidebox_msg_content'), $this->thehook , 'side', 'core');
       
   776 			add_meta_box('xili-language-sidebox-info', __('Info','xili-language'), array(&$this,'on_sidebox_info_content'), $this->thehook , 'side', 'core');
       
   777 			
       
   778 			if ( !is_multisite() )
       
   779 			  add_meta_box('xili-language-sidebox-uninstall', __('Uninstall Options','xili-language'), array(&$this,'on_sidebox_uninstall_content'), $this->thehook , 'side', 'low');
       
   780 			  
       
   781 			$this->insert_news_pointer ( 'languages_settings' ); // news pointer 2.6.2
       
   782 			
       
   783 	}
       
   784 	
       
   785 	/**
       
   786 	 * Manage settings of languages behaviour in front-end (theme)
       
   787 	 * @since 2.4.1 
       
   788 	 */
       
   789 	function on_load_page_set() {
       
   790 			wp_enqueue_script('common');
       
   791 			wp_enqueue_script('wp-lists');
       
   792 			wp_enqueue_script('postbox');
       
   793 			
       
   794 			add_meta_box('xili-language-sidebox-theme', __('Current theme infos','xili-language'), array(&$this,'on_sidebox_4_theme_info'), $this->thehook2 , 'side', 'high');
       
   795 			add_meta_box('xili-language-sidebox-info', __('Info','xili-language'), array(&$this,'on_sidebox_info_content'), $this->thehook2 , 'side', 'core');
       
   796 			
       
   797 			$this->insert_news_pointer ( 'languages_frontend_settings' ); // news pointer 2.6.2
       
   798 			$this->insert_news_pointer ( 'languages_theme_infos' );
       
   799 	}
       
   800 	
       
   801 	/**
       
   802 	 * Settings by experts and info 
       
   803 	 * @since 2.4.1 
       
   804 	 */
       
   805 	function on_load_page_expert() {
       
   806 			wp_enqueue_script('common');
       
   807 			wp_enqueue_script('wp-lists');
       
   808 			wp_enqueue_script('postbox');
       
   809 			
       
   810 			add_meta_box('xili-language-sidebox-theme', __('Current theme infos','xili-language'), array(&$this,'on_sidebox_4_theme_info'), $this->thehook4 , 'side', 'high');
       
   811 			
       
   812 			add_meta_box('xili-language-sidebox-special', __('Special','xili-language'), array(&$this,'on_sidebox_for_specials'), $this->thehook4 , 'side', 'core');
       
   813 			add_meta_box('xili-language-sidebox-info', __('Info','xili-language'), array(&$this,'on_sidebox_info_content'), $this->thehook4 , 'side', 'core');
       
   814 			
       
   815 			$this->insert_news_pointer ( 'languages_expert' ); // news pointer 2.6.2
       
   816 			$this->insert_news_pointer ( 'languages_expert_special' );
       
   817 	}
       
   818 	
       
   819 	/**
       
   820 	 * Support and info
       
   821 	 * @since 2.4.1 
       
   822 	 */
       
   823 	function on_load_page_support() {
       
   824 			wp_enqueue_script('common');
       
   825 			wp_enqueue_script('wp-lists');
       
   826 			wp_enqueue_script('postbox');
       
   827 			
       
   828 			add_meta_box('xili-language-sidebox-info', __('Info','xili-language'), array(&$this,'on_sidebox_info_content'), $this->thehook3 , 'side', 'core');
       
   829 			
       
   830 			$this->insert_news_pointer ( 'languages_support' ); // news pointer 2.6.2
       
   831 	}
       
   832 
       
   833 	
       
   834 	/******************************** Main Settings screens *************************/
       
   835 	
       
   836 	/**
       
   837 	 * to display the languages settings admin UI
       
   838 	 *
       
   839 	 * @since 0.9.0
       
   840 	 * @updated 0.9.6 - only for WP 2.7.X - do new meta boxes and JS
       
   841 	 *
       
   842 	 */
       
   843 	function languages_settings() { 
       
   844 		
       
   845 		$formtitle = __('Add a language', 'xili-language'); /* translated in form */
       
   846 		$submit_text = __('Add &raquo;','xili-language');
       
   847 		$cancel_text = __('Cancel');
       
   848 		$action = '';
       
   849 		$actiontype = '';
       
   850 		$language = (object) array ('name' => '', 'slug' => '', 'description' => '', 'term_order' => '' ); //2.2.3
       
   851 		
       
   852 		
       
   853 		$msg = 0 ; /* 1.7.1 */
       
   854 		if (isset($_POST['reset'])) {
       
   855 			$action =$_POST['reset'];
       
   856 		} elseif ( isset($_POST['updateoptions']) ) {
       
   857 			$action ='updateoptions';
       
   858 		} elseif ( isset($_POST['updateundefined'])) {
       
   859 			$action ='updateundefined';
       
   860 		} elseif ( isset($_POST['menuadditems'])) {
       
   861 			$action ='menuadditems';	
       
   862 		} elseif ( isset($_POST['sendmail']) ) { //1.8.5
       
   863 			$action = 'sendmail' ; 
       
   864 		} elseif ( isset($_POST['uninstalloption']) ) { //1.8.8
       
   865 			$action = 'uninstalloption' ; 
       
   866 		} elseif ( isset($_POST['action'])) {
       
   867 			$action=$_POST['action'];
       
   868 		} 
       
   869 		
       
   870 		if (isset($_GET['action'])) :
       
   871 			$action=$_GET['action'];
       
   872 			$term_id = $_GET['term_id'];
       
   873 		endif;
       
   874 		$message = $action ;
       
   875 		
       
   876 		switch( $action ) {
       
   877 					
       
   878 			case 'uninstalloption' ; // 1.8.8 see Uninstall Options metabox in sidebar
       
   879 				$this->xili_settings['delete_settings'] = $_POST['delete_settings'];
       
   880 				update_option('xili_language_settings', $this->xili_settings);
       
   881 				break;
       
   882 				
       
   883 			case 'add';
       
   884 				check_admin_referer( 'xili-language-settings' );
       
   885 				$term = $_POST['language_name'];
       
   886 				if ("" != $term ) {
       
   887 					$slug = $_POST['language_nicename'];
       
   888 					$args = array( 'alias_of' => '', 'description' => $_POST['language_description'], 'parent' => 0, 'slug' =>$slug );
       
   889 				    
       
   890 				    $theids = $this->safe_lang_term_creation ( $term, $args );
       
   891 				    
       
   892 					if ( ! is_wp_error($theids) ) {
       
   893 						
       
   894 						wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
   895 				    	update_term_order ($theids['term_id'],$this->langs_group_tt_id,$_POST['language_order']);
       
   896 				    
       
   897 				    	$this->xili_settings['langs_list_status'] = "added"; // 1.6.0 
       
   898 				    	$lang_ids = $this->get_lang_ids();				
       
   899 				    	$this->available_langs = $lang_ids ;
       
   900 				    	$this->xili_settings['available_langs'] = $this->available_langs;
       
   901 				    	$this->xili_settings['lang_features'][$slug]['hidden'] = ( isset($_POST['language_hidden']) ) ? $_POST['language_hidden'] : "" ;
       
   902 				    	$this->xili_settings['lang_features'][$slug]['charset'] = ( isset($_POST['language_charset'])) ? $_POST['language_charset'] : "";
       
   903 						update_option('xili_language_settings', $this->xili_settings);
       
   904 				    	$actiontype = "add";
       
   905 				    	$message .= " - ".__('A new language was added.','xili-language');
       
   906 				    	$msg = 5;
       
   907 					} else {
       
   908 						$message .= " error type = " . $theids->get_error_message() . " with slug (". $slug .")"; //2.4
       
   909 						$msg = 10; 
       
   910 					} 	
       
   911 				} else {
       
   912 						$message .= " error type = empty name"; //2.4
       
   913 						$msg = 10;
       
   914 				}
       
   915 			    break;
       
   916 			    
       
   917 			case 'edit';
       
   918 				
       
   919 			    $actiontype = "edited";
       
   920 			    $language = get_term_and_order ($term_id,$this->langs_group_tt_id,TAXONAME);
       
   921 			    $submit_text = __('Update &raquo;');
       
   922 			    $formtitle = __('Edit language', 'xili-language');
       
   923 			    $message .= " - ".__('Language to update.','xili-language');
       
   924 			    $msg = 3;
       
   925 			    break;
       
   926 			    
       
   927 			case 'edited';
       
   928 				check_admin_referer( 'xili-language-settings' );
       
   929 			    $actiontype = "add";
       
   930 			    $term_id = $_POST['language_term_id'];
       
   931 			    $term = $_POST['language_name']; // 2.4
       
   932 			    $slug = $_POST['language_nicename'];
       
   933 				$args = array( 'name' => $term, 'alias_of' => '', 'description' => $_POST['language_description'], 'parent' => 0, 'slug' => $slug);
       
   934 				$theids = wp_update_term( $term_id, TAXONAME, $args);
       
   935 				if ( !is_wp_error($theids) ) {
       
   936 					wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
   937 					update_term_order ($theids['term_id'],$this->langs_group_tt_id,$_POST['language_order']);
       
   938 					$this->xili_settings['langs_list_status'] = "edited"; // 1.6.0 
       
   939 					$this->xili_settings['lang_features'][$slug]['hidden'] = ( isset ( $_POST['language_hidden'] ) ) ? $_POST['language_hidden'] : "";
       
   940 				    $this->xili_settings['lang_features'][$slug]['charset'] = $_POST['language_charset'];
       
   941 					update_option('xili_language_settings', $this->xili_settings);
       
   942 					$message .= " - ".__('A language was updated.','xili-language');
       
   943 					$msg = 4 ;
       
   944 				} else {
       
   945 					$msg = 8 ;
       
   946 					$message .= " error type = ".$theids->get_error_code(); //2.4
       
   947 				}
       
   948 			    break;
       
   949 			    
       
   950 			case 'delete';
       
   951 			    $actiontype = "deleting";
       
   952 			    $submit_text = __('Delete &raquo;','xili-language');
       
   953 			    $formtitle = __('Delete language ?', 'xili-language'); 
       
   954 			    $language = get_term_and_order ($term_id,$this->langs_group_tt_id,TAXONAME);
       
   955 			    $message .= " - ".__('A language to delete.','xili-language');
       
   956 			    $msg = 1;
       
   957 			    break;
       
   958 			    
       
   959 			case 'deleting';
       
   960 				check_admin_referer( 'xili-language-settings' );
       
   961 			    $actiontype = "add";
       
   962 			    $term_id = $_POST['language_term_id'];
       
   963 			    $slug = $_POST['language_nicename'];
       
   964 			    if ( isset ( $_POST['multilingual_links_erase'] ) && $_POST['multilingual_links_erase'] == 'erase' ) {
       
   965 			    	$this->multilingual_links_erase ( $term_id ); // as in uninstall.php - 1.8.8
       
   966 			    }
       
   967 			    
       
   968 			    wp_delete_object_term_relationships( $term_id, TAXOLANGSGROUP ); // degrouping
       
   969 			    wp_delete_term( $term_id, TAXONAME );
       
   970 			    
       
   971 			    $this->xili_settings['langs_list_status'] = "deleted"; // 1.6.0 
       
   972 			    $lang_ids = $this->get_lang_ids();				
       
   973 				$this->available_langs = $lang_ids ;
       
   974 				$this->xili_settings['available_langs'] = $this->available_langs;
       
   975 				unset ( $this->xili_settings['lang_features'][$slug] );
       
   976 				update_option('xili_language_settings', $this->xili_settings);
       
   977 			    $message .= " - ".__('A language was deleted.','xili-language');
       
   978 			    $msg = 2;
       
   979 			    break;
       
   980 			     
       
   981 			case 'reset';    
       
   982 			    $actiontype = "add";
       
   983 			    break;
       
   984 			    
       
   985 			default :
       
   986 			    $actiontype = "add";
       
   987 			    $message .= ' '.__('Find above the list of languages.','xili-language');
       
   988 			    
       
   989 			    
       
   990 		}
       
   991 		/* register the main boxes always available */
       
   992 		add_meta_box('xili-language-lang-list', __('List of languages','xili-language'), array(&$this,'on_box_lang_list_content'), $this->thehook , 'normal', 'high'); 
       
   993 		add_meta_box('xili-language-lang-form', __('Language','xili-language'), array(&$this,'on_box_lang_form_content'), $this->thehook , 'normal', 'high');
       
   994 				
       
   995 		$themessages[1] = __('A language to delete.','xili-language');
       
   996 		$themessages[2] = __('A language was deleted.','xili-language');
       
   997 		$themessages[3] = __('Language to update.','xili-language');
       
   998 		$themessages[4] = __('A language was updated.','xili-language');
       
   999 		$themessages[5] = __('A new language was added.','xili-language');
       
  1000 		$themessages[8] = __('Error when updating.','xili-language');
       
  1001 		$themessages[10] = __('Error when adding.','xili-language');
       
  1002 		
       
  1003 		/* form datas in array for do_meta_boxes() */
       
  1004 		$language_features = ( isset( $this->xili_settings['lang_features'][$language->slug] ) && '' != $language->slug ) ? $this->xili_settings['lang_features'][$language->slug] : array('charset'=>"",'hidden'=>"");
       
  1005 		$data = array(
       
  1006 			'message'=>$message, 'action'=>$action, 'formtitle'=>$formtitle, 'language'=>$language,'submit_text'=>$submit_text,'cancel_text'=>$cancel_text, 
       
  1007 			'language_features' => $language_features
       
  1008 		);
       
  1009 		?>
       
  1010 		
       
  1011 		<div id="xili-language-settings" class="wrap columns-2 minwidth" >
       
  1012 			<?php screen_icon('options-general'); ?>
       
  1013 			<h2><?php _e('Languages','xili-language') ?></h2>
       
  1014 			<h3 class="nav-tab-wrapper">
       
  1015 			<?php $this->set_tabs_line() ?>
       
  1016 			</h3>
       
  1017 			<?php //echo '---'.$id  ?>
       
  1018 			<?php if (0!= $msg ) { ?>
       
  1019 			<div id="message" class="updated fade"><p><?php echo $themessages[$msg]; ?></p></div>
       
  1020 			<?php } ?>
       
  1021 			<form name="add" id="add" method="post" action="options-general.php?page=language_page">
       
  1022 				<input type="hidden" name="action" value="<?php echo $actiontype ?>" />
       
  1023 				<?php wp_nonce_field('xili-language-settings'); ?>
       
  1024 				<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
       
  1025 				<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); 
       
  1026 				$this->setting_form_content( $this->thehook, $data );
       
  1027 				?>
       
  1028 		</form>
       
  1029 		</div>
       
  1030 		<?php $this->setting_form_js( $this->thehook ); 
       
  1031 	}
       
  1032 	
       
  1033 	/**
       
  1034 	 * Settings page for front-end features
       
  1035 	 *
       
  1036 	 * @since 2.4.1
       
  1037 	 */
       
  1038 	function languages_frontend_settings() { 
       
  1039 		
       
  1040 		$msg = 0;
       
  1041 		$themessages = array('ok');
       
  1042 		$action = '';
       
  1043 		$optionmessage = '';
       
  1044 		
       
  1045 		if (isset($_POST['reset'])) {
       
  1046 			$action =$_POST['reset'];
       
  1047 		} elseif ( isset($_POST['updateoptions']) ) {
       
  1048 			$action ='updateoptions';
       
  1049 		} elseif ( isset($_POST['updateundefined'])) {
       
  1050 			$action ='updateundefined';
       
  1051 			
       
  1052 		} elseif ( isset($_POST['action'])) {
       
  1053 			$action=$_POST['action'];
       
  1054 		} 
       
  1055 		
       
  1056 		if (isset($_GET['action'])) :
       
  1057 			$action=$_GET['action'];
       
  1058 			$term_id = $_GET['term_id'];
       
  1059 		endif;
       
  1060 		$message = $action ;
       
  1061 		
       
  1062 		
       
  1063 		switch( $action ) {
       
  1064 			
       
  1065 			case 'updateundefined'; // gold options 
       
  1066 				check_admin_referer( 'xili-language-frontsettings' );
       
  1067 				if ( function_exists('xiliml_setlang_of_undefined_posts') ) {
       
  1068 					$targetlang = $_POST['xili_language_toset'];
       
  1069 					$fromcats = $_POST['from_categories'];
       
  1070 					if (""!= $targetlang) {
       
  1071 						$q = xiliml_setlang_of_undefined_posts ($targetlang, $fromcats, 50);
       
  1072 						$message .= " _ $q ".__('posts are set in:','xili-language')." ".$targetlang." ".__("category")." =[$fromcats]";
       
  1073 					} else {
       
  1074 						$q = xiliml_setlang_of_undefined_posts ($targetlang, $fromcats, 50);
       
  1075 						$message .= " _ around $q ".__('posts are undefined in','xili-language')." ".__("category")."  = [$fromcats]";	
       
  1076 					}
       
  1077 				}
       
  1078 				
       
  1079 				break;
       
  1080 				
       
  1081 			case 'updateoptions'; // sidebox 3 - below in source
       
  1082 				check_admin_referer( 'xili-language-frontsettings' );
       
  1083 				$this->browseroption = ( isset($_POST['xili_language_check_option'] ) ) ? $_POST['xili_language_check_option'] : "";
       
  1084 				$this->authorbrowseroption = ( isset($_POST['xili_language_check_option_author'] ) ) ? $_POST['xili_language_check_option_author'] : "";
       
  1085 				$this->xili_settings['functions_enable'] = ( isset($_POST['xili_language_check_functions_enable'] ) ) ?$_POST['xili_language_check_functions_enable'] : "";
       
  1086 				$this->xili_settings['browseroption'] = $this->browseroption;
       
  1087 				$this->xili_settings['allcategories_lang'] = ( isset($_POST['allcategories_lang'] ) ) ?$_POST['allcategories_lang'] : ""; // 1.8.9.1
       
  1088 				$this->lang_neither_browser = ( isset($_POST['xili_lang_neither_browser'] ) ) ? $_POST['xili_lang_neither_browser'] : ""; // 2.3.1
       
  1089 				$this->xili_settings['lang_neither_browser'] = $this->lang_neither_browser ;
       
  1090 				$this->xili_settings['authorbrowseroption'] = $this->authorbrowseroption;
       
  1091 				
       
  1092 				$this->xili_settings['widget'] = ( isset($_POST['xili_language_widgetenable'] ) ) ? $_POST['xili_language_widgetenable'] : ""; //1.8.8 
       
  1093 				
       
  1094 				$this->xili_settings['homelang'] = ( isset($_POST['xili_language_home_lang'] ) ) ? $_POST['xili_language_home_lang'] : ""; // 1.3.2 
       
  1095 				/* since 1.8.0 */
       
  1096 				$types = get_post_types(array('show_ui'=>1));
       
  1097 				if ( count($types) > 2 ) {
       
  1098 					$desc_customs = $this->get_custom_desc() ;
       
  1099 					if ( count($desc_customs) > 0 ) {
       
  1100 						foreach ( $desc_customs as $type => $desc_custom) {
       
  1101 							if ( isset($_POST['xili_language_multilingual_custom_'.$type]) ) $desc_customs[$type]['multilingual'] = $_POST['xili_language_multilingual_custom_'.$type]; 
       
  1102 						}
       
  1103 						$this->xili_settings['multilingual_custom_post'] = $desc_customs ;
       
  1104 					} else {
       
  1105 						$this->xili_settings['multilingual_custom_post'] = array() ;
       
  1106 					}			
       
  1107 				} else {
       
  1108 					$this->xili_settings['multilingual_custom_post'] = array() ;	
       
  1109 				}
       
  1110 				/* widget settings */
       
  1111 				if ( current_theme_supports( 'widgets' ) ) {
       
  1112 					$link_cats = get_terms( 'link_category');
       
  1113 					$this->xili_settings['link_categories_settings']['all'] = ( isset($_POST['xili_language_link_cat_all'] ) && $_POST['xili_language_link_cat_all'] == 'enable'  ) ? true : false ; 
       
  1114 					foreach ( $link_cats as $link_cat ) {
       
  1115 						$this->xili_settings['link_categories_settings']['category'][$link_cat->term_id] = (( isset($_POST['xili_language_link_cat_'.$link_cat->term_id] ) && $_POST['xili_language_link_cat_'.$link_cat->term_id] == 'enable'  ) ? true : false );
       
  1116 					}
       
  1117 				}
       
  1118 								
       
  1119 				/* UPDATE OPTIONS */
       
  1120 				update_option('xili_language_settings', $this->xili_settings);
       
  1121 				
       
  1122 				/* messages */
       
  1123 				$optionmessage .= " - ".sprintf(__("Options are updated: home language = %s, For Author language of a new post = %s, xilidev functions = %s ",'xili-language'), $this->browseroption, $this->authorbrowseroption, $this->xili_settings['functions_enable'] );
       
  1124 				$message .= $optionmessage ;
       
  1125 				$msg = 1;
       
  1126 				$this->insert_gold_functions (); 
       
  1127 				
       
  1128 				break;
       
  1129 			
       
  1130 		}
       
  1131 		add_meta_box('xili-language-box-2', __('Settings','xili-language'), array(&$this,'on_box_frontend'), $this->thehook2 , 'normal', 'high');
       
  1132 		
       
  1133 		$themessages[1] = $optionmessage ;
       
  1134 		
       
  1135 		$data = array(
       
  1136 			'message'=>$message, 'action'=>$action, 
       
  1137 			'browseroption'=>$this->browseroption, 
       
  1138 			'authorbrowseroption'=>$this->authorbrowseroption , 
       
  1139 			'functions_enable'=>$this->xili_settings['functions_enable'],	
       
  1140 		);
       
  1141 		
       
  1142 		?>
       
  1143 		<div id="xili-language-frontsettings" class="wrap columns-2 minwidth">
       
  1144 			<?php screen_icon('options-general'); ?>
       
  1145 			<h2><?php _e('Languages','xili-language') ?></h2>
       
  1146 			<h3 class="nav-tab-wrapper">
       
  1147 			<?php $this->set_tabs_line() ?>
       
  1148 			</h3>
       
  1149 			
       
  1150 			<?php if (0!= $msg ) { ?>
       
  1151 			<div id="message" class="updated fade"><p><?php echo $themessages[$msg]; ?></p></div>
       
  1152 			<?php } ?>
       
  1153 			<form name="add" id="add" method="post" action="options-general.php?page=language_front_set">
       
  1154 				<?php wp_nonce_field('xili-language-frontsettings'); 
       
  1155 				wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false );
       
  1156 				wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); 
       
  1157 				$this->setting_form_content( $this->thehook2, $data );
       
  1158 			?>
       
  1159 			</form>
       
  1160 		</div>
       
  1161 		<?php $this->setting_form_js( $this->thehook2 ); 
       
  1162 	}
       
  1163 	
       
  1164 	/**
       
  1165 	 * Support page
       
  1166 	 *
       
  1167 	 * @since 2.4.1
       
  1168 	 */
       
  1169 	function languages_expert() { 
       
  1170 		
       
  1171 		$msg = 0;
       
  1172 		$themessages = array('ok');
       
  1173 		$action = '';
       
  1174 		$message = '';
       
  1175 		$optionmessage = '';
       
  1176 		
       
  1177 		if (isset($_POST['reset'])) {
       
  1178 			$action =$_POST['reset'];
       
  1179 		} elseif ( isset($_POST['menuadditems'])) {
       
  1180 			$action ='menuadditems';
       
  1181 		} elseif ( isset($_POST['updatespecials'])) {
       
  1182 			$action ='updatespecials';			
       
  1183 		} elseif ( isset($_POST['innavenable']) || isset($_POST['pagnavenable']) ) {
       
  1184 			$action ='menunavoptions';
       
  1185 		}
       
  1186 		
       
  1187 		switch( $action ) {
       
  1188 			case 'menuadditems';	
       
  1189 				check_admin_referer( 'xili-language-expert' );
       
  1190 				$this->xili_settings['navmenu_check_option2'] = $_POST['xili_navmenu_check_option2']; // 1.8.1
       
  1191 				
       
  1192 				$result = $this->add_list_of_language_links_in_wp_menu($this->xili_settings['navmenu_check_option2']);
       
  1193 				$optionmessage .= ' - '. __('Go to Nav-menus in Themes to validate changes','xili-language').' ('.$result.')';
       
  1194 				$message .= $optionmessage ;
       
  1195 				$msg = 1;
       
  1196 				
       
  1197 				break;
       
  1198 				
       
  1199 			case 'menunavoptions';
       
  1200 				check_admin_referer( 'xili-language-expert' );	
       
  1201 				if ( current_theme_supports( 'menus' ) ) {
       
  1202 					$menu_locations = get_nav_menu_locations(); 
       
  1203 					$selected_menu_locations = array();
       
  1204 					if ( $menu_locations ) { 
       
  1205 						foreach ($menu_locations as $menu_location => $location_id) {						
       
  1206 							if ( isset ( $_POST['xili_navmenu_check_option_'.$menu_location] ) && $_POST['xili_navmenu_check_option_'.$menu_location] == 'enable' ) {
       
  1207 								$selected_menu_locations[$menu_location]['navenable'] = 'enable';
       
  1208 								$selected_menu_locations[$menu_location]['navtype'] = $_POST['xili_navmenu_check_optiontype_'.$menu_location]; //0.9.1
       
  1209 							}
       
  1210 						}
       
  1211 					} else {
       
  1212 						$optionmessage = '<strong>'.__('Locations menu not set: go to menus settings','xili-language').'</strong> ';
       
  1213 					}
       
  1214 					$this->xili_settings['navmenu_check_options'] = $selected_menu_locations; // 2.1.0
       
  1215 					
       
  1216 					$this->xili_settings['in_nav_menu'] = ( isset($_POST['list_in_nav_enable'] ) ) ? $_POST['list_in_nav_enable'] : ""; // 1.6.0
       
  1217 					$this->xili_settings['page_in_nav_menu'] = ( isset($_POST['page_in_nav_enable'] ) ) ? $_POST['page_in_nav_enable'] : ""; // 1.7.1
       
  1218 					$this->xili_settings['args_page_in_nav_menu'] = ( isset($_POST['args_page_in_nav'] ) ) ? $_POST['args_page_in_nav'] : ""; // 1.7.1
       
  1219 					$this->xili_settings['navmenu_check_option'] = ( isset($_POST['xili_navmenu_check_option'] ) ) ? $_POST['xili_navmenu_check_option'] : "";
       
  1220 					$this->xili_settings['navmenu_check_optionp'] = ( isset($_POST['xili_navmenu_check_optionp'] ) ) ? $_POST['xili_navmenu_check_optionp'] : "";
       
  1221 					$this->xili_settings['home_item_nav_menu'] = ( isset($_POST['xili_home_item_nav_menu'] ) ) ?$_POST['xili_home_item_nav_menu'] : ""; // 1.8.9.2 
       
  1222 				// 1.8.1
       
  1223 				}
       
  1224 				/* UPDATE OPTIONS */
       
  1225 				update_option('xili_language_settings', $this->xili_settings);
       
  1226 				/* messages */
       
  1227 				$optionmessage .= " - ".sprintf(__("Options are updated: Automatic Nav Menu = %s, Selection of pages in Nav Menu = %s",'xili-language'), $this->xili_settings['in_nav_menu'], $this->xili_settings['page_in_nav_menu']);
       
  1228 				$message .= $optionmessage ;
       
  1229 				$msg = 1;
       
  1230 				
       
  1231 				
       
  1232 				break;
       
  1233 			
       
  1234 			case 'updatespecials':
       
  1235 				
       
  1236 				/* force rules flush - 2.1.1 */
       
  1237 				if ( isset($_POST['force_permalinks_flush'] ) && $_POST['force_permalinks_flush'] == 'enable' ) {
       
  1238 					$this->get_lang_slug_ids(); // if list need refresh
       
  1239 					flush_rewrite_rules( false );
       
  1240 				}
       
  1241 				/* domains switching settings 1.8.7 */
       
  1242 				foreach ( $this->xili_settings['domains'] as $domain => $state ) {
       
  1243 					if ( isset($_POST['xili_language_domains_'.$domain] ) && $_POST['xili_language_domains_'.$domain] == 'enable' ) {
       
  1244 						$this->xili_settings['domains'][$domain] = 'enable';
       
  1245 					} else {
       
  1246 						$this->xili_settings['domains'][$domain] = '';
       
  1247 					}
       
  1248 				}
       
  1249 				// 2.4.0
       
  1250 				$this->xili_settings['wp_locale'] = ( isset($_POST['xili_language_wp_locale'] ) ) ? $_POST['xili_language_wp_locale'] : "db_locale";
       
  1251 				$this->xili_settings['creation_redirect'] = ( isset($_POST['xili_language_creation_redirect'] ) ) ? $_POST['xili_language_creation_redirect'] : "";
       
  1252 				// xili_language_exists_style_ext on off
       
  1253 				$this->xili_settings['external_xl_style'] = ( isset($_POST['xili_language_external_xl_style'] ) ) ? $_POST['xili_language_external_xl_style'] : "off";
       
  1254 				/* UPDATE OPTIONS */
       
  1255 				update_option('xili_language_settings', $this->xili_settings);
       
  1256 				/* messages */
       
  1257 				$optionmessage .= " - ".sprintf(__("Options are updated %s ",'xili-language'), $this->xili_settings['wp_locale']);
       
  1258 				$message .= $optionmessage ;
       
  1259 				$msg = 1;
       
  1260 				
       
  1261 			break;		
       
  1262 		}
       
  1263 		
       
  1264 		add_meta_box('xili-language-box-3', __('Navigation menus','xili-language'), array(&$this,'on_box_expert'), $this->thehook4 , 'normal', 'high');
       
  1265 		
       
  1266 		$themessages[1] = $optionmessage ;
       
  1267 		
       
  1268 		$data = array(
       
  1269 			'message'=>$message, 'action'=>$action, 'list_in_nav_enable' => $this->xili_settings['in_nav_menu'],
       
  1270 			'args_page_in_nav' => $this->xili_settings['args_page_in_nav_menu'], 'page_in_nav_enable' => $this->xili_settings['page_in_nav_menu'],
       
  1271 			);
       
  1272 		?>
       
  1273 		<div id="xili-language-support" class="wrap columns-2 minwidth">
       
  1274 			<?php screen_icon('options-general'); ?>
       
  1275 			<h2><?php _e('Languages','xili-language') ?></h2>
       
  1276 			<h3 class="nav-tab-wrapper">
       
  1277 			<?php $this->set_tabs_line() ?>
       
  1278 			</h3>
       
  1279 			
       
  1280 			<?php if (0!= $msg ) { ?>
       
  1281 			<div id="message" class="updated fade"><p><?php echo $themessages[$msg]; ?></p></div>
       
  1282 			<?php } ?>
       
  1283 			<form name="add" id="add" method="post" action="options-general.php?page=language_expert">
       
  1284 				<?php wp_nonce_field('xili-language-expert'); ?>
       
  1285 				<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
       
  1286 				<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); 
       
  1287 				$this->setting_form_content( $this->thehook4, $data );
       
  1288 			?>	
       
  1289 			</form>
       
  1290 		</div>
       
  1291 		<?php $this->setting_form_js( $this->thehook4 );
       
  1292 	
       
  1293 	}
       
  1294 	
       
  1295 	/**
       
  1296 	 * Support page
       
  1297 	 *
       
  1298 	 * @since 2.4.1
       
  1299 	 */
       
  1300 	function languages_support() { 
       
  1301 		global $wp_version ;
       
  1302 		$msg = 0;
       
  1303 		$themessages = array('ok');
       
  1304 		$emessage = "";
       
  1305 		$action = '';
       
  1306 		if ( isset( $_POST['sendmail'] ) ) {
       
  1307 			$action = 'sendmail' ; 
       
  1308 		} 
       
  1309 		$message = $action ;
       
  1310 		
       
  1311 		
       
  1312 		switch( $action ) {	
       
  1313 		
       
  1314 			case 'sendmail'; // 1.8.5
       
  1315 					check_admin_referer( 'xili-postinpost-sendmail' ); 
       
  1316 					$this->xili_settings['url'] = ( isset( $_POST['urlenable'] ) ) ? $_POST['urlenable'] : '' ;
       
  1317 					$this->xili_settings['theme'] = ( isset( $_POST['themeenable'] ) ) ? $_POST['themeenable'] : '' ;
       
  1318 					$this->xili_settings['wplang'] = ( isset( $_POST['wplangenable'] ) ) ? $_POST['wplangenable'] : '' ;
       
  1319 					$this->xili_settings['version'] = ( isset( $_POST['versionenable'] ) ) ? $_POST['versionenable'] : '' ;
       
  1320 					$this->xili_settings['xiliplug'] = ( isset( $_POST['xiliplugenable'] ) ) ? $_POST['xiliplugenable'] : '' ;
       
  1321 					update_option('xili_language_settings', $this->xili_settings);
       
  1322 					$contextual_arr = array();
       
  1323 					if ( $this->xili_settings['url'] == 'enable' ) $contextual_arr[] = "url=[ ".get_bloginfo ('url')." ]" ;
       
  1324 					if ( isset($_POST['onlocalhost']) ) $contextual_arr[] = "url=local" ;
       
  1325 					if ( $this->xili_settings['theme'] == 'enable' ) $contextual_arr[] = "theme=[ ".get_option ('stylesheet')." ]" ;
       
  1326 					if ( $this->xili_settings['wplang'] == 'enable' ) $contextual_arr[] = "WPLANG=[ ".WPLANG." ]" ;
       
  1327 					if ( $this->xili_settings['version'] == 'enable' ) $contextual_arr[] = "WP version=[ ".$wp_version." ]" ;
       
  1328 					if ( $this->xili_settings['xiliplug'] == 'enable' ) $contextual_arr[] = "xiliplugins=[ ". $this->check_other_xili_plugins() ." ]" ;
       
  1329 					$contextual_arr[] = $_POST['webmestre']; // 1.9.1
       
  1330 					
       
  1331 					$headers = 'From: xili-language plugin page <' . get_bloginfo ('admin_email').'>' . "\r\n" ;
       
  1332 		   			if ( '' != $_POST['ccmail'] ) { 
       
  1333 		   				$headers .= 'Cc: <'.$_POST['ccmail'].'>' . "\r\n";
       
  1334 		   				$headers .= 'Reply-To: <'.$_POST['ccmail'].'>' . "\r\n";
       
  1335 		   			}
       
  1336 		   			$headers .= "\\";
       
  1337 		   			$message = "Message sent by: ".get_bloginfo ('admin_email')."\n\n" ;
       
  1338 		   			$message .= "Subject: ".$_POST['subject']."\n\n" ;
       
  1339 		   			$message .= "Topic: ".$_POST['thema']."\n\n" ;
       
  1340 		   			$message .= "Content: ".$_POST['mailcontent']."\n\n" ;
       
  1341 		   			$message .= "Checked contextual infos: ". implode ( ', ', $contextual_arr ) ."\n\n" ;
       
  1342 		   			$message .= "This message was sent by webmaster in xili-language plugin settings page.\n\n";
       
  1343 		   			$message .= "\n\n"; 
       
  1344 		   			if ( preg_match ( '/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}$/i', $_POST['ccmail'] ) && preg_match ( '/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}$/i', get_bloginfo ('admin_email') ) ) {
       
  1345 			   			$result = wp_mail('contact@xiligroup.com', $_POST['thema'].' from xili-language v.'.XILILANGUAGE_VER.' plugin settings page.' , $message, $headers );
       
  1346 			   			$message = __('Email sent.','xili-language');
       
  1347 						$msg = 1;
       
  1348 						$emessage = sprintf( __( 'Thanks for your email. A copy was sent to %s (%s)','xili-language' ), $_POST['ccmail'],  $result ) ;
       
  1349 		   			} else {
       
  1350 		   				$msg = 2;
       
  1351 		   				$emessage = sprintf( __( 'Issue in your email. NOT sent to Cc: %s or the return address %s is not good !','xili-language' ), $_POST['ccmail'], get_bloginfo ('admin_email') ) ;
       
  1352 		   			}
       
  1353 			break;
       
  1354 		}
       
  1355 		$themessages[1] = __('Email sent.','xili-language');
       
  1356 		$themessages[2] = __('Email not sent. Please verify email field','xili-language');
       
  1357 		
       
  1358 		add_meta_box('xili-language-box-mail', __('Mail & Support','xili-language'), array(&$this,'on_box_mail_content'), $this->thehook3 , 'normal', 'low');
       
  1359 		
       
  1360 		
       
  1361 		
       
  1362 		$data = array(
       
  1363 			'message'=>$message, 'action'=>$action, 'emessage'=>$emessage
       
  1364 		);
       
  1365 		
       
  1366 		?>
       
  1367 		<div id="xili-language-support" class="wrap columns-2 minwidth">
       
  1368 			<?php screen_icon('options-general'); ?>
       
  1369 			<h2><?php _e('Languages','xili-language') ?></h2>
       
  1370 			<h3 class="nav-tab-wrapper">
       
  1371 			<?php $this->set_tabs_line() ?>
       
  1372 			</h3>
       
  1373 			<?php //echo '---'.$id  ?>
       
  1374 			<?php if (0!= $msg ) { ?>
       
  1375 			<div id="message" class="updated fade"><p><?php echo $themessages[$msg]; ?></p></div>
       
  1376 			<?php } ?>
       
  1377 			<form name="add" id="add" method="post" action="options-general.php?page=language_support">
       
  1378 				<?php wp_nonce_field('xili-language-support'); ?>
       
  1379 				<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
       
  1380 				<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>
       
  1381 				<p class="width23 boldtext">
       
  1382 				<?php printf(__("For support, before sending an email with the form below, don't forget to visit the readme as %shere%s and the links listed in contextual help tab (on top left).",'xili-language'),'<a href="http://wordpress.org/extend/plugins/xili-language/" target="_blank">','</a>' ); ?>
       
  1383 				</p>	
       
  1384 				<?php $this->setting_form_content( $this->thehook3, $data );
       
  1385 			?>	
       
  1386 			</form>
       
  1387 		</div>
       
  1388 		<?php $this->setting_form_js( $this->thehook3 ); 
       
  1389 	}
       
  1390 	
       
  1391 	
       
  1392 	function check_other_xili_plugins () {
       
  1393 		$list = array();
       
  1394 		//if ( class_exists( 'xili_language' ) ) $list[] = 'xili-language' ;
       
  1395 		if ( class_exists( 'xili_tidy_tags' ) ) $list[] = 'xili-tidy-tags' ;
       
  1396 		if ( class_exists( 'xili_dictionary' ) ) $list[] = 'xili-dictionary' ;
       
  1397 		if ( class_exists( 'xilithemeselector' ) ) $list[] = 'xilitheme-select' ;
       
  1398 		if ( function_exists( 'insert_a_floom' ) ) $list[] = 'xili-floom-slideshow' ;
       
  1399 		if ( class_exists( 'xili_postinpost' ) ) $list[] = 'xili-postinpost' ;
       
  1400 		return implode (', ',$list) ;
       
  1401 	}
       
  1402 	
       
  1403 	
       
  1404 	/**
       
  1405 	 * for each page : tabs line
       
  1406 	 * @since 2.4.1
       
  1407 	 */
       
  1408 	function set_tabs_line() {
       
  1409 		global $pagenow;
       
  1410 		$id = isset( $_REQUEST['page'] ) ? $_REQUEST['page']  : 'language_page';
       
  1411 		$tabs = array(
       
  1412 				'language-page' => array( 'label' => __( 'Languages page', 'xili-language' ), 'url' => 'options-general.php?page=language_page'     ),
       
  1413 				'language-frontend-settings' => array( 'label' => __( 'Languages front-end settings', 'xili-language' ), 'url' => 'options-general.php?page=language_front_set'    ),
       
  1414 				'language-expert' => array( 'label' => __( 'Settings for experts', 'xili-language' ), 'url' => 'options-general.php?page=language_expert'   ),
       
  1415 				'language-support' => array( 'label' => __( 'xili-language support', 'xili-language' ), 'url' => 'options-general.php?page=language_support'   ),
       
  1416 			);
       
  1417 		foreach ( $tabs as $tab_id => $tab ) {
       
  1418 				$class = ( $tab['url'] == $pagenow.'?page='.$id ) ? ' nav-tab-active' : '';
       
  1419 				echo '<a href="' . $tab['url'] .'" class="nav-tab' . $class . '">' .  esc_html( $tab['label'] ) . '</a>';
       
  1420 		}
       
  1421 	}
       
  1422 	
       
  1423 	/**
       
  1424 	 * for each three forms of settings side-info-column 
       
  1425 	 * @since 2.4.1
       
  1426 	 * @updated 2.5
       
  1427 	 */
       
  1428 	function setting_form_content( $the_hook, $data ) {
       
  1429 		global $wp_version;
       
  1430 		if ( version_compare($wp_version, '3.3.9', '<') ) {
       
  1431 			$poststuff_class = 'class="metabox-holder has-right-sidebar"';
       
  1432 			$postbody_class = "";
       
  1433 			$postleft_id = "";
       
  1434 			$postright_id = "side-info-column";
       
  1435 			$postleft_class = "";
       
  1436 			$postright_class = "inner-sidebar";
       
  1437 		} else { // 3.4
       
  1438 			$poststuff_class = "";
       
  1439 			$postbody_class = 'class="metabox-holder columns-2"';
       
  1440 			$postleft_id = 'id="postbox-container-2"';
       
  1441 			$postright_id = "postbox-container-1";
       
  1442 			$postleft_class = 'class="postbox-container"';
       
  1443 			$postright_class = "postbox-container";
       
  1444 		}
       
  1445 		
       
  1446 		?>
       
  1447 		<div id="poststuff" <?php echo $poststuff_class; ?>>
       
  1448 			<div id="post-body" <?php echo $postbody_class; ?> >
       
  1449 				
       
  1450 				<div id="<?php echo $postright_id; ?>" class="<?php echo $postright_class; ?>">
       
  1451 					<?php do_meta_boxes($the_hook, 'side', $data); ?>
       
  1452 				</div>
       
  1453 			
       
  1454 				<div id="post-body-content">
       
  1455 					
       
  1456 					<div <?php echo $postleft_id; ?> <?php echo $postleft_class; ?> style="min-width:360px">
       
  1457 						<?php do_meta_boxes($the_hook, 'normal', $data); ?>
       
  1458 					</div>
       
  1459 					
       
  1460 					<h4><a href="http://dev.xiligroup.com/xili-language" title="xili-language page and docs" target="_blank" style="text-decoration:none" ><img style="vertical-align:middle" src="<?php echo plugins_url( 'images/xililang-logo-32.jpg', $this->file_file ) ;  ?>" alt="xili-language logo"/></a> - © <a href="http://dev.xiligroup.com" target="_blank" title="<?php _e('Author'); ?>" >xiligroup.com</a>™ - msc 2007-2012 - v. <?php echo XILILANGUAGE_VER; ?></h4>	
       
  1461 					
       
  1462 				</div>	
       
  1463 			</div>
       
  1464 			<br class="clear" />
       
  1465 		</div>
       
  1466 	<?php		
       
  1467 	}
       
  1468 	
       
  1469 	/**
       
  1470 	 * add js at end of each three forms of settings
       
  1471 	 * @since 2.4.1
       
  1472 	 */
       
  1473 	function setting_form_js( $the_hook ) { ?>
       
  1474 	<script type="text/javascript">
       
  1475 	//<![CDATA[
       
  1476 			jQuery(document).ready( function($) {
       
  1477 				// close postboxes that should be closed
       
  1478 				$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
       
  1479 				// postboxes setup
       
  1480 				postboxes.add_postbox_toggles('<?php echo $the_hook; ?>');
       
  1481 			
       
  1482 			<?php if ( $the_hook == $this->thehook ) {	?>
       
  1483 				// for examples list
       
  1484 				$('#language_name_list').change(function() {
       
  1485                  	var x = $(this).val();
       
  1486       				$('#language_name').val(x);
       
  1487       				var x = $(this).val();
       
  1488       				x = x.toLowerCase();
       
  1489       				$('#language_nicename').val(x);
       
  1490       				var v = $('#language_name_list option:selected').text();
       
  1491       				v = v.substring(0,v.indexOf(" (",0));
       
  1492       				$('#language_description').val(v);
       
  1493     			});
       
  1494 			<?php } ?>
       
  1495 			});
       
  1496 			//]]>
       
  1497 		</script>
       
  1498 	<?php
       
  1499 	}
       
  1500 	
       
  1501 	
       
  1502 	
       
  1503 	/***************** Side settings metaboxes *************/
       
  1504 
       
  1505 	/**
       
  1506 	 * private functions for languages_settings 
       
  1507 	 * @since 0.9.6
       
  1508 	 *
       
  1509 	 * fill the content of the boxes (right side and normal)
       
  1510 	 * 
       
  1511 	 */
       
  1512 	function  on_sidebox_msg_content( $data ) { 
       
  1513 		extract($data);
       
  1514 		?>
       
  1515 	 	<h4><?php _e('Note:','xili-language') ?></h4>
       
  1516 		<p><?php echo $message;?></p>
       
  1517 		<?php
       
  1518 	}
       
  1519 	
       
  1520 	/** 
       
  1521 	 * info box 
       
  1522 	 */
       
  1523 	function  on_sidebox_info_content() { ?>
       
  1524 	 	
       
  1525 		<p><?php _e("This plugin was developed with the taxonomies, terms tables and WP specifications. <br /> xili-language create a new taxonomy used for language of posts and pages and custom post types. For settings (basic or expert), 4 tabs were available since v. 2.4.1.<br /><br /> To attach a language to a post, a box gathering infos in available in new and edit post admin side pages. Also, selectors are in Quick Edit bulk mode of Posts list. It is updated for WP 3.3 and 3.4 since 2.5 version.",'xili-language') ?></p>
       
  1526 		<?php
       
  1527 	}	
       
  1528 	
       
  1529 	/** 
       
  1530 	 *where to choose if browser language preferences is tested or not 
       
  1531 	 */
       
  1532 	function on_box_frontend ( $data ) { 
       
  1533 		extract( $data );
       
  1534 		/* 1.0 browser - default - languages */
       
  1535 		
       
  1536 		
       
  1537 		?>
       
  1538 		<fieldset class="box leftbox">
       
  1539 			<p><?php _e('Here select language of the home page', 'xili-language'); ?></p>	
       
  1540 		</fieldset>
       
  1541 		<fieldset class="box rightbox" ><legend><?php _e('Select language of the home page', 'xili-language'); ?></legend>
       
  1542 			<select name="xili_language_check_option" id="xili_language_check_option" class="fullwidth">
       
  1543 				<?php  if ( $browseroption == 'browser' )
       
  1544 						$checked = 'selected = "selected"';
       
  1545 						else 
       
  1546 						$checked = '';
       
  1547 				?>
       
  1548 				<option value="" ><?php _e('Software defined','xili-language'); ?></option>
       
  1549 				<option value="browser" <?php echo $checked; ?> ><?php _e("Language of visitor's browser",'xili-language'); ?></option>
       
  1550 				<?php $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
       
  1551 			foreach ($listlanguages as $language) {
       
  1552 				if ($browseroption == $language->slug) 
       
  1553 						$checked = 'selected = "selected"';
       
  1554 					else 
       
  1555 						$checked = '';
       
  1556 				echo '<option value="'.$language->slug.'" '.$checked.' >'.__($language->description,'xili-language').'</option>';
       
  1557 			}
       
  1558 				?>
       
  1559 			</select>
       
  1560 			
       
  1561 			<?php  if ( $browseroption == 'browser' ) {  // 2.3.1 ?>	
       
  1562 				<br /><label for="xili_lang_neither_browser" ><?php _e("if not found",'xili-language'); ?>:&nbsp;<select name="xili_lang_neither_browser" id="xili_lang_neither_browser" class="width23">
       
  1563 				<?php  if ( $this->lang_neither_browser == '' )
       
  1564 						$checked = 'selected = "selected"';
       
  1565 						else 
       
  1566 						$checked = '';
       
  1567 				?>
       
  1568 				<option value="" <?php echo $checked; ?> ><?php _e("Language of dashboard",'xili-language'); ?></option>
       
  1569 				<?php 
       
  1570 				foreach ($listlanguages as $language) {
       
  1571 					if ( $this->lang_neither_browser == $language->slug ) 
       
  1572 							$checked = 'selected = "selected"';
       
  1573 						else 
       
  1574 							$checked = '';
       
  1575 					echo '<option value="'.$language->slug.'" '.$checked.' >'.__($language->description,'xili-language').'</option>';
       
  1576 				}
       
  1577 				?>
       
  1578 				</select></label>
       
  1579 			<?php }  ?>	
       
  1580 
       
  1581 			<?php  if ( !$this->show_page_on_front ) { ?>
       
  1582 				<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>
       
  1583 				<?php }  ?>
       
  1584 					</fieldset>
       
  1585 		<br />			
       
  1586 		<fieldset class="box leftbox">
       
  1587 			<p><?php _e('Here select language of the theme items when a category is displayed without language sub-selection', 'xili-language'); ?></p>	
       
  1588 		</fieldset>			
       
  1589 		<fieldset class="box rightbox"><legend><?php _e("Theme's language when categories in 'all'", 'xili-language'); ?></legend>
       
  1590 			<label for="allcategories_lang" >
       
  1591 			<select name="allcategories_lang" id="allcategories_lang" class="fullwidth">
       
  1592 				<?php $allcategories_lang = $this->xili_settings['allcategories_lang']; ?>
       
  1593 				<option value="" ><?php _e('Software defined','xili-language'); ?></option>
       
  1594 				<option value="browser" <?php echo  ( ($allcategories_lang == 'browser') ? 'selected = "selected"' : '' ) ; ?> ><?php _e("Language of visitor's browser",'xili-language'); ?></option>
       
  1595 				<option value="firstpost" <?php echo  ( ($allcategories_lang == 'firstpost') ? 'selected = "selected"' : '' ) ; ?> ><?php _e("Language of first post in loop",'xili-language'); ?></option>
       
  1596 				<?php 
       
  1597 				foreach ($listlanguages as $language) {
       
  1598 					if ($allcategories_lang == $language->slug) 
       
  1599 						$checked = 'selected = "selected"';
       
  1600 					else 
       
  1601 						$checked = '';
       
  1602 				echo '<option value="'.$language->slug.'" '.$checked.' >'.__($language->description,'xili-language').'</option>';
       
  1603 			}
       
  1604 				?>
       
  1605 			</select></label>
       
  1606 	
       
  1607 		</fieldset>
       
  1608 		<br />
       
  1609 		<fieldset class="box leftbox">
       
  1610 			<p><?php _e('For new post, in post edit author side:', 'xili-language'); ?></p>	
       
  1611 		</fieldset>
       
  1612 		<fieldset class="box rightbox">
       
  1613 		<label for="xili_language_check_option_author" class="selectit">
       
  1614 		
       
  1615 		<select name="xili_language_check_option_author" id="xili_language_check_option_author" class="fullwidth" >
       
  1616 			<option value="" <?php selected( '', $authorbrowseroption ); ?>><?php _e('No default language','xili-language'); ?></option>
       
  1617 			<option value="authorbrowser" <?php selected( 'authorbrowser', $authorbrowseroption ); ?>><?php _e('Browser language','xili-language'); ?></option>
       
  1618 			<option value="authordashboard" <?php selected( 'authordashboard', $authorbrowseroption ); ?>><?php _e('Dashboard language','xili-language'); ?></option>
       
  1619 		</select><br /><em>
       
  1620 		<?php _e('For new post, pre-select by default the browser or dashboard language of current author', 'xili-language'); /* 2.8.0*/ ?></em></label>
       
  1621 		
       
  1622 		</fieldset>
       
  1623 		<br /><br />
       
  1624 		<?php if ( file_exists( WP_PLUGIN_DIR . $this->xilidev_folder ) ) { /* test if folder exists - ready to add functions.php inside - since 1.0 */?>
       
  1625 		<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 _e('Enable gold functions', 'xili-language'); ?></label>&nbsp;&nbsp;
       
  1626 		<?php } else {	
       
  1627 		echo '<input type="hidden" name="xili_language_check_functions_enable" value="'.$functions_enable.'" />';
       
  1628 		} 
       
  1629 		?>
       
  1630 		<br /><br />
       
  1631 		<?php 
       
  1632 		$types = get_post_types(array('show_ui'=>1));
       
  1633 		
       
  1634 		if ( count($types) > 2 ) {
       
  1635 			$thecheck = array() ;
       
  1636 			$thecustoms = $this->get_custom_desc() ;
       
  1637 			if ( count($thecustoms) > 0 ) {	
       
  1638 				foreach ( $thecustoms as $type => $thecustom) { 
       
  1639 					$thecheck[] = $type ;
       
  1640 				}
       
  1641 				$clabel = implode(', ', $thecheck);
       
  1642 		
       
  1643 		
       
  1644 		?>
       
  1645 		<fieldset class="box fullwidth"><legend><?php _e('Multilingual custom posts', 'xili-language'); ?></legend>
       
  1646 		<?php ( count($thecheck) == 1 ) ? printf(__('One custom post (%s) is available.','xili-language'), $clabel ) : printf(__('More than one custom post (%s) are available.','xili-language'), $clabel );
       
  1647 		?>
       
  1648 		<br /><?php _e('Check the custom to enable multilanguage features.', 'xili-language'); ?><br /><br />
       
  1649 		<?php 
       
  1650 		$customs_options = $this->xili_settings['multilingual_custom_post'];
       
  1651 		foreach ( $thecustoms as $type => $thecustom) { 
       
  1652 			$customs_enable = ( isset($customs_options[$type]) ) ? $customs_options[$type]['multilingual'] : '';	
       
  1653 		?>	
       
  1654 		<label for="xili_language_multilingual_custom_<?php echo $type; ?>" class="selectit"><input id="xili_language_multilingual_custom_<?php echo $type; ?>" name="xili_language_multilingual_custom_<?php echo $type; ?>" type="checkbox" value="enable"  <?php if($customs_enable =='enable') echo 'checked="checked"' ?> /> <?php echo $thecustom['singular_name']; ?></label><br />
       
  1655 		<?php } ?>
       
  1656 		
       
  1657 		</fieldset>	
       
  1658 		<?php } }
       
  1659 		if ( current_theme_supports( 'widgets' ) ) {  // 1.8.8 ?>
       
  1660 			<br /><label for="xili_language_widgetenable" class="selectit"><input id="xili_language_widgetenable" name="xili_language_widgetenable" type="checkbox" value="enable"  <?php if($this->xili_settings['widget'] =='enable') echo 'checked="checked"' ?> /> <?php _e('Enable widgets', 'xili-language'); ?></label><br /><br />
       
  1661 		<?php } else { 
       
  1662 			echo '<br /><small>'.__('Current theme has no widgets support.','xili-language').'</small>';		
       
  1663 			echo '<input type="hidden" name="xili_language_widgetenable" value="'.$this->xili_settings['widget'].'" />';
       
  1664 		}  
       
  1665 		if ( current_theme_supports( 'widgets' ) ) {  // theme widget enable
       
  1666 			$link_cats = get_terms( 'link_category');
       
  1667 			$cat_settings = ( isset($this->xili_settings['link_categories_settings'] ) ) ? $this->xili_settings['link_categories_settings']  : array ( 'all' => '', 'category' => array() ) ; // 2.3.1
       
  1668 			?>	
       
  1669 			<fieldset class="box fullwidth"><legend><?php _e('Bookmarks widget settings', 'xili-language'); ?></legend>
       
  1670 			<?php _e("Check the bookmark's categories where to enable multilanguage features.", "xili-language"); ?><br /><br />
       
  1671 			
       
  1672 			<label for="xili_language_link_cat_all" class="selectit"><input id="xili_language_link_cat_all" name="xili_language_link_cat_all" type="checkbox" value="enable"  <?php if( $cat_settings['all'] == 'enable') echo 'checked="checked"' ?> /> <?php _e('All Links'); ?></label><br />
       
  1673 			<?php
       
  1674 			foreach ( $link_cats as $link_cat ) {
       
  1675 				
       
  1676 			?>
       
  1677 			<label for="xili_language_link_cat_<?php echo intval($link_cat->term_id) ?>" class="selectit"><input id="xili_language_link_cat_<?php echo intval($link_cat->term_id) ?>" name="xili_language_link_cat_<?php echo intval($link_cat->term_id) ?>" type="checkbox" value="enable"  <?php echo ( isset( $cat_settings['category'][$link_cat->term_id] ) && $cat_settings['category'][$link_cat->term_id]  == 'enable' ) ? ' checked="checked"' : ''  ?> /> <?php echo $link_cat->name ; ?></label><br />
       
  1678 			
       
  1679 			<?php	
       
  1680 			}
       
  1681 			?>
       
  1682 			
       
  1683 			
       
  1684 			</fieldset><br />
       
  1685 		<?php } ?>
       
  1686 		
       
  1687 	 	<div class='submit'>
       
  1688 		<input id='updateoptions' name='updateoptions' type='submit' tabindex='6' value="<?php _e('Update','xili-language') ?>" /></div>
       
  1689 		
       
  1690 		<div class="clearb1"></div><?php
       
  1691 	}
       
  1692 	
       
  1693 	/**
       
  1694 	 * Special box
       
  1695 	 *
       
  1696 	 * @since 2.4.1
       
  1697 	 *
       
  1698 	 */
       
  1699 	function on_sidebox_for_specials ( $data ) {
       
  1700 		if ($this->lang_perma ) { // to force permalinks flush ?> 
       
  1701 			
       
  1702 			<fieldset class="box"><legend><?php _e('Permalinks rules', 'xili-language'); ?></legend>
       
  1703 			<label for="force_permalinks_flush" class="selectit"><input id="force_permalinks_flush" name="force_permalinks_flush" type="checkbox" value="enable"  /> <?php _e('force permalinks flush', 'xili-language'); ?></label> 
       
  1704 			</fieldset><br />
       
  1705 		<?php } ?>
       
  1706 		<fieldset class="box"><legend><?php _e('Translation domains settings', 'xili-language'); ?></legend><p>
       
  1707 			<?php _e("For experts in multilingual CMS: Check to modify domains switching.", "xili-language"); ?><br /><br />
       
  1708 			<?php
       
  1709 			foreach ( $this->xili_settings['domains'] as $domain => $state ) {
       
  1710 				$domaininlist = ( $domain == 'all' ) ? __( 'Switch all domains excepted default WP','xili-language' ) : $domain ;
       
  1711 			?>
       
  1712 			<label for="xili_language_domains_<?php echo $domain ; ?>" class="selectit"><input id="xili_language_domains_<?php echo $domain ; ?>" name="xili_language_domains_<?php echo $domain ; ?>" type="checkbox" value="enable"  <?php echo ( $state  == 'enable' ? ' checked="checked"' : '' ) ?> /> <?php echo $domaininlist ; ?></label><br />
       
  1713 			
       
  1714 			<?php	
       
  1715 			}
       
  1716 			if ( $this->show ) print_r( $this->arraydomains ) ;
       
  1717 			 ?>
       
  1718 		</p></fieldset>
       
  1719 		<fieldset class="box" ><legend><?php _e('Dashboard style: External xl-style.css', 'xili-language'); ?></legend>
       
  1720 		<?php
       
  1721 		if ( ! $this->exists_style_ext ) {
       
  1722 			
       
  1723 			echo '<p>'. __( 'There is no style for dashboard','xili-language' ) .' ('.$this->style_message . ' )</p>';
       
  1724 			
       
  1725 		} else {
       
  1726 			
       
  1727 			echo '<p>'. $this->style_message . '</p>';
       
  1728 		}
       
  1729 		?>
       
  1730 		<p><label for="xili_language_external_xl_style"><?php _e('Activate xl-style.css','xili-language') ?> <input id="xili_language_external_xl_style" name="xili_language_external_xl_style" type="checkbox" value="on" <?php if( $this->xili_settings['external_xl_style'] == 'on') echo 'checked="checked"' ?> /></label></p>
       
  1731 		</fieldset>
       
  1732 		<fieldset class="box" ><legend><?php _e('Locale (date) translation', 'xili-language'); ?></legend><p>
       
  1733 			<?php _e("Since v2.4, new way for locale (wp_locale) translation.", "xili-language"); ?><br /><br />
       
  1734 			<label for="xili_language_wp_locale"><?php _e('Mode wp_locale','xili-language') ?> <input id="xili_language_wp_locale" name="xili_language_wp_locale" type="checkbox" value="wp_locale" <?php if( $this->xili_settings['wp_locale'] == 'wp_locale') echo 'checked="checked"' ?> /></label></p>
       
  1735 		</fieldset>
       
  1736 	 	<fieldset class="box"><legend><?php _e('Redirect to created post', 'xili-language'); ?></legend><p>
       
  1737 			<?php _e("After creating a linked post in other language, the Edit post is automatically displayed.", "xili-language"); ?><br /><br />
       
  1738 			<label for="xili_language_creation_redirect"><?php _e('Redirection','xili-language') ?> <input id="xili_language_creation_redirect" name="xili_language_creation_redirect" type="checkbox" value="redirect" <?php if( $this->xili_settings['creation_redirect'] == 'redirect') echo 'checked="checked"' ?> /></label></p>
       
  1739 		</fieldset>
       
  1740 	 	
       
  1741 	 	
       
  1742 	 	<div class='submit'>
       
  1743 		<input id='updatespecials' name='updatespecials' type='submit' tabindex='6' value="<?php _e('Update','xili-language') ?>" /></div>
       
  1744 		
       
  1745 		<div class="clearb1"></div><?php
       
  1746 	
       
  1747 	}
       
  1748 	
       
  1749 	/**
       
  1750 	 * Theme's information box
       
  1751 	 *
       
  1752 	 * @since 2.4.1
       
  1753 	 *
       
  1754 	 */
       
  1755 	function on_sidebox_4_theme_info( $data ) {
       
  1756 		$template_directory = $this->get_template_directory;
       
  1757 		if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0
       
  1758 			$theme_name = get_option("stylesheet").' '.__('child of','xili-language').' '.get_option("template"); 
       
  1759 		} else {
       
  1760 			$theme_name = get_option("template"); 
       
  1761 		}
       
  1762 	 	?>
       
  1763 	 	<fieldset class="themeinfo"><legend><?php echo __("Theme type and domain:",'xili-language'); ?></legend>
       
  1764 	 		<p><strong><?php echo ' - '.$theme_name.' -'; ?></strong>
       
  1765 	 		<?php 
       
  1766 	 		if ("" != $this->parent->thetextdomain) {
       
  1767 	 			echo __('theme_domain:','xili-language').' <em>'.$this->parent->thetextdomain.'</em><br />'.__('as function like:','xili-language').'<em> _e(\'-->\',\''.$this->parent->thetextdomain.'\');</em>'; 
       
  1768 	 		} else {
       
  1769 	 			echo '<span class="red-alert">'.$this->admin_messages['alert']['no_domain_defined'].'</span>';
       
  1770 	 			if (''!=$this->domaindetectmsg) { 
       
  1771 	 				echo '<br /><span class="red-alert">'. $this->domaindetectmsg.' '.$this->admin_messages['alert']['default'].'</span>';
       
  1772 	 			}
       
  1773 	 		} ?><br />
       
  1774 	 		</p>
       
  1775 	 	</fieldset>
       
  1776 	 	<fieldset class="box"><legend><?php echo __("Language files:",'xili-language'); ?></legend>
       
  1777 	 	<p>
       
  1778 	 	<?php echo __("Languages sub-folder:",'xili-language').' '.$this->xili_settings['langs_folder']; ?><br />
       
  1779 	 	<?php _e('Available MO files:','xili-language'); echo '<br />';
       
  1780 	 	if ( file_exists( $template_directory ) ) // when theme was unavailable
       
  1781 	 		$this->find_files($template_directory, "/.mo$/", array(&$this,"available_mo_files")) ;
       
  1782 	 	if ( $this->parent->ltd === false )	echo '<br /><span class="red-alert">'.$this->admin_messages['alert']['no_load_function'].'</span>'; 
       
  1783 	 		
       
  1784 	 		?>
       
  1785 	 	</p>
       
  1786 	 	</fieldset>
       
  1787 	<?php
       
  1788 	}
       
  1789 	
       
  1790 	/** 
       
  1791 	 * Actions box 
       
  1792 	 * menu 
       
  1793 	 * gold options 
       
  1794 	 */
       
  1795 	function on_box_expert( $data ) { 
       
  1796 		extract($data);
       
  1797 		$template_directory = $this->get_template_directory;
       
  1798 		if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0
       
  1799 			$theme_name = get_option("stylesheet").' '.__('child of','xili-language').' '.get_option("template"); 
       
  1800 		} else {
       
  1801 			$theme_name = get_option("template"); 
       
  1802 		}
       
  1803 		//$leftboxstyle = 'margin:2px; padding:12px 6px; border:0px solid #ccc; width:45%; float:left;';
       
  1804 		//$rightboxstyle = 'margin:2px 5px 2px 49%; padding:12px 6px; border:1px solid #ccc; width:47%;';
       
  1805 		if ( current_theme_supports( 'menus' ) ) { ?>
       
  1806 		
       
  1807 	 	<fieldset class="box"><legend><?php echo __("Nav menu: Home links in each language",'xili-language'); ?></legend>
       
  1808 	 		<?php 
       
  1809 	 			$menu_locations =  get_nav_menu_locations(); //get_registered_nav_menus() ; // 
       
  1810 	 			//print_r(get_registered_nav_menus());
       
  1811 		 		$selected_menu_locations = ( isset($this->xili_settings['navmenu_check_options'] ) ) ? $this->xili_settings['navmenu_check_options'] : array();
       
  1812 		 	if ( is_array( $menu_locations ) ) {
       
  1813 		 	?>
       
  1814 		 	<fieldset class="box leftbox">
       
  1815 				<p><?php _e('Choose location(s) of nav menu(s) where languages list will be automatically inserted. For each location, choose the type of list. Experts can create their own list by using api (hook) available in plugin.','xili-language'); ?></p>
       
  1816 			</fieldset>
       
  1817 		 	<fieldset class="box rightbox">
       
  1818 			<?php
       
  1819 			if ( $this->this_has_filter('xl_language_list') ) {	// is list of options described
       
  1820 				$this->langs_list_options = array();
       
  1821 				do_action( 'xili_language_list_options', $theoption); // update the list of external action
       
  1822 			}	
       
  1823 			
       
  1824 			foreach ( $menu_locations as $menu_location => $location_id ) { 
       
  1825 				
       
  1826 				$locations_enable = ( isset($selected_menu_locations[$menu_location]) ) ? $selected_menu_locations[$menu_location]['navenable'] : '';
       
  1827 				
       
  1828 				if ( $locations_enable == 'enable' || ( !isset($this->xili_settings['navmenu_check_options'] ) && isset($this->xili_settings['navmenu_check_option']) && $this->xili_settings['navmenu_check_option'] ==  $menu_location ) )
       
  1829 						$checked = 'checked="checked"'; // ascendant compatibility ( !isset($this->xili_settings['navmenu_check_options']) && 
       
  1830 					else 
       
  1831 						$checked = '';
       
  1832 				?>
       
  1833 				<label for="xili_navmenu_check_option_<?php echo $menu_location; ?>" class="selectit"><input id="xili_navmenu_check_option_<?php echo $menu_location; ?>" name="xili_navmenu_check_option_<?php echo $menu_location; ?>" type="checkbox" value="enable"  <?php echo $checked; ?> /> <?php echo $menu_location; ?></label>&nbsp;<?php echo ( 0 != $location_id) ? '-' : '<abbr title="menu location without content" class="red-alert"> (?) </abbr>' ; ?> 
       
  1834 				<label for="xili_navmenu_check_optiontype_<?php echo $menu_location; ?>"><?php _e('Type','xili_language' ) ?>:
       
  1835 				<select name="xili_navmenu_check_optiontype_<?php echo $menu_location; ?>" id="xili_navmenu_check_optiontype_<?php echo $menu_location; ?>">
       
  1836 				<?php
       
  1837 				if ( $this->langs_list_options == array() ) {
       
  1838 						echo '<option value="" >default</option>';
       
  1839 				} else {
       
  1840 					
       
  1841 					foreach ($this->langs_list_options as $typeoption) {
       
  1842 						if ( false !== strpos( $typeoption[0], 'navmenu' ) ) {
       
  1843 							$seltypeoption = ( isset( $this->xili_settings['navmenu_check_options'][$menu_location]['navtype']) ) ? $this->xili_settings['navmenu_check_options'][$menu_location]['navtype'] : "";
       
  1844 							$selectedoption = ($seltypeoption == $typeoption[0]) ? 'selected = "selected"':'';
       
  1845 							echo '<option value="'.$typeoption[0].'" '.$selectedoption.' >'.$typeoption[1].'</option>';
       
  1846 						}
       
  1847 					}
       
  1848 				}
       
  1849 				
       
  1850 				?>
       
  1851 				
       
  1852 				</select></label><br />
       
  1853 				<?php // focus error
       
  1854 			} 
       
  1855 				?>
       
  1856 			</fieldset>
       
  1857 			
       
  1858 			<br />	<br />
       
  1859 	 		<label for="list_in_nav_enable" class="selectit"><input id="list_in_nav_enable" name="list_in_nav_enable" type="checkbox" value="enable"  <?php if($list_in_nav_enable =='enable') echo 'checked="checked"' ?> /> <?php _e('Add list in nav menu', 'xili-language'); ?></label><br />
       
  1860 	 		
       
  1861 	 		<br />
       
  1862 	 		<label for="xili_home_item_nav_menu" class="selectit"><input id="xili_home_item_nav_menu" name="xili_home_item_nav_menu" type="checkbox" value="modify"  <?php if($this->xili_settings['home_item_nav_menu'] =='modify') echo 'checked="checked"' ?> /> <?php _e('Menu Home item with lang.', 'xili-language'); ?></label><br />
       
  1863 	 		<div class="submit"><input  id='innavenable' name='innavenable' type='submit' value="<?php _e('Update','xili-language') ?>" /></div>
       
  1864 	 		<br />
       
  1865 	 		</fieldset>
       
  1866 	 		<br />
       
  1867 	 		<fieldset class="box"><legend><?php echo __("Nav menu: Automatic sub-selection of pages according current language",'xili-language'); ?></legend>
       
  1868 	 			<fieldset class="box leftbox">
       
  1869 					<p><?php _e('Choose location of nav menu where sub-selection of pages list will be automatically inserted according current displayed language:','xili-language'); ?></p>
       
  1870 				</fieldset>
       
  1871 		 		<fieldset class="box rightbox">
       
  1872 	 		
       
  1873 	 		<select name="xili_navmenu_check_optionp" id="xili_navmenu_check_optionp" class="fullwidth">
       
  1874 			<?php	
       
  1875 			foreach ($menu_locations as $menu_location => $location_id) {
       
  1876 				if ( isset( $this->xili_settings['navmenu_check_optionp'] ) && $this->xili_settings['navmenu_check_optionp'] == $menu_location ) 
       
  1877 						$checked = 'selected = "selected"';
       
  1878 					else 
       
  1879 						$checked = '';
       
  1880 				
       
  1881 				echo '<option value="'.$menu_location.'" '.$checked.' >'.$menu_location.'</option>';
       
  1882 			} 
       
  1883 				?>
       
  1884 			</select> 
       
  1885 			<br />	<br />
       
  1886 	 		<label for="page_in_nav_enable" class="selectit"><input id="page_in_nav_enable" name="page_in_nav_enable" type="checkbox" value="enable"  <?php if($page_in_nav_enable =='enable') echo 'checked="checked"' ?> /> <?php _e('Add selection of pages in nav menu', 'xili-language'); ?></label><br /><br />
       
  1887 	 		
       
  1888 	 		<label for="args_page_in_nav" class="selectit"><?php _e('Args', 'xili-language'); ?> : <input id="args_page_in_nav" name="args_page_in_nav" type="text" value="<?php echo $args_page_in_nav ?>"  /> </label>
       
  1889 	 		</fieldset>
       
  1890 		 	<div class="submit"><input  id='pagnavenable' name='pagnavenable' type='submit' value="<?php _e('Update','xili-language') ?>" /></div>
       
  1891 		 	<?php } else {
       
  1892 		 		printf (__("This theme doesn't contain active Nav Menu. List of languages cannot be automatically added.","xili-language"));
       
  1893 		 		echo '<br />';printf (__("See <a href=\"%s\" title=\"Menu Items definition\">Appearance Menus activation</a> settings.","xili-language"), "nav-menus.php");
       
  1894 		 	} ?>
       
  1895 		 	
       
  1896 		</fieldset>
       
  1897 	 	<br /> 	
       
  1898 	 	
       
  1899 	 	<fieldset class="box"><legend><?php echo __("Theme's nav menu items settings",'xili-language'); ?></legend>
       
  1900 		 	<p><?php
       
  1901 		 	if ( $menu_locations ) {
       
  1902 		 		$loc_count = count( $menu_locations ); ?>
       
  1903 		 		<fieldset class="box leftbox">
       
  1904 		 			<?php printf (__("This theme (%s) contains %d Nav Menu(s).",'xili-language'), $theme_name, $loc_count); ?>
       
  1905 		 			<p><?php _e('Choose nav menu where languages list will be manually inserted:','xili-language'); ?></p>
       
  1906 		 		</fieldset>
       
  1907 		 		<fieldset class="box rightbox">
       
  1908 		 		<select name="xili_navmenu_check_option2" id="xili_navmenu_check_option2" class="fullwidth">
       
  1909 				<?php	
       
  1910 					foreach ($menu_locations as $menu_location => $location_id) {
       
  1911 				if ( isset( $this->xili_settings['navmenu_check_option2'] ) && $this->xili_settings['navmenu_check_option2'] == $menu_location ) 
       
  1912 						$checked = 'selected = "selected"';
       
  1913 					else 
       
  1914 						$checked = '';
       
  1915 				
       
  1916 				echo '<option value="'.$menu_location.'" '.$checked.' >'.$menu_location.'</option>';
       
  1917 			}
       
  1918 				?>
       
  1919 			</select>
       
  1920 			<br />	<br />
       
  1921 		 	<?php
       
  1922 		 	echo '<br />';printf (__("See <a href=\"%s\" title=\"Menu Items definition\">Appearance Menus</a> settings.","xili-language"), "nav-menus.php");
       
  1923 		 	if($list_in_nav_enable =='enable') {
       
  1924 		 			echo '<br /><span class="red-alert">'.$this->admin_messages['alert']['menu_auto_inserted'].'</span>'; }
       
  1925 		 	
       
  1926 		 	?>
       
  1927 		 	</p>
       
  1928 		 	</fieldset>
       
  1929 		 	<br /><?php _e('Do you want to add list of language links at the end ?','xili-language'); ?><br />
       
  1930 			<div class="submit"><input  id='menuadditems' name='menuadditems' type='submit' value="<?php _e('Add menu items','xili-language') ?>" /></div>
       
  1931 		 	
       
  1932 		 	<?php } else {
       
  1933 		 		printf (__("This theme doesn't contain active Nav Menu.","xili-language"));
       
  1934 		 		echo '<br />';printf (__("See <a href=\"%s\" title=\"Menu Items definition\">Appearance Menus</a> settings.","xili-language"), "nav-menus.php");
       
  1935 		 	} ?>
       
  1936 	 	</fieldset>
       
  1937 	 	<?php }
       
  1938 	 	
       
  1939 		
       
  1940 		if ( $this->xili_settings['functions_enable'] !='' && function_exists('xiliml_setlang_of_undefined_posts')) {
       
  1941 			?><p><?php _e("Special Gold Actions",'xili-language') ?></p><?php
       
  1942 			xiliml_special_UI_undefined_posts ($this->langs_group_id);
       
  1943 		}
       
  1944 	}
       
  1945 	
       
  1946 	function on_box_mail_content ( $data ) {
       
  1947 		extract( $data );
       
  1948 		global $wp_version ;
       
  1949 		$theme = ( isset ($this->xili_settings['theme']) ) ? $this->xili_settings['theme'] : "";
       
  1950 		$wplang = ( isset ($this->xili_settings['wplang']) ) ? $this->xili_settings['wplang'] : "";
       
  1951 		$xiliplug = ( isset ($this->xili_settings['xiliplug']) ) ? $this->xili_settings['xiliplug'] : "";
       
  1952 		if ( '' != $emessage ) { ?>
       
  1953 	 		<h4><?php _e('Note:','xili-language') ?></h4>
       
  1954 			<p><strong><?php echo $emessage;?></strong></p>
       
  1955 		<?php } ?>
       
  1956 		<fieldset class="mailto"><legend><?php _e('Mail to dev.xiligroup', 'xili-language'); ?></legend><p class="textright">
       
  1957 		<label for="ccmail"><?php _e('Cc: (Reply to:)','xili-language'); ?>
       
  1958 		<input class="widefat width23" id="ccmail" name="ccmail" type="text" value="<?php bloginfo ('admin_email') ; ?>" /></label><br /><br /></p><p class="textleft">
       
  1959 		<?php if ( false === strpos( get_bloginfo ('url'), 'local' ) ){ ?>
       
  1960 			<label for="urlenable">
       
  1961 				<input type="checkbox" id="urlenable" name="urlenable" value="enable" <?php if( isset ($this->xili_settings['url']) && $this->xili_settings['url']=='enable') echo 'checked="checked"' ?> />&nbsp;<?php bloginfo ('url') ; ?>
       
  1962 			</label><br />
       
  1963 		<?php } else { ?>
       
  1964 			<input type="hidden" name="onlocalhost" id="onlocalhost" value="localhost" />
       
  1965 		<?php } ?>
       
  1966 		<label for="themeenable">
       
  1967 			<input type="checkbox" id="themeenable" name="themeenable" value="enable" <?php if( $theme == 'enable' ) echo 'checked="checked"' ?> />&nbsp;<?php echo "Theme name= ".get_option ('stylesheet') ; ?>
       
  1968 		</label><br />
       
  1969 		<?php if (''!= WPLANG ) {?>
       
  1970 		<label for="wplangenable">
       
  1971 			<input type="checkbox" id="wplangenable" name="wplangenable" value="enable" <?php if( $wplang == 'enable' ) echo 'checked="checked"' ?> />&nbsp;<?php echo "WPLANG= ".WPLANG ; ?>
       
  1972 		</label><br />
       
  1973 		<?php } ?>
       
  1974 		<label for="versionenable">
       
  1975 			<input type="checkbox" id="versionenable" name="versionenable" value="enable" <?php if( $this->xili_settings['version']=='enable') echo 'checked="checked"' ?> />&nbsp;<?php echo "WP version: ".$wp_version ; ?>
       
  1976 		</label><br /><br />
       
  1977 		<?php $list = $this->check_other_xili_plugins();
       
  1978 		if (''!= $list ) {?>
       
  1979 		<label for="xiliplugenable">
       
  1980 			<input type="checkbox" id="xiliplugenable" name="xiliplugenable" value="enable" <?php if( $xiliplug == 'enable' ) echo 'checked="checked"' ?> />&nbsp;<?php echo "Other xili plugins = ".$list ; ?>
       
  1981 		</label><br /><br />
       
  1982 		<?php } ?>
       
  1983 		</p><p class="textright">
       
  1984 		<label for="webmestre"><?php _e('Type of webmaster:','xili-language'); ?>
       
  1985 		<select name="webmestre" id="webmestre" class="width23">
       
  1986 			<option value="?" ><?php _e('Define your experience as webmaster…','xili-language'); ?></option>
       
  1987 			<option value="newbie" ><?php _e('Newbie in WP','xili-language'); ?></option>
       
  1988 			<option value="wp-php" ><?php _e('Good knowledge in WP and few in php','xili-language'); ?></option>
       
  1989 			<option value="wp-php-dev" ><?php _e('Good knowledge in WP, CMS and good in php','xili-language'); ?></option>
       
  1990 			<option value="wp-plugin-theme" ><?php _e('WP theme and /or plugin developper','xili-language'); ?></option>
       
  1991 		</select></label><br /><br />
       
  1992 		<label for="subject"><?php _e('Subject:','xili-language'); ?>
       
  1993 		<input class="widefat width23" id="subject" name="subject" type="text" value="" /></label>
       
  1994 		<select name="thema" id="thema" class="width23">
       
  1995 			<option value="" ><?php _e('Choose topic...','xili-language'); ?></option>
       
  1996 			<option value="Message" ><?php _e('Message','xili-language'); ?></option>
       
  1997 			<option value="Question" ><?php _e('Question','xili-language'); ?></option>
       
  1998 			<option value="Encouragement" ><?php _e('Encouragement','xili-language'); ?></option>
       
  1999 			<option value="Support need" ><?php _e('Support need','xili-language'); ?></option>
       
  2000 		</select>
       
  2001 		<textarea class="widefat width45" rows="5" cols="20" id="mailcontent" name="mailcontent"><?php _e('Your message here…','xili-language'); ?></textarea>
       
  2002 		</p></fieldset>
       
  2003 		<p>
       
  2004 		<?php _e('Before send the mail, be accurate, check the infos to inform support and complete textarea. A copy (Cc:) is sent to webmaster email (modify it if needed).','xili-language'); ?>
       
  2005 		</p>
       
  2006 		<div class='submit'>
       
  2007 		<input id='sendmail' name='sendmail' type='submit' tabindex='6' value="<?php _e('Send email','xili-language') ?>" /></div>
       
  2008 		<?php wp_nonce_field('xili-postinpost-sendmail'); ?>
       
  2009 		<div class="clearb1"></div>
       
  2010 		<?php
       
  2011 	}
       
  2012 	
       
  2013 	/**
       
  2014 	 * If checked, functions in uninstall.php will be fired when deleting the plugin via plugins list.
       
  2015 	 *
       
  2016 	 * @since 1.8.8
       
  2017 	 */
       
  2018 	function on_sidebox_uninstall_content ( $data ) {
       
  2019 		extract( $data );
       
  2020 	?>
       
  2021 	<p class="red-alert"><?php echo $this->admin_messages['alert']['plugin_deinstalling']; ?></p>
       
  2022 	<label for="delete_settings">
       
  2023 			<input type="checkbox" id="delete_settings" name="delete_settings" value="delete" <?php if( $this->xili_settings['delete_settings']=='delete') echo 'checked="checked"' ?> />&nbsp;<?php _e("Delete DB plugin's datas",'xili-language') ; ?>
       
  2024 	</label>
       
  2025 	<div class='submit'>
       
  2026 		<input id='uninstalloption' name='uninstalloption' type='submit' tabindex='6' value="<?php _e('Update','xili-language') ?>" /></div>
       
  2027 	<?php
       
  2028 	}
       
  2029 	
       
  2030 	/** 
       
  2031 	 * main setting window 
       
  2032 	 * the list 
       
  2033 	 * clear:none - compat 3.3 - 3.4 
       
  2034 	 */
       
  2035 	function on_box_lang_list_content( $data ) { 
       
  2036 		extract($data); ?>
       
  2037 					<table class="widefat" style="clear:none;">
       
  2038 						<thead>
       
  2039 						<tr>
       
  2040 						<th scope="col" class="head-id" ><?php _e('ID') ?></th>
       
  2041 	        			<th scope="col"><?php _e('ISO Name','xili-language') ?></th>
       
  2042 	        			<th scope="col"><?php _e('Full name','xili-language') ?></th>
       
  2043 	        			<th scope="col"><?php _e('Language slug','xili-language') ?></th>
       
  2044 	        			<th scope="col"><?php _e('Order','xili-language') ?></th>
       
  2045 	        			<th scope="col"><?php _e('Vis.','xili-language') ?></th>
       
  2046 	        			<th scope="col"><?php _e('Dashb.','xili-language') ?></th>
       
  2047 	        			<th scope="col" class="head-count" ><?php _e('Posts') ?></th>
       
  2048 	        			<th scope="col" class="head-action" ><?php _e('Action') ?></th>
       
  2049 						</tr>
       
  2050 						</thead>
       
  2051 						<tbody id="the-list">
       
  2052 							<?php $this->available_languages_row(); /* the lines */ ?>
       
  2053 						</tbody>
       
  2054 					</table>
       
  2055 					<?php if ($action=='edit' || $action=='delete') :?>
       
  2056 					<p>(<a href="?action=add&page=language_page"><?php _e('Add a language','xili-language') ?></a>)</p>
       
  2057 	   				<?php endif; ?>	
       
  2058 	<?php	
       
  2059 	}	
       
  2060 	
       
  2061 	/** 
       
  2062 	 * form to create or edit one language 
       
  2063 	 */
       
  2064 	function on_box_lang_form_content( $data ) { 
       
  2065 		extract($data);
       
  2066 		?>
       
  2067 		
       
  2068 		<h2 id="addlang" <?php if ($action=='delete') echo 'class="red-alert"'; ?>><?php echo $formtitle ;  ?></h2>
       
  2069 		<?php if ($action=='edit' || $action=='delete') :?>
       
  2070 			<input type="hidden" name="language_term_id" value="<?php echo $language->term_id ?>" />
       
  2071 			
       
  2072 		<?php endif; ?>
       
  2073 		<?php if ( $action=='delete') :?>
       
  2074 			
       
  2075 			<input type="hidden" name="language_nicename" value="<?php echo $language->slug ?>" />
       
  2076 		<?php endif; ?>
       
  2077 		<table class="editform" width="100%" cellspacing="2" cellpadding="5">
       
  2078 			<tr>
       
  2079 				<th width="33%" scope="row" valign="middle" align="right"><label for="language_name_list"><?php _e('Examples', 'xili-language') ?></label>:&nbsp;</th>
       
  2080 				<td width="67%"><select name="language_name_list" id="language_name_list">
       
  2081 					<?php $this->example_langs_list($language->name, $action);  ?>
       
  2082 				</select>&nbsp;<small> <a href="http://www.gnu.org/software/hello/manual/gettext/Usual-Language-Codes.html#Usual-Language-Codes" target="_blank"><?php _e('ISO Language-Codes','xili-language'); ?></a></small>&nbsp;_&nbsp;<small><a href="http://www.gnu.org/software/hello/manual/gettext/Country-Codes.html#Country-Codes" target="_blank"><?php _e('ISO Country-Codes','xili-language'); ?></a></small><br />&nbsp;</td>		
       
  2083 			</tr>
       
  2084 			<tr>
       
  2085 				<th scope="row" valign="middle" align="right"><label for="language_name"><?php _e('ISO Name', 'xili-language') ?></label>:&nbsp;</th>
       
  2086 				<td ><input name="language_name" id="language_name" type="text" value="<?php echo esc_attr($language->name); ?>" size="10" <?php if($action=='delete') echo 'disabled="disabled"' ?> />  <small>(<?php printf( __("two or five chars like 'ja' or 'zh_TW', see %s docs", 'xili-language'), '<a href="'.$this->wikilink.'" target="_blank" >wiki</a>'); ?>)</small></td>
       
  2087 			</tr>
       
  2088 			<tr>
       
  2089 				<th scope="row" valign="middle" align="right"><label for="language_nicename"><?php _e('Language slug','xili-language') ?></label>:&nbsp;</th>
       
  2090 				<td><input name="language_nicename" id="language_nicename" type="text" value="<?php echo esc_attr($language->slug); ?>" size="10" <?php if( $action=='delete' ) echo 'disabled="disabled"' ?> /></td>
       
  2091 			</tr>
       
  2092 			<tr>
       
  2093 				<th scope="row" valign="middle" align="right"><label for="language_description"><?php _e('Full name','xili-language') ?></label>:&nbsp;</th>
       
  2094 				<td><input name="language_description" id="language_description" size="20" type="text" value="<?php echo $language->description; ?>" <?php if($action=='delete') echo 'disabled="disabled"' ?> />  <small>(<?php _e('as visible in list or menu: english, chinese', 'xili-language'); ?>,…)</small></td>
       
  2095 				
       
  2096 			</tr>
       
  2097 			<tr>
       
  2098 				<th scope="row" valign="middle" align="right"><label for="language_order"><?php _e('Order','xili-language') ?></label>:&nbsp;</th>
       
  2099 				<td><input name="language_order" id="language_order" size="3" type="text" value="<?php echo $language->term_order; ?>" <?php if( $action=='delete' ) echo 'disabled="disabled"' ?> />&nbsp;&nbsp;&nbsp;<small>
       
  2100 					<label for="language_hidden"><?php _e('hidden','xili-language') ?>&nbsp;<input name="language_hidden" id="language_hidden" type="checkbox" value="hidden" <?php if($action=='delete') echo 'disabled="disabled"' ?> <?php if($language_features['hidden']=='hidden') echo 'checked="checked"' ?> /></label>&nbsp;&nbsp;
       
  2101 					<label for="language_charset"><?php _e('Server Entities Charset:','xili-language') ?>&nbsp;<input name="language_charset" id="language_charset" type="text" value="<?php echo $language_features['charset'] ?>" size="25" <?php if($action=='delete') echo 'disabled="disabled"' ?> /></label></small>
       
  2102 				
       
  2103 				</td>
       
  2104 			</tr>
       
  2105 			<?php if ( $action=='delete' ) :?>
       
  2106 			<tr>
       
  2107 				<th scope="row" valign="top" align="right"><label for="multilingual_links_erase"><span class="red-alert" ><?php echo $this->admin_messages['alert']['erasing_language']; ?></span></label>&nbsp;:&nbsp;</th>
       
  2108 				<td><input name="multilingual_links_erase" id="multilingual_links_erase" type="checkbox" value="erase" /></td>
       
  2109 				
       
  2110 			</tr>
       
  2111 			<?php endif; ?>
       
  2112 			<tr>
       
  2113 			<th><p class="submit"><input type="submit" name="reset" value="<?php echo $cancel_text ?>" /></p></th>
       
  2114 			<td>
       
  2115 			<p class="submit"><input type="submit" name="submit" value="<?php echo $submit_text ?>" /></p>
       
  2116 			</td>
       
  2117 			</tr>
       
  2118 		</table>
       
  2119 	<?php	
       
  2120 	}
       
  2121 	
       
  2122 	/**
       
  2123 	 * private functions for admin page : the language example list
       
  2124 	 * @since 1.6.0
       
  2125 	 */
       
  2126 	function example_langs_list($language_name, $state) {
       
  2127 		
       
  2128 		/* reduce list according present languages in today list */
       
  2129 		if ($state != 'delete' && $state != 'edit') {
       
  2130 			$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
       
  2131 			foreach ($listlanguages as $language) {
       
  2132 			 	if ( array_key_exists($language->name, $this->examples_list))  unset ($this->examples_list[$language->name]);	
       
  2133 			}
       
  2134 		}
       
  2135 		//
       
  2136 		echo '<option value="">'.__('Choose…','xili-language').'</option>';
       
  2137 		foreach($this->examples_list AS $key=>$value) {
       
  2138 			$selected = (''!=$language_name && $language_name == $key) ? 'selected=selected' : '';
       
  2139 			echo '<option value="'.$key.'" '.$selected.'>'.$value.' ('.$key.')</option>';
       
  2140 		}
       
  2141 	}
       
  2142 	
       
  2143 	/**
       
  2144 	 * add styles in options
       
  2145 	 *
       
  2146 	 * @since 2.6
       
  2147 	 *
       
  2148 	 */
       
  2149 	 function print_styles_options_language_page ( ) { // first tab
       
  2150 	 	
       
  2151 	 	echo "<!---- xl options css 1  ----->\n";
       
  2152 		echo '<style type="text/css" media="screen">'."\n";
       
  2153 			echo ".red-alert {color:red;}\n";
       
  2154 			echo ".minwidth {min-width:840px !important ;}\n";
       
  2155 			echo "th.head-id { color:red ; width:60px; }\n";
       
  2156 			echo "th.head-count { text-align: center !important; width: 60px; }\n";
       
  2157 			echo "th.head-action { text-align: center !important; width: 140px; }\n";
       
  2158 			echo ".col-center { text-align: center; }\n";
       
  2159 		 	echo "th.lang-id { font-size:70% !important; }\n";
       
  2160 		 	echo "span.lang-flag { display:inline-block; height: 18px; }\n";
       
  2161 	 	echo "</style>\n";
       
  2162 	 	
       
  2163 	 	if ( $this->exists_style_ext && $this->xili_settings['external_xl_style'] == "on" ) wp_enqueue_style( 'xili_language_stylesheet' );
       
  2164 	 }
       
  2165 	 
       
  2166 	 function print_styles_options_language_tabs ( ) {  // the 2 others tabs
       
  2167 	 	
       
  2168 	 	echo "<!---- xl options css 2 to 3  ----->\n";
       
  2169 		echo '<style type="text/css" media="screen">'."\n";
       
  2170 			echo ".red-alert {color:red;}\n";
       
  2171 			echo ".minwidth {min-width:840px !important ;}\n";
       
  2172 			echo ".fullwidth { width:97%; }\n";
       
  2173 			echo ".width23 { width:70% ; }\n";
       
  2174 			echo ".box { margin:2px; padding:12px 6px; border:1px solid #ccc; } \n";
       
  2175 			echo ".rightbox { margin:2px 5px 2px 49%; width:47%;} \n";
       
  2176 			echo ".leftbox {border:0px; width:45%; float:left;} \n";
       
  2177 			echo ".clearb1 {clear:both; height:1px;} \n";
       
  2178 			echo ".themeinfo {margin:2px 2px 5px; padding:12px 6px; border:1px solid #ccc;} \n";
       
  2179 	 	echo "</style>\n";
       
  2180 	 	
       
  2181 	 	if ( $this->exists_style_ext && $this->xili_settings['external_xl_style'] == "on" ) wp_enqueue_style( 'xili_language_stylesheet' );
       
  2182 	 }
       
  2183 	 
       
  2184 	 function print_styles_options_language_support ( ) {
       
  2185 	 	
       
  2186 	 	echo "<!---- xl options css 4  ----->\n";
       
  2187 	 	echo '<style type="text/css" media="screen">'."\n";
       
  2188 	 		echo ".red-alert {color:red;}\n";
       
  2189 	 		echo ".minwidth {min-width:840px !important;}\n";
       
  2190 	 		echo ".textleft {text-align:left;}\n";
       
  2191 	 		echo ".textright {text-align:right;}\n";
       
  2192 	 		echo ".fullwidth { width:97%; }\n";
       
  2193 	 		echo ".width23 { width:70% !important; }\n";
       
  2194 	 		echo ".width45 { width:80% !important; }\n";
       
  2195 	 		echo ".boldtext {font-size:1.15em;}\n";
       
  2196 	 		echo ".mailto {margin:2px; padding:12px 100px 12px 30px; border:1px solid #ccc; }\n";
       
  2197 	 	echo "</style>\n";
       
  2198 	 	
       
  2199 	 	if ( $this->exists_style_ext && $this->xili_settings['external_xl_style'] == "on" ) wp_enqueue_style( 'xili_language_stylesheet' );
       
  2200 	 }
       
  2201 	
       
  2202 	/**
       
  2203 	 * private functions for admin page : the language list
       
  2204 	 * @since 0.9.0
       
  2205 	 *
       
  2206 	 * @update 0.9.5 : two default languages if taxonomy languages is empty
       
  2207 	 * @update 1.8.8 : fixes slug of defaults
       
  2208 	 * @update 1.8.9.1 : visible = *
       
  2209 	 * @updated 2.6 : style
       
  2210 	 * @updated 2.7.1 : default full name
       
  2211 	 */
       
  2212 	function available_languages_row() { 	
       
  2213 		/*list of languages*/
       
  2214 		$listlanguages = get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC' );
       
  2215 		if ( empty($listlanguages) ) { /*create two default lines with the default language (as in config)*/
       
  2216 		  	/* language of WP */
       
  2217 			$term = 'en_US';
       
  2218 			$args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'en_us');
       
  2219 			$theids = $this->safe_lang_term_creation ( $term, $args );
       
  2220 			if ( ! is_wp_error($theids) ) {
       
  2221 				wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
  2222 			}
       
  2223 		 	$term = $this->default_lang;
       
  2224 		 	$desc = ( isset($this->examples_list[$term]) ) ? $this->examples_list[$term] : $this->default_lang;
       
  2225 		 	$slug = strtolower( $this->default_lang ) ; // 2.3.1
       
  2226 		 	if ( !defined('WPLANG') || $this->default_lang == 'en_US' || $this->default_lang == '' ) {
       
  2227 		 		$term = 'fr_FR'; $desc = 'french'; $slug = 'fr_fr' ;
       
  2228 		 	}
       
  2229 		 	$args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug);
       
  2230 		 	
       
  2231 		 	$theids = $this->safe_lang_term_creation ( $term, $args );
       
  2232 		 	if ( ! is_wp_error($theids) ) {
       
  2233 		 		wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
  2234 		 	}
       
  2235 			$listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
       
  2236 		}
       
  2237 		$trclass = '';
       
  2238 		
       
  2239 		// 1.8.9.1 - update language_features
       
  2240 		 
       
  2241 		$update_features = ( $this->xili_settings['lang_features'] == array() || count($this->xili_settings['lang_features']) != count($listlanguages)  ) ? true : false ; // 2.4
       
  2242 		
       
  2243 		foreach ($listlanguages as $language) {	
       
  2244 			if ( $update_features ) { // create default values
       
  2245 				$slug = $language->slug;
       
  2246 				$this->xili_settings['lang_features'][$slug]['hidden']= "";
       
  2247 				$this->xili_settings['lang_features'][$slug]['charset']= "";
       
  2248 			}
       
  2249 			$trclass = ((defined('DOING_AJAX') && DOING_AJAX) || ' alternate' == $trclass ) ? '' : ' alternate';
       
  2250 			$language->count = number_format_i18n( $language->count );
       
  2251 			$posts_count = ( $language->count > 0 ) ? "<a href='edit.php?lang=$language->slug'>$language->count</a>" : $language->count;	
       
  2252 		
       
  2253 			$edit = "<a href='?action=edit&amp;page=language_page&amp;term_id=".$language->term_id."' >".__( 'Edit' )."</a>&nbsp;|";	
       
  2254 			/* delete link*/
       
  2255 			$edit .= "&nbsp;<a href='?action=delete&amp;page=language_page&amp;term_id=".$language->term_id."' class='delete'>".__( 'Delete' )."</a>";	
       
  2256 			$h = ( isset ( $this->xili_settings['lang_features'][$language->slug]['hidden'] ) && $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden') ? "&nbsp;" : "&#10004;";
       
  2257 			$h .= ( isset ( $this->xili_settings['lang_features'][$language->slug]['charset'] ) && $this->xili_settings['lang_features'][$language->slug]['charset'] != '') ? "&nbsp;+" : "";
       
  2258 			
       
  2259 			$is_mo = ! empty( $language->name ) && array_key_exists( $language->name, (array) $this->available_languages() );
       
  2260 			
       
  2261 			$mo_available_for_dashboard = ( $is_mo ) ? "&#10004;" : "";
       
  2262 			
       
  2263 			$line = '<tr id="lang-'.$language->term_id.'" class="lang-'. $language->slug . $trclass . '" >'
       
  2264 			.'<th scope="row" class="lang-id" ><span class="lang-flag">'.$language->term_id.'<span></th>'
       
  2265 			.'<td>' . $language->name . '</td>'
       
  2266 			.'<td>' . $language->description . '</td>'
       
  2267 			.'<td>' . $language->slug . '</td>'
       
  2268 			.'<td>' . $language->term_order . '</td>'
       
  2269 			.'<td class="col-center" >'. $h . '</td>'
       
  2270 			.'<td class="col-center" >'. $mo_available_for_dashboard . '</td>'
       
  2271 			.'<td class="col-center" >' . $posts_count . '</td>' 
       
  2272 			.'<td class="col-center" >'. $edit . "</td>\n\t</tr>\n"; 
       
  2273 			
       
  2274 			echo $line;
       
  2275 			
       
  2276 		}
       
  2277 		if ( $update_features ) update_option('xili_language_settings', $this->xili_settings);	
       
  2278 	}
       
  2279 	
       
  2280 	/**
       
  2281 	 * Recursive search of files in a path
       
  2282 	 * @since 1.1.9 
       
  2283 	 * @update 1.2.1 - 1.8.5
       
  2284 	 *
       
  2285 	 */
       
  2286 	 function find_files( $path, $pattern, $callback ) {
       
  2287  		//$path = rtrim(str_replace("\\", "/", $path), '/') . '/';
       
  2288  		
       
  2289 		  $matches = Array();
       
  2290 		  $entries = Array();
       
  2291 		  $dir = dir($path);
       
  2292 		  
       
  2293 		  while (false !== ($entry = $dir->read())) {
       
  2294 		    $entries[] = $entry;
       
  2295 		  }
       
  2296 		  $dir->close();
       
  2297 		  foreach ($entries as $entry) {
       
  2298 		    $fullname = $path .$this->ossep. $entry;
       
  2299 		    if ($entry != '.' && $entry != '..' && is_dir($fullname)) {
       
  2300 		      $this->find_files($fullname, $pattern, $callback);
       
  2301 		    } else if (is_file($fullname) && preg_match($pattern, $entry)) {
       
  2302 		      call_user_func($callback, $path , $entry);
       
  2303 		    }
       
  2304 		  }
       
  2305  		
       
  2306 	}
       
  2307 	
       
  2308 	/**
       
  2309 	 * display lines of files in special sidebox
       
  2310 	 * @since 1.1.9
       
  2311 	 * 
       
  2312 	 * @updated 1.8.8
       
  2313 	 */
       
  2314 	function available_mo_files( $path , $filename ) {
       
  2315   		$shortfilename = str_replace(".mo","",$filename );
       
  2316   		$alert = '<span class="red-alert">'.__('Uncommon filename','xili-language').'</span>' ;
       
  2317   		if ( strlen($shortfilename)!=5 && strlen($shortfilename) != 2  ) {
       
  2318   		  if ( false === strpos( $shortfilename, 'local-' ) ) {
       
  2319   		  	$message = $alert;
       
  2320   		  } else {
       
  2321   		  	$message = '<em>'.__("Site's values",'xili-language').'</em>';
       
  2322   		  }
       
  2323   			
       
  2324   		} else if (  false === strpos( $shortfilename, '_' ) && strlen($shortfilename) == 5 )  {
       
  2325   			$message = $alert; 
       
  2326   		} else {
       
  2327   			$message = '';
       
  2328   		}
       
  2329   		  		
       
  2330   		echo $shortfilename. " (".$this->ossep.str_replace($this->ossep,"",str_replace($this->get_template_directory,'',$path)).") ".$message."<br />";
       
  2331 	}
       
  2332 	
       
  2333 	
       
  2334 	/********************************** Edit Post UI ***********************************/
       
  2335 	
       
  2336 	/** 
       
  2337 	 * style for new dashboard
       
  2338 	 * @since 2.5
       
  2339 	 * @updated 2.6
       
  2340 	 */	
       
  2341 	function admin_init () {  
       
  2342 				// test successively style file in theme, plugins, current plugin subfolder
       
  2343 		if ( file_exists ( get_stylesheet_directory().'/xili-css/xl-style.css' ) ) { // in child theme
       
  2344 				$this->exists_style_ext = true; 
       
  2345 				$this->style_folder = get_stylesheet_directory_uri();
       
  2346 				$this->style_flag_folder_path = get_stylesheet_directory () . '/images/flags/';
       
  2347 				$this->style_message = __( 'xl-style.css is in sub-folder <em>xili-css</em> of current theme folder', 'xili-language' );
       
  2348 		} elseif ( file_exists( WP_PLUGIN_DIR . $this->xilidev_folder . '/xili-css/xl-style.css' ) ) { // in plugin xilidev-libraries
       
  2349 				$this->exists_style_ext = true;
       
  2350 				$this->style_folder = plugins_url() . $this->xilidev_folder;
       
  2351 				$this->style_flag_folder_path = WP_PLUGIN_DIR . $this->xilidev_folder . '/xili-css/flags/' ;
       
  2352 				$this->style_message = sprintf( __( 'xl-style.css is in sub-folder <em>xili-css</em> of %s folder', 'xili-language' ), $this->style_folder ); 
       
  2353 		} elseif ( file_exists ( $this->plugin_path.'/xili-css/xl-style.css' ) ) { // in current plugin
       
  2354 				$this->exists_style_ext = true;
       
  2355 				$this->style_folder = $this->plugin_url ;
       
  2356 				$this->style_flag_folder_path = $this->plugin_path . '/xili-css/flags/' ;
       
  2357 				$this->style_message = __( 'xl-style.css is in sub-folder <em>xili-css</em> of xili-language plugin folder (example)', 'xili-language' );
       
  2358 		} else {
       
  2359 				$this->style_message = __( 'no xl-style.css', 'xili-language' );
       
  2360 		}
       
  2361 		if ( $this->exists_style_ext ) wp_register_style( 'xili_language_stylesheet', $this->style_folder . '/xili-css/xl-style.css' );
       
  2362 	}
       
  2363 	
       
  2364 	
       
  2365 	
       
  2366 	/**
       
  2367 	 * Add Translations Dashboard in post edit screen
       
  2368 	 *
       
  2369 	 * @since 2.5
       
  2370 	 *
       
  2371 	 */
       
  2372 	function add_custom_box_in_post_edit () {
       
  2373 		
       
  2374 		$custompoststype = $this->authorized_custom_post_type();
       
  2375 		
       
  2376 		foreach ( $custompoststype as $key => $customtype ) {
       
  2377 			if ( $customtype['multilingual'] == 'enable' ) {
       
  2378 				$plural_name = $customtype['name'] ;  
       
  2379 	 			$singular_name = $customtype['singular_name'] ;
       
  2380 				add_meta_box( 'post_state', sprintf(__("%s of this %s",'xili-language'), __('Translations', 'xili-language'), $singular_name ), array(&$this,'post_state_box'), $key, 'normal', 'high' );
       
  2381 			}
       
  2382 		}
       
  2383 	}
       
  2384 	
       
  2385 	/**
       
  2386 	 * Display content and parts of translations dashboard metabox
       
  2387 	 *
       
  2388 	 * @since 2.5
       
  2389 	 *
       
  2390 	 */
       
  2391 	function post_state_box () {
       
  2392 	  global $post_ID ;
       
  2393 	  ?>
       
  2394 <div id="msg-states">
       
  2395 	  <?php
       
  2396 	  
       
  2397 	    $curlang = $this->post_translation_display ( $post_ID ); 
       
  2398 	  
       
  2399 	  ?>
       
  2400 </div>
       
  2401 <div id="msg-states-comments">
       
  2402 	  <?php
       
  2403 	  $this->post_status_addons ( $post_ID, $curlang );
       
  2404 	 
       
  2405 	  ?>
       
  2406 	<p class="docinfos" ><?php printf(__( 'This list gathers together the titles and infos about (now and future) linked posts by language. For more info, visit the <a href="%s">wiki</a> website.', 'xili-language' ), $this->wikilink) ; ?></p>
       
  2407 	<p class="xlversion">©xili-language v. <?php echo XILILANGUAGE_VER; ?></p>
       
  2408 </div>
       
  2409 <div class="clearb1"></div>
       
  2410 	  <?php
       
  2411 	}
       
  2412 	
       
  2413 	/**
       
  2414 	 * Display main part and list of translation dashboard metabox
       
  2415 	 *
       
  2416 	 * @since 2.5
       
  2417 	 *
       
  2418 	 */
       
  2419 	function post_translation_display ( $post_ID ) {
       
  2420 		global $post ;
       
  2421 		$postlang = '';
       
  2422 		$test = ($post->post_status == 'auto-draft') ? false : true ; 	
       
  2423 		if ($test === true){
       
  2424 			$postlang = $this->get_post_language( $post_ID );
       
  2425 		} else {
       
  2426 			$postlang = ""; /* new post */
       
  2427 		}
       
  2428 		
       
  2429 		$listlanguages = get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC'); 
       
  2430 		
       
  2431 		if ( $this->authorbrowseroption == 'authorbrowser' ) { // setting = select language of author's browser
       
  2432 			$listofprefs = $this->the_preferred_languages();
       
  2433 			if ( is_array( $listofprefs ) ) {
       
  2434 				arsort($listofprefs, SORT_NUMERIC);
       
  2435 				$sitelanguage = $this->match_languages ( $listofprefs, $listlanguages );
       
  2436 				if ( $sitelanguage ) {
       
  2437 					$defaultlanguage = $sitelanguage->slug;
       
  2438 				} else {
       
  2439 					$defaultlanguage = "";
       
  2440 				}	
       
  2441 				$mention = __('Your browser language preset by default for this new post...', 'xili-language') ;
       
  2442 			} else {
       
  2443 				$defaultlanguage = ""; /* undefined */
       
  2444 			}
       
  2445 		} elseif ( $this->authorbrowseroption == 'authordashboard' ) {	
       
  2446 			$current_dash_lang = strtolower( $this->admin_side_locale() );
       
  2447 			if ( isset( $this->langs_slug_name_array[$current_dash_lang]) ) {
       
  2448 				$defaultlanguage = $current_dash_lang;
       
  2449 				$mention = __('Your dashboard language preset by default for this new post...', 'xili-language') ;
       
  2450 			} else {
       
  2451 				$defaultlanguage = ""; /* undefined */
       
  2452 			}	
       
  2453 		} else {
       
  2454 			$defaultlanguage = ""; /* undefined */
       
  2455 			$mention = "";
       
  2456 		}
       
  2457 		$this->authorbrowserlanguage = $defaultlanguage; // for right box
       
  2458 		
       
  2459 		if ( isset ($_GET['xlaction'] ) && isset ($_GET['xllang']) ) {
       
  2460 			// create new translation
       
  2461 			$targetlang = $_GET['xllang'];
       
  2462 			if ( $_GET['xlaction'] == 'transcreate' )
       
  2463 				$translated_post_ID = $this->create_initial_translation ( $targetlang, $post->post_title , $postlang, $post_ID );
       
  2464 			
       
  2465 				if ( $translated_post_ID > 0 && $this->xili_settings['creation_redirect'] == 'redirect') {
       
  2466 					$url_redir = admin_url().'post.php?post='.$translated_post_ID.'&action=edit';
       
  2467 			
       
  2468 				?>
       
  2469    <script type="text/javascript">
       
  2470    <!--
       
  2471       window.location= <?php echo "'" . $url_redir . "'"; ?>;
       
  2472    //-->
       
  2473    </script>
       
  2474 <?php
       
  2475 				}
       
  2476 		} //elseif ( isset ($_GET['xlaction'] ) && $_GET['xlaction'] == 'refresh' ) {
       
  2477 		if ( $postlang != ""  ) {	// refresh only if defined
       
  2478 			foreach ( $listlanguages as $language ) {
       
  2479 				if ( $language->slug != $postlang ) {
       
  2480 					$otherpost = $this->linked_post_in( $post_ID, $language->slug ) ;
       
  2481 					if ( $otherpost ) {
       
  2482 						$linepost = $this->temp_get_post ( $otherpost ); 
       
  2483 						if ( $linepost && $otherpost != $post_ID) { 
       
  2484 							// search metas of target
       
  2485 							$metacurlang = $this->get_cur_language( $linepost->ID ) ; // array
       
  2486 							foreach ( $listlanguages as $metalanguage ) {
       
  2487 								if ( $metalanguage->slug != $postlang && $metalanguage->slug != $metacurlang[QUETAG] ) {
       
  2488 									$id = get_post_meta( $linepost->ID, QUETAG.'-'.$metalanguage->slug, true ); 
       
  2489 									$locid = get_post_meta( $post_ID, QUETAG.'-'.$metalanguage->slug, true ); // do not erase
       
  2490 									if ( $id != "" && $locid =='' && $id != $post_ID ) {
       
  2491 										update_post_meta( $post_ID, QUETAG.'-'.$metalanguage->slug, $id );
       
  2492 									}
       
  2493 								}
       
  2494 								if ( $metalanguage->slug == $postlang ) {
       
  2495 									update_post_meta( $linepost->ID, QUETAG.'-'.$metalanguage->slug, $post_ID );
       
  2496 								}
       
  2497 							}
       
  2498 				
       
  2499 						} else {
       
  2500 							delete_post_meta ( $post_ID,  QUETAG.'-'.$language->slug ); 
       
  2501 						}
       
  2502 					}
       
  2503 				}
       
  2504 			} // for
       
  2505 		}
       
  2506 		if ( isset ($_GET['xlaction'] ) && $_GET['xlaction'] == 'propataxo' ) {
       
  2507 			$this->propagate_categories_to_linked ( $post_ID, $postlang );
       
  2508 		}
       
  2509 		
       
  2510 		
       
  2511 		$post_type = $post->post_type ;
       
  2512 		
       
  2513 		$post_type_object = get_post_type_object( $post_type );
       
  2514 		
       
  2515 		$i = 0;
       
  2516 		// table of languages - asc sorted
       
  2517 		?>
       
  2518 		<table id="postslist" class="widefat">
       
  2519 		<thead>
       
  2520 		<tr><th class="language" ><?php _e('Language','xili-language'); ?></th><th class="postid"><?php _e('ID', 'xili-language'); ?></th><th class="title"><?php _e('Title','xili-language'); ?></th><th class="status" ><?php _e('Status'); ?></th><th class="action" ><?php _e('Edit'); ?></th></tr>
       
  2521 		</thead>
       
  2522 		<tbody id='the-linked' class='postsbody'>
       
  2523 		<?php
       
  2524 		foreach ( $listlanguages as $language ) {
       
  2525 			$otherpost = $this->linked_post_in( $post_ID, $language->slug ) ;
       
  2526 			
       
  2527 			$checkpostlang = ( ''!= $postlang ) ? $postlang : $defaultlanguage ; // according author language
       
  2528 			$checked = ( $checkpostlang == $language->slug ) ? 'checked="checked"' : '';
       
  2529 			
       
  2530 			$creation_edit = ( $this->xili_settings['creation_redirect'] == 'redirect' ) ? __('Create and edit', 'xili-language') : __('Create', 'xili-language');
       
  2531 			
       
  2532 			$tr_class = ' class="lang-'.$language->slug.'" ';
       
  2533 			
       
  2534 			$language_name = '<span class="lang-iso"><abbr class="abbr_name" title="'.$language->description.'">'.$language->name.'</abbr></span>';
       
  2535 			
       
  2536 			$checkline = '<label  title="'.$language->description.'" class="checklang" for="xili_language_check_'.$language->slug.'" class="selectit"></label><input id="xili_language_check_'.$language->slug.'" title="'.$language->description.'" name="xili_language_set" type="radio" value="'.$language->slug .'"  '. $checked.' />&nbsp;&nbsp;'.$language_name ;
       
  2537 			
       
  2538 			$hiddeninput = '<input class="inputid" id="xili_language_'.QUETAG.'-'.$language->slug .'" name="xili_language_'.QUETAG.'-'.$language->slug.'"  value="" /><input type="hidden" name="xili_language_rec_'.QUETAG.'-'.$language->slug.'" value=""/>';
       
  2539 			
       
  2540 			if ( $otherpost && $language->slug !=  $postlang ) {
       
  2541 				$linepost = $this->temp_get_post ( $otherpost );
       
  2542 				
       
  2543 				if ( $linepost ) {
       
  2544 					
       
  2545 					if ( $linepost->post_status == 'trash' ) {
       
  2546 						
       
  2547 						$edit = __( 'uneditable', 'xili-language' );
       
  2548 					} else {
       
  2549 						$edit = sprintf( ' <a href="%s" title="link to:%d">%s</a> ', 'post.php?post='.$otherpost.'&action=edit', $otherpost, __('Edit') );
       
  2550 					}
       
  2551 					
       
  2552 					
       
  2553 					echo '<tr'.$tr_class.'><th  title="'.$language->description.'" >&nbsp;'.$language_name .'</th><td>'.$otherpost.'</td><td>'.$linepost->post_title
       
  2554 					 
       
  2555 					.'</td><td>';
       
  2556 					
       
  2557 					switch ( $linepost->post_status ) {
       
  2558 						case 'private':
       
  2559 							_e('Privately Published');
       
  2560 							break;
       
  2561 							case 'publish':
       
  2562 								_e('Published');
       
  2563 								break;
       
  2564 							case 'future':
       
  2565 								_e('Scheduled');
       
  2566 								break;
       
  2567 							case 'pending':
       
  2568 								_e('Pending Review');
       
  2569 								break;
       
  2570 							case 'trash':
       
  2571 								_ex('Trash' ,'post');
       
  2572 								break;	
       
  2573 							case 'draft':
       
  2574 							case 'auto-draft':
       
  2575 								_e('Draft');
       
  2576 								break;
       
  2577 					}
       
  2578 					
       
  2579 					echo '</td><td>'
       
  2580 					.$edit
       
  2581 					.'</td></tr>';
       
  2582 					
       
  2583 				} else {
       
  2584 					// delete post_meta - not target post
       
  2585 					delete_post_meta ( $post_ID,  QUETAG.'-'.$language->slug );
       
  2586 					$search = '<a class="hide-if-no-js" onclick="findPosts.open( \'lang[]\',\''.$language->slug.'\' );return false;" href="#the-list" title="'.__( 'Search linked post', 'xili-language' ).'"> '.__( 'Search', 'xili-language' ).'</a>';
       
  2587 				
       
  2588 					echo '<tr'.$tr_class.'><th>'.$checkline.'</th><td>'. $hiddeninput.' </td><td>'.__('not yet translated', 'xili-language')
       
  2589 						.'&nbsp;&nbsp;'.sprintf( '<a href="%s" title="%s">'.$creation_edit.'</a>', 'post.php?post='.$post_ID.'&action=edit&xlaction=transcreate&xllang='.$language->slug, sprintf(__('For create a linked draft translation in %s', 'xili-language'), $language->name )  ). '&nbsp;|&nbsp;'.  $search
       
  2590 			 			.'</td><td>&nbsp;</td><td>'. $search 
       
  2591 			 			. '&nbsp;'  
       
  2592 			 			. '</td></tr>';
       
  2593 			 		
       
  2594 				}	
       
  2595 							
       
  2596 			} elseif ( $language->slug ==  $postlang) {
       
  2597 				
       
  2598 				echo '<tr class="editing lang-'.$language->slug.'" ><th>'.$checkline.'</th><td>'.$post_ID.'</td><td>'
       
  2599 				.$post->post_title
       
  2600 			 	.'</td><td>';
       
  2601 			 	switch ( $post->post_status ) {
       
  2602 						case 'private':
       
  2603 							_e('Privately Published');
       
  2604 							break;
       
  2605 							case 'publish':
       
  2606 								_e('Published');
       
  2607 								break;
       
  2608 							case 'future':
       
  2609 								_e('Scheduled');
       
  2610 								break;
       
  2611 							case 'pending':
       
  2612 								_e('Pending Review');
       
  2613 								break;
       
  2614 							case 'trash':
       
  2615 								_e('Trash');
       
  2616 								break;
       
  2617 							case 'draft':
       
  2618 							case 'auto-draft':
       
  2619 								_e('Draft');
       
  2620 								break;
       
  2621 					}
       
  2622 					
       
  2623 			 	echo '</td><td>&nbsp;</td></tr>';
       
  2624 			
       
  2625 			} else { // no linked post
       
  2626 				
       
  2627 				if ( in_array( $post->post_status, array ( 'draft', 'pending', 'future', 'publish', 'private' ) ) && $postlang != '' ) {
       
  2628 				
       
  2629 				$search = '<a class="hide-if-no-js" onclick="findPosts.open( \'lang[]\',\''.$language->slug.'\' );return false;" href="#the-list" title="'.__( 'Search linked post', 'xili-language' ).'"> '.__( 'Search' ).'</a>';
       
  2630 				
       
  2631 				echo '<tr'.$tr_class.'><th>'.$checkline.'</th><td>' . $hiddeninput .'</td><td>'
       
  2632 					. sprintf(__('not yet translated in %s', 'xili-language'), $language->description )
       
  2633 					.'&nbsp;&nbsp;'.sprintf( '<a href="%s" title="%s">'. $creation_edit .'</a>', 'post.php?post='.$post_ID.'&action=edit&xlaction=transcreate&xllang='.$language->slug, sprintf(__('For create a linked draft translation in %s', 'xili-language'), $language->name )  ).'&nbsp;|&nbsp;'.  $search 
       
  2634 			 		.'</td><td>&nbsp;</td><td>'
       
  2635 			 		. '&nbsp;' 
       
  2636 			 		. '</td></tr>';
       
  2637 			 		
       
  2638 				} else {
       
  2639 					
       
  2640 					if ( $defaultlanguage != '' &&  $defaultlanguage == $language->slug ) {	
       
  2641 						// if post-new.php and pre-checked for author's brother
       
  2642 						$the_message = $mention;
       
  2643 						$the_class = ' class="editing lang-'.$defaultlanguage.'"';
       
  2644 					
       
  2645 					} else {
       
  2646 							$the_message = sprintf(__('select language %s !', 'xili-language'), $language->description );
       
  2647 							$the_class = $tr_class;
       
  2648 					}
       
  2649 					
       
  2650 					echo '<tr'.$the_class.'><th>'.$checkline.'</th><td>&nbsp;</td><td>'
       
  2651 						. '<p class="message" ><––––– '.$the_message.'</p>'
       
  2652 						.'</td><td>&nbsp;</td><td>'
       
  2653 						.'&nbsp'
       
  2654 						. '</td></tr>';
       
  2655 				}
       
  2656 			}
       
  2657 		}
       
  2658 		?>
       
  2659 		</tbody>
       
  2660 		</table>
       
  2661 		<div id="ajax-response"></div>
       
  2662 				<?php 
       
  2663 				// ajax form
       
  2664 					$this->xili_find_posts_div('', $post_type, $post_type_object->label);
       
  2665 				?>
       
  2666 		<?php
       
  2667 		return $postlang ;
       
  2668 	}
       
  2669 	
       
  2670 	/**
       
  2671 	 * Display right part of translations dashboard
       
  2672 	 *
       
  2673 	 * @since 2.5
       
  2674 	 *
       
  2675 	 */
       
  2676 	function post_status_addons ( $post_ID, $curlang ) {
       
  2677 		$notundefinedlang = ( $curlang != "" ) ? $curlang : $this->authorbrowserlanguage; // set in left box
       
  2678 		$un_id = ( $curlang == "" ) ? '&nbsp;('. $post_ID .')' : '';
       
  2679 		$refresh = sprintf( '<a href="%s" title="%s">%s</a> ', 'post.php?post='.$post_ID.'&action=edit&xlaction=refresh', __('Refresh links series', 'xili-language'), __('Refresh links', 'xili-language') );
       
  2680 		?>
       
  2681 		<p><?php echo $refresh; ?>
       
  2682 		<?php if ( '' != $curlang && current_user_can ('xili_language_clone_tax') && is_object_in_taxonomy( get_post_type($post_ID), 'category') ) { //2.6.3
       
  2683 			printf( '&nbsp|&nbsp;<a href="%s" title="%s">%s</a> ', 'post.php?post='.$post_ID.'&action=edit&xlaction=propataxo', __('Propagate categories', 'xili-language'), __('Propagate categories', 'xili-language') );
       
  2684 		} ?></p>
       
  2685 		<label for="xili_language_check" class="selectit"><?php _e( 'set post to:', 'xili-language') ?>&nbsp;<input id="xili_language_check" name="xili_language_set" type="radio" value="undefined" <?php if($notundefinedlang=="") echo 'checked="checked"' ?> />&nbsp;<?php _e('undefined','xili-language'); echo $un_id; ?></label>
       
  2686 		<?php
       
  2687 	}
       
  2688 	
       
  2689 	function propagate_categories_to_linked ( $post_ID, $curlang ) {
       
  2690 		
       
  2691 		$listlanguages = $this->get_listlanguages();
       
  2692 		foreach ( $listlanguages as $language ) {
       
  2693 			if ( $language->slug != $curlang ) {
       
  2694 				// get to post
       
  2695 				$otherpost = $this->linked_post_in( $post_ID, $language->slug ) ;
       
  2696 				if ( $otherpost ) {
       
  2697 					$this->propagate_categories ( $post_ID, $otherpost, 'erase' ); 
       
  2698 				}
       
  2699 			}
       
  2700 		}
       
  2701 	}
       
  2702 	
       
  2703 	/** 
       
  2704 	 * scripts for findposts only in post-new and post
       
  2705 	 * @since 2.2.2
       
  2706 	 */	
       
  2707 	function  find_post_script () {
       
  2708 		wp_enqueue_script( 'wp-ajax-response' );
       
  2709 		wp_enqueue_script( 'jquery-ui-draggable' );
       
  2710 		wp_enqueue_script( 'xili-find-post', plugin_dir_url ( $this->file_file ) . 'js/xili-findposts.dev.js','' , XILILANGUAGE_VER );
       
  2711 	}
       
  2712 	
       
  2713 	/**
       
  2714 	 * add styles in edit msg screen
       
  2715 	 *
       
  2716 	 * @since 2.5
       
  2717 	 *
       
  2718 	 */
       
  2719 	 function print_styles_cpt_edit ( ) { 
       
  2720 	 	global $post; 
       
  2721 	 	
       
  2722 	 	$custompoststype = $this->authorized_custom_post_type();
       
  2723 	 	$custompoststype_keys = array_keys ( $custompoststype );
       
  2724 	 	$type = get_post_type( $post->ID );
       
  2725 	 	if ( in_array ( $type , $custompoststype_keys ) && $custompoststype[$type]['multilingual'] == 'enable'  ){
       
  2726 	  		$insert_flags = ( $this->xili_settings['external_xl_style'] == "on" );
       
  2727 		 	echo '<!---- xl css ----->'."\n";
       
  2728 			echo '<style type="text/css" media="screen">'."\n";
       
  2729 		 	echo '#msg-states { width:79%;  float:left; overflow:hidden;}'."\n";
       
  2730 		 	echo '#msg-states-comments { width:18.5%; margin-left: 80%; border-left:0px #666 solid;  padding:10px 10px 0;  }'."\n";
       
  2731 		 	echo '.xlversion {font-size:80%; margin-top:20px; text-align:right;}';
       
  2732 		 	
       
  2733 		 	echo '.alert { color:red;}'."\n";
       
  2734 		 	echo '.message { font-size:80%; color:#bbb !important; font-style:italic; }'."\n";
       
  2735 		 	echo '.editing { color:#333; background:#fffbcc;}'."\n";
       
  2736 		 	echo '.abbr_name:hover {border-bottom:1px dotted grey;}'."\n";
       
  2737 		 	echo '#postslist {width: 100%; border:1px solid grey ;}'."\n";
       
  2738 		 	echo '.language {width: 80px;}'."\n";
       
  2739 		 	echo '.postid {width: 35px;}'."\n";
       
  2740 		 //echo '.title {width: 54%;}';
       
  2741 		 	echo '.status {width: 60px;}'."\n";
       
  2742 		 	echo '.action {width: 120px;}'."\n";
       
  2743 		 //	echo '.postsbody { border:1px solid black; }';
       
  2744 		 	echo '.inputid {width: 40px;}'."\n";
       
  2745 		 	$lang = $this->get_post_language( $post->ID ) ; //slug
       
  2746 		 	if (  $this->style_folder == get_stylesheet_directory_uri() ) {
       
  2747 		 		$folder = $this->style_folder . '/images/flags/' ;
       
  2748 		 	} else {
       
  2749 		 		$folder = $this->style_folder . '/xili-css/flags/' ;
       
  2750 		 	}
       
  2751 		 	if ( $insert_flags && $lang != ''  && file_exists( $this->style_flag_folder_path . $lang .'.png' ) )
       
  2752 		 		echo '#titlewrap input {background : url('. $folder . $lang.'.png' . ') 98.5% center no-repeat !important; }'."\n";
       
  2753 		 	
       
  2754 		 	echo '.postsbody tr > th span { display:inline-block; height: 20px; }'."\n";
       
  2755 		 	$listlanguages = $this->get_listlanguages();
       
  2756 		 	foreach ($listlanguages as $language)  {	
       
  2757 	 			if ( $insert_flags && file_exists( $this->style_flag_folder_path . $language->slug .'.png' ) && $this->xili_settings['external_xl_style'] == "on" ) {
       
  2758 			 		echo '.postsbody tr.lang-'. $language->slug .' > th span { display:inline-block; text-indent:-9999px ; height: 20px; }'."\n";
       
  2759 	 			}
       
  2760 		 	}
       
  2761 		 	
       
  2762 		 	
       
  2763 		 	echo '</style>'."\n";
       
  2764 		 
       
  2765 		 	if ( $this->exists_style_ext && $insert_flags ) wp_enqueue_style( 'xili_language_stylesheet' );
       
  2766 		 
       
  2767 	 	}
       
  2768 	 }
       
  2769 	 
       
  2770 	 /**
       
  2771 	 * Hide language post_meta link
       
  2772 	 * from apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
       
  2773 	 *
       
  2774 	 * @since 2.5
       
  2775 	 */
       
  2776 	function hide_lang_post_meta ( $protected, $meta_key, $meta_type ) {
       
  2777 		if ( $meta_type == 'post' && QUETAG.'-' == substr( $meta_key, 0, strlen(QUETAG) + 1 ) ) {
       
  2778 			$protected = true;
       
  2779 		}
       
  2780 		return $protected;	
       
  2781 	} 
       
  2782 	
       
  2783 	/**
       
  2784 	 * test of tracs http://core.trac.wordpress.org/ticket/18979#comment:2
       
  2785 	 */
       
  2786 	
       
  2787 	function hide_lang_post_meta_popup ( $keys, $limit = 10 ) {
       
  2788 		global $wpdb, $post; 
       
  2789 		$q = "SELECT meta_key FROM $wpdb->postmeta"; 
       
  2790  		$post_type = get_post_type ( $post->ID  ); 
       
  2791  		if ( ! empty( $post_type ) ) 
       
  2792  			$q .= $wpdb->prepare( " INNER JOIN $wpdb->posts ON post_id = ID WHERE post_type LIKE %s", $post_type ); 
       
  2793  	  
       
  2794  	 	$q .= " GROUP BY meta_key HAVING ( meta_key NOT LIKE '\_%' AND meta_key NOT LIKE '" . QUETAG . "-%' )  ORDER BY meta_key LIMIT $limit"; 
       
  2795  	  	$keys = $wpdb->get_col( $q ); 
       
  2796 	 	//$keys = apply_filters( 'postmeta_form_keys', $keys, $post_type );
       
  2797 	 	if ( $keys )
       
  2798 			natcasesort($keys);
       
  2799 		return $keys;
       
  2800 	}	
       
  2801 	
       
  2802 	/**
       
  2803 	 * set language when post or page is saved or changed 
       
  2804 	 *
       
  2805 	 * @since 0.9.0
       
  2806 	 * @completed 0.9.7.1 to record postmeta of linked posts in other languages
       
  2807 	 * @updated 0.9.7.5 to delete relationship when undefined
       
  2808 	 * @updated 0.9.9 to avoid delete relationship when in quick_edit
       
  2809 	 * @updated 1.3.0 to avoid delete relationship when trashing - 1.4.1 - create post-meta xl-search-linked
       
  2810 	 * @updated 1.8.9.3 for bulk edit...
       
  2811 	 *
       
  2812 	 * @updated 2.5, 2.6
       
  2813 	 * 
       
  2814 	 * @param $post_ID
       
  2815 	 */
       
  2816 	function xili_language_add( $post_ID, $post ) { 
       
  2817 		
       
  2818 		$posttypes = array_keys( $this->xili_settings['multilingual_custom_post'] );
       
  2819 		$posttypes[] = 'post';
       
  2820 		$posttypes[] = 'page';
       
  2821 		$thetype = $post->post_type; 
       
  2822 		if ( in_array ( $thetype, $posttypes ) ) { 
       
  2823 			if ( isset($_POST['_inline_edit']) ) { /* when in quick_edit (edit.php) */
       
  2824 				
       
  2825 				$sellang = $_POST['xlpop'];
       
  2826 				if ( "" != $sellang ) {
       
  2827 					wp_set_object_terms( $post_ID, $sellang, TAXONAME );
       
  2828 				} else {
       
  2829 					if ( $_GET['action'] != 'trash' && $_GET['action'] != 'untrash' )
       
  2830 							wp_delete_object_term_relationships( $post_ID, TAXONAME ); 	
       
  2831 				}
       
  2832 				
       
  2833 			} else if ( isset( $_GET['bulk_edit']) ) { // bulk_edit 
       
  2834 					 	
       
  2835 			 	$sellang = $_GET['xlpop'];
       
  2836 				if ( "-1" != $sellang && "*" != $sellang) {
       
  2837 					
       
  2838 					wp_set_object_terms( $post_ID, $sellang, TAXONAME );
       
  2839 				} else if ( "*" == $sellang )  {
       
  2840 					if ( $_GET['action'] != 'trash' && $_GET['action'] != 'untrash' )
       
  2841 							wp_delete_object_term_relationships( $post_ID, TAXONAME ); 	
       
  2842 				}
       
  2843 			 	
       
  2844 			} else {	
       
  2845 			
       
  2846 				$listlanguages = $this->get_listlanguages () ;
       
  2847 				
       
  2848 				$previous_lang = $this->get_post_language ( $post_ID ) ;
       
  2849 				
       
  2850 				$sellang = ( isset ( $_POST['xili_language_set'] )) ? $_POST['xili_language_set'] : "" ;
       
  2851 				if ( "" != $sellang && "undefined" != $sellang ) {
       
  2852 					if ( $sellang != $previous_lang && $previous_lang != '' ) {
       
  2853 						// move a language
       
  2854 						// clean linked targets
       
  2855 						foreach ($listlanguages as $language) {
       
  2856 						
       
  2857 							$target_id = get_post_meta( $post_ID, QUETAG.'-'.$language->slug, true );
       
  2858 							if ( $target_id != "" ) {
       
  2859 								delete_post_meta( $target_id, QUETAG.'-'.$previous_lang );
       
  2860 								update_post_meta( $target_id, QUETAG.'-'.$sellang, $post_ID  );
       
  2861 							}
       
  2862 						}
       
  2863 						wp_delete_object_term_relationships( $post_ID, TAXONAME );
       
  2864 					} 
       
  2865 					wp_set_object_terms($post_ID, $sellang, TAXONAME);
       
  2866 				} elseif (  "undefined" == $sellang ) {
       
  2867 					
       
  2868 					// clean linked targets
       
  2869 					foreach ($listlanguages as $language) {
       
  2870 						
       
  2871 						$target_id = get_post_meta( $post_ID, QUETAG.'-'.$language->slug, true );
       
  2872 						if ( $target_id != "" ) {
       
  2873 							delete_post_meta( $target_id, QUETAG.'-'.$previous_lang );
       
  2874 						}
       
  2875 					}
       
  2876 					// now undefined
       
  2877 					wp_delete_object_term_relationships( $post_ID, TAXONAME );
       
  2878 				}
       
  2879 				
       
  2880 				$curlang = $this->get_cur_language( $post_ID ) ; // array
       
  2881 				
       
  2882 					
       
  2883 				/* the linked posts set by author in postmeta */	
       
  2884 				
       
  2885 				foreach ($listlanguages as $language) {
       
  2886 					$inputid = 'xili_language_'.QUETAG.'-'.$language->slug ;
       
  2887 					$recinputid = 'xili_language_rec_'.QUETAG.'-'.$language->slug ;
       
  2888 					$linkid = ( isset ( $_POST[$inputid] ) ) ? $_POST[$inputid] : 0 ;
       
  2889 					$reclinkid = ( isset ( $_POST[$recinputid] ) ) ? $_POST[$recinputid] : 0 ; /* hidden previous value */
       
  2890 					$langslug = QUETAG.'-'.$language->slug ;
       
  2891 					
       
  2892 					if ( $reclinkid != $linkid ) { /* only if changed value or created since 1.3.0 */			
       
  2893 						if ((is_numeric($linkid) && $linkid == 0) || '' == $linkid ) {
       
  2894 							delete_post_meta($post_ID, $langslug);
       
  2895 						} elseif ( is_numeric( $linkid ) && $linkid > 0 ) {
       
  2896 							// test if possible 2.5.1 
       
  2897 							if ( $this->is_post_free_for_link ( $post_ID, $curlang[QUETAG], $language->slug, $linkid ) ) {
       
  2898 								update_post_meta( $post_ID, $langslug, $linkid);
       
  2899 							
       
  2900 								if ($reclinkid == "-1")	update_post_meta( $linkid, QUETAG.'-'.$sellang, $post_ID); 
       
  2901 								
       
  2902 								// update target 2.5
       
  2903 								foreach ($listlanguages as $metalanguage) {
       
  2904 									if ( $metalanguage->slug != $language->slug && $metalanguage->slug != $curlang[QUETAG] ) {
       
  2905 										$id = get_post_meta( $post_ID, QUETAG.'-'.$metalanguage->slug, true );
       
  2906 										if ( $id != "" ) {
       
  2907 											update_post_meta( $linkid, QUETAG.'-'.$metalanguage->slug, $id );
       
  2908 										}
       
  2909 									}
       
  2910 								}
       
  2911 								update_post_meta( $linkid, QUETAG.'-'.$curlang[QUETAG], $post_ID ); // cur post
       
  2912 								wp_set_object_terms( $linkid, $language->slug, TAXONAME );
       
  2913 							}
       
  2914 						}
       
  2915 					}	
       
  2916 				}
       
  2917 			}
       
  2918 		}	
       
  2919 	}
       
  2920 	
       
  2921 	/**
       
  2922 	 * add to secure manual input of linked post
       
  2923 	 *
       
  2924 	 * @since 2.5.1
       
  2925 	 *
       
  2926 	 */
       
  2927 	
       
  2928 	function is_post_free_for_link ( $from_post_ID, $from_lang, $target_lang, $target_ID ) {
       
  2929 		
       
  2930 		if ( $from_post_ID == $target_ID ) return false ; // obvious
       
  2931 		
       
  2932 		if ( $this->temp_get_post ( $target_ID ) ) {
       
  2933 			// check if target ID is not yet in another lang
       
  2934 			$target_slug = $this->get_post_language ( $target_ID ) ;
       
  2935 			if ( $target_slug == '' ) { 
       
  2936 				return true; // undefined
       
  2937 			} elseif (  $target_slug == $target_lang ) {
       
  2938 				// check target is not yet link to other
       
  2939 				$id = get_post_meta( $target_ID, QUETAG.'-'.$from_lang, true );	
       
  2940 				if ( $id != "" ) { 
       
  2941 					return false; // yet linked
       
  2942 				} else {
       
  2943 					return true;
       
  2944 				}
       
  2945 				
       
  2946 			} else {
       
  2947 				return false; // yet another language
       
  2948 			}
       
  2949 		
       
  2950 		} else {
       
  2951 			return false; // no target
       
  2952 		}
       
  2953 		
       
  2954 	}
       
  2955 	
       
  2956 	/**
       
  2957 	 * if post created by dashboard, when first saved by author, fixes post_name for permalinks use
       
  2958 	 *
       
  2959 	 * @since 2.5
       
  2960 	 *
       
  2961 	 */
       
  2962 	function fixes_post_slug ( $post_id, $post ) {
       
  2963 		$state = get_post_meta( $post_id, $this->translation_state, true );
       
  2964 		if (  $state == "initial" ) {
       
  2965 			global $wpdb;
       
  2966     		if ( defined ( 'XDMSG' ) && get_post_type( $post_id ) == XDMSG ) return;
       
  2967     		
       
  2968     		$where = array( 'ID' => $post_id );
       
  2969         	$what = array ();
       
  2970         	
       
  2971         	$what['post_name'] = sanitize_title($post->post_title);
       
  2972         	
       
  2973         	if ( $what != array() ) 
       
  2974         			$wpdb->update( $wpdb->posts, $what, $where );
       
  2975     	
       
  2976 			delete_post_meta( $post_id, $this->translation_state );
       
  2977 		}
       
  2978 	}
       
  2979 	
       
  2980 	/**
       
  2981 	 * inspired by find_posts_div from wp-admin/includes/template.php
       
  2982 	 *
       
  2983 	 * @since 2.3.1 to restrict to type of post
       
  2984 	 *
       
  2985 	 * @param unknown_type $found_action
       
  2986 	 */
       
  2987 	function xili_find_posts_div($found_action = '', $post_type, $post_label ) {
       
  2988 
       
  2989 	?>
       
  2990 		<div id="find-posts" class="find-box" style="display:none;">
       
  2991 			<div id="find-posts-head" class="find-box-head"><?php printf( __( 'Find %s','xili-language' ), $post_label ) ; ?></div>
       
  2992 			<div class="find-box-inside">
       
  2993 				<div class="find-box-search">
       
  2994 					<?php if ( $found_action ) { ?>
       
  2995 						<input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
       
  2996 					<?php } ?>
       
  2997 	
       
  2998 					<input type="hidden" name="affected" id="affected" value="" />
       
  2999 					<?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
       
  3000 					<label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
       
  3001 					<input type="text" id="find-posts-input" name="ps" value="" />
       
  3002 					<input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
       
  3003 					<?php /* checks replaced by hidden - see js findposts*/ ?>
       
  3004 					<input type="hidden" name="find-posts-what" id="find-posts-what" value="<?php echo esc_attr($post_type); ?>" />
       
  3005 					
       
  3006 				</div>
       
  3007 				<div id="find-posts-response"></div>
       
  3008 			</div>
       
  3009 			<div class="find-box-buttons">
       
  3010 				<input id="find-posts-close" type="button" class="button alignleft" value="<?php esc_attr_e('Close'); ?>" />
       
  3011 				<?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
       
  3012 			</div>
       
  3013 		</div>
       
  3014 	<?php
       
  3015 	}
       
  3016 	
       
  3017 	/**************** Attachment post language  *******************/
       
  3018 	
       
  3019 	function add_language_attachment_fields ($form_fields, $post) {
       
  3020 		$attachment_id = $post->ID; 
       
  3021 		
       
  3022 		// get list of languages for popup
       
  3023 		$attachment_post_language = get_cur_language( $attachment_id, 'slug' );
       
  3024 		
       
  3025 		$listlanguages = $this->get_listlanguages () ;
       
  3026 		// get_language
       
  3027 		if ( '' != $attachment_post_language ) { // impossible to change if assigned
       
  3028 			$name = $this->langs_slug_name_array[$attachment_post_language];
       
  3029 			$fullname = $this->langs_slug_fullname_array[$attachment_post_language];
       
  3030 			$form_fields['attachment_post_language'] = array(
       
  3031 				'label'      => __('Language', 'xili-language'),
       
  3032 				'input'      => 'html',
       
  3033 				'html'       =>  "<strong>$fullname</strong> ($name)<input type='hidden' name='attachments[$attachment_id][attachment_post_language]' value='" . $attachment_post_language . "' /><br />", 
       
  3034 				'helps'      => __('Language of the file caption and description.', 'xili-language')
       
  3035 			);
       
  3036 			
       
  3037 		} else { // selector
       
  3038 			
       
  3039 			$html_input = '<select name="attachments['.$attachment_id.'][attachment_post_language]" ><option value="undefined">'.__('Choose…','xili-language').'</option>';
       
  3040 			foreach ($listlanguages as $language) {
       
  3041 				$selected = (''!=$attachment_post_language && $language->slug == $attachment_post_language) ? 'selected=selected' : '';
       
  3042 				$html_input .= '<option value="'.$language->slug.'" '.$selected.'>'.$language->description.' ('.$language->name.')</option>';		
       
  3043 			}
       
  3044 			$html_input .= '</select>';
       
  3045 				
       
  3046 			$form_fields['attachment_post_language'] = array(
       
  3047 				'label'      => __('Language', 'xili-language'),
       
  3048 				'input'      => 'html',
       
  3049 				'html'       =>  $html_input, 
       
  3050 				'helps'      => __('Language of the file caption and description.', 'xili-language')
       
  3051 			);
       
  3052 		}
       
  3053 		
       
  3054 		//error_log ( '---------'.serialize ( get_current_screen() ));
       
  3055 		
       
  3056 		if ( '' != $attachment_post_language && get_current_screen()->base == "media" ) { // only in media edit not in media-upload 
       
  3057 			
       
  3058 			$result = $this->translated_in ( $attachment_id, 'link', 'attachment' );
       
  3059 			$trans = $this->translated_in ( $attachment_id, 'array');
       
  3060 			
       
  3061 			if ( $result == '' ) {
       
  3062 				$html_input = __('not yet translated', 'xili-language') ;
       
  3063 			} else {
       
  3064 				$html_input = __('Title, Caption and description are translated in', 'xili-language');
       
  3065 				$html_input .= '&nbsp;<span class="translated-in">' . $result .'</span>'; 	
       
  3066 			}
       
  3067 			
       
  3068 			$html_input .= '<br /><select name="attachments['.$attachment_id.'][create_clone_attachment_with_language]" ><option value="undefined">'.__('Select…','xili-language').'</option>';
       
  3069 			foreach ($listlanguages as $language) {
       
  3070 				if ( $language->slug != $attachment_post_language && !isset ($trans[$language->slug] )) {
       
  3071 					$selected = '' ; //(''!=$attachment_post_language && $language->slug == $attachment_post_language) ? 'selected=selected' : '';
       
  3072 					$html_input .= '<option value="'.$language->slug.'" '.$selected.'>'.$language->description.' ('.$language->name.')</option>';	
       
  3073 				}	
       
  3074 			}
       
  3075 			$html_input .= '</select>';
       
  3076 			$form_fields['create_clone_attachment_with_language'] = array(
       
  3077 				'label'      => __('Create clone in language', 'xili-language'),
       
  3078 				'input'      => 'html',
       
  3079 				'html'       =>  $html_input, 
       
  3080 				'helps'      => __('Selection of the language of a linked cloned attachment (with same file).', 'xili-language')
       
  3081 			);
       
  3082 		}
       
  3083 		
       
  3084 		return $form_fields ;
       
  3085 	}
       
  3086 	
       
  3087 	// attachment_fields_to_save apply_filters('attachment_fields_to_save', $post, $attachment);
       
  3088 	
       
  3089 	function set_attachment_fields_to_save ( $post, $attachment ) {
       
  3090 		global $wpdb;
       
  3091 		
       
  3092 		if ( isset($attachment['attachment_post_language']) ){
       
  3093 			if ( $attachment['attachment_post_language'] != '' && $attachment['attachment_post_language'] != 'undefined' ) {
       
  3094 				wp_set_object_terms($post['ID'], $attachment['attachment_post_language'], TAXONAME);
       
  3095 			} else {
       
  3096 				wp_delete_object_term_relationships( $post['ID'], TAXONAME );
       
  3097 			}	
       
  3098 		}
       
  3099 		$clone = $post;
       
  3100 		unset ($clone['ID']);	
       
  3101 		if ( isset($attachment['create_clone_attachment_with_language']) && $attachment['create_clone_attachment_with_language'] != 'undefined' ){
       
  3102 			
       
  3103 			$clone['post_title'] = sprintf(__('Translate in %2$s: %1$s', 'xili-language'),$clone['post_title'], $attachment['create_clone_attachment_with_language'] );
       
  3104 			$parent_id = $clone['post_parent'];
       
  3105 			$linked_parent_id = xl_get_linked_post_in ( $parent_id, $attachment['create_clone_attachment_with_language'] );
       
  3106 			$clone['post_parent'] = $linked_parent_id; // 0 if unknown linked id of parent in assigned language
       
  3107 			
       
  3108 			$cloned_attachment_id = wp_insert_post( $clone );
       
  3109 			// clone post_meta
       
  3110 			$data = get_post_meta( $post['ID'], '_wp_attachment_metadata', true );
       
  3111 			$data_file = get_post_meta( $post['ID'], '_wp_attached_file', true );
       
  3112 			$data_alt = get_post_meta( $post['ID'], '_wp_attachment_image_alt', true );
       
  3113 			update_post_meta( $cloned_attachment_id, '_wp_attachment_metadata', $data);
       
  3114 			update_post_meta( $cloned_attachment_id, '_wp_attached_file', $data_file);
       
  3115 			if ( '' != $data_alt ) update_post_meta( $cloned_attachment_id, '_wp_attachment_image_alt', $data_alt);
       
  3116 			// set language and links of cloned of current
       
  3117 			update_post_meta( $cloned_attachment_id, QUETAG.'-'.$attachment['attachment_post_language'], $post['ID'] ); 
       
  3118 			wp_set_object_terms( $cloned_attachment_id, $attachment['create_clone_attachment_with_language'], TAXONAME );
       
  3119 			
       
  3120 			// get already linked of cloned
       
  3121 			$already_linked = array();
       
  3122 			if ( $meta_values = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value, meta_key FROM $wpdb->postmeta WHERE meta_key LIKE %s AND post_id = %d", QUETAG .'-' . '%', $post['ID']) ) ) {
       
  3123 				//error_log( serialize ( $meta_values ) );
       
  3124 				
       
  3125 				foreach ( $meta_values as $key_val ) {
       
  3126 					update_post_meta( $key_val->meta_value, QUETAG.'-'.$attachment['create_clone_attachment_with_language'], $cloned_attachment_id );
       
  3127 					$slug = str_replace( QUETAG.'-', '', $key_val->meta_key );
       
  3128 					$already_linked[$slug] = $key_val->meta_value;  
       
  3129 				}
       
  3130 			}
       
  3131 			// set links of current to cloned
       
  3132 			update_post_meta( $post['ID'], QUETAG.'-'.$attachment['create_clone_attachment_with_language'], $cloned_attachment_id );
       
  3133 			if ( $already_linked != array() ) {
       
  3134 				foreach ( $already_linked as $key => $id ) {
       
  3135 					update_post_meta( $post['ID'], QUETAG.'-'.$key, $id );
       
  3136 					if ( $key != $attachment['create_clone_attachment_with_language'] ) update_post_meta( $cloned_attachment_id, QUETAG.'-'.$key, $id );
       
  3137 				}
       
  3138 			}
       
  3139 		}
       
  3140 		
       
  3141 		return $post;
       
  3142 	}
       
  3143 	// called before deleting attachment by do_action( 'delete_attachment'
       
  3144 	function if_cloned_attachment ( $post_id ) {
       
  3145 		global $wpdb;
       
  3146 		if ( $post = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id) ) ) {		   
       
  3147 		
       
  3148 			if ( 'attachment' == $post->post_type ) {
       
  3149 				$attachment_post_language = get_cur_language( $post_id, 'slug' );
       
  3150 				// test meta lang
       
  3151 				$linked_list = $this->translated_in ( $post_id, 'array'); //error_log (serialize($linked_list));
       
  3152 				if ( array()  != $linked_list ) {
       
  3153 					$this->dont_delete_file = true;
       
  3154 					// update meta in linked attachments
       
  3155 					foreach ( $linked_list as $lang_slug => $linked_id ) {
       
  3156 						delete_post_meta ( $linked_id,  QUETAG.'-'.$attachment_post_language );
       
  3157 					}
       
  3158 				} else {
       
  3159 					$this->dont_delete_file = false;
       
  3160 				}
       
  3161 			}
       
  3162 		}
       
  3163 	}
       
  3164 	
       
  3165 	// called before deleting file by apply_filters( 'wp_delete_file'
       
  3166 	function if_file_cloned_attachment ( $file ) {
       
  3167 		if ( $this->dont_delete_file == true ) $file = '';
       
  3168 		return $file;
       
  3169 	}
       
  3170 	
       
  3171 	
       
  3172 	/**************** List of Posts (edit.php)  *******************/ 
       
  3173 	
       
  3174 	/** 
       
  3175 	 * display languages column name in Posts/Pages list
       
  3176 	 *
       
  3177 	 * @updated 1.8.9
       
  3178 	 */
       
  3179 	function xili_manage_column_name( $cols ) {
       
  3180 		global $wp_query; // 2.8.1
       
  3181 		
       
  3182 		if ( defined ('XDMSG') ) $CPTs = array( XDMSG );
       
  3183 		$CPTs[] = 'page';
       
  3184 		$CPTs[] = 'post';
       
  3185 		
       
  3186 		$custompoststype = $this->xili_settings['multilingual_custom_post'] ;
       
  3187  		if ( $custompoststype != array()) {
       
  3188 			foreach ( $custompoststype as $key => $customtype ) {
       
  3189  				if ( $customtype['multilingual'] == 'enable' ) {
       
  3190  					$CPTs[] = $key;	
       
  3191  				}
       
  3192 			}
       
  3193  		}
       
  3194  		$post_type = ( isset ( $wp_query->query_vars['post_type' ] ) ) ?  $wp_query->query_vars['post_type' ] : '' ;
       
  3195 		// post no cpt
       
  3196 		if ( in_array ( $post_type, $CPTs)  )   {
       
  3197 			
       
  3198 			$ends = apply_filters ( 'xiliml_manage_column_name', array( 'comments', 'date', 'rel', 'visible'), $cols, $post_type ); // 2.8.1
       
  3199 			$end = array();
       
  3200 			foreach( $cols AS $k=>$v ) {
       
  3201 				if ( in_array($k, $ends) ) {
       
  3202 					$end[$k] = $v;
       
  3203 					unset($cols[$k]);
       
  3204 				}
       
  3205 			}
       
  3206 			$cols[TAXONAME] = __('Language','xili-language');
       
  3207 			$cols = array_merge($cols, $end);
       
  3208 		}
       
  3209 		return $cols;
       
  3210 	}
       
  3211 		
       
  3212 	/** 
       
  3213 	 * display languages column in Posts/Pages list
       
  3214 	 *
       
  3215 	 * @updated 1.8.9
       
  3216 	 */
       
  3217 	function xili_manage_column( $name, $id ) {
       
  3218 		global $wp_query; // 2.8.1
       
  3219 		if( $name != TAXONAME )
       
  3220 			return;
       
  3221 		$output = '';	
       
  3222 		$terms = wp_get_object_terms( $id, TAXONAME );
       
  3223 		$first = true;
       
  3224 		foreach( $terms AS $term ) {
       
  3225 			if ( $first )
       
  3226 				$first = false;
       
  3227 			else
       
  3228 				$output .= ', ';
       
  3229 				
       
  3230 			if ( current_user_can ('activate_plugins') ) {	
       
  3231 				$output .= '<span class="curlang lang-'. $term->slug .'"><a href="' . 'options-general.php?page=language_page'.'" title="'.sprintf(__('Post in %s. Link to see list of languages…','xili-language'), $term->description ) .'" >'; /* see more precise link ?*/
       
  3232 				$output .= $term->name .'</a></span>';
       
  3233 			} else {
       
  3234 				$output .= '<span title="'. sprintf(__('Post in %s.','xili-language'), $term->description ) .'" class="curlang lang-'. $term->slug .'">' . $term->name . '</span>' ;
       
  3235 			}
       
  3236 			
       
  3237 			$output .= '<input type="hidden" id="'.QUETAG.'-'.$id.'" value="'.$term->slug.'" >'; // for Quick-Edit - 1.8.9
       
  3238 		}
       
  3239 		$xdmsg = ( defined ('XDMSG') ) ? XDMSG : '' ;
       
  3240 		
       
  3241 		
       
  3242 		$post_type = ( isset ( $wp_query->query_vars['post_type' ] ) ) ?  $wp_query->query_vars['post_type' ] : '' ; 
       
  3243 		
       
  3244 		if (  $post_type != $xdmsg  )  {  // no for XDMSG
       
  3245 			$output .= '<br />';
       
  3246 		
       
  3247 			$result = $this->translated_in ( $id );
       
  3248 		
       
  3249 			$output .= apply_filters ( 'xiliml_language_translated_in_column', $this->display_translated_in_result ( $result ), $result, $post_type );
       
  3250 		}
       
  3251 		echo $output; // called by do_action() class wp_posts_list_table
       
  3252 	}
       
  3253 	
       
  3254 	function display_translated_in_result ( $result ) {
       
  3255 		$output = "";
       
  3256 		if ( $result == '' ) {
       
  3257 			$output .= __('not yet translated', 'xili-language') ;
       
  3258 		} else {
       
  3259 			$output .= __('translated in:', 'xili-language') ;
       
  3260 			$output .= '&nbsp;<span class="translated-in">' . $result .'</span>'; 	
       
  3261 		}
       
  3262 		return $output;
       
  3263 	}
       
  3264 	
       
  3265 		
       
  3266 	/**
       
  3267 	 * Return list of linked posts 
       
  3268 	 * used in edit list
       
  3269 	 * 
       
  3270 	 * @param: mode = array to customize list 
       
  3271 	 * @since 2.5
       
  3272 	 *
       
  3273 	 */
       
  3274 	function translated_in ( $post_ID, $mode = 'link', $type = 'post' ) {
       
  3275 		
       
  3276 		$curlang = $this->get_cur_language( $post_ID ) ; // array
       
  3277 		$listlanguages = $this->get_listlanguages () ;
       
  3278 		$trans = array();
       
  3279 			foreach ( $listlanguages as $language ) {
       
  3280 				if ( $language->slug != $curlang[QUETAG] ) {
       
  3281 					$otherpost = $this->linked_post_in( $post_ID, $language->slug ) ;
       
  3282 					if ( $otherpost ) {
       
  3283 						$linepost = $this->temp_get_post ( $otherpost ); 
       
  3284 						if ( $linepost ) { 
       
  3285 							switch ( $mode ) {
       
  3286 								case 'link' :
       
  3287 									if ( $type == 'post' ) {
       
  3288 										$link = 'post.php?post='.$linepost->ID.'&action=edit';
       
  3289 									} elseif ( $type == 'attachment') {
       
  3290 										$link = 'media.php?attachment_id='.$linepost->ID.'&action=edit';
       
  3291 									}
       
  3292 									
       
  3293 									$title = sprintf ( __( 'link to edit %s %d in %s', 'xili-language' ), $type, $linepost->ID, $language->description );
       
  3294 									$trans[] = sprintf( __('<a href="%1$s" title="%2$s" class="lang-%4$s" >%3$s</a>','xili-language'), $link, $title, $language->name, $language->slug );
       
  3295 								break;
       
  3296 								case 'array' :
       
  3297 									$trans[$language->slug] = array ( 'post_ID'=>$linepost->ID, 'name'=>$language->name, 'description'=>$language->description );
       
  3298 								break;
       
  3299 							
       
  3300 							}
       
  3301 						}
       
  3302 					}
       
  3303 				}
       
  3304 			}
       
  3305 		
       
  3306 		if ( $mode == 'array' ) return $trans;
       
  3307 			
       
  3308 		$list = implode (' ', $trans ) ;
       
  3309 		return $list;
       
  3310 	}
       
  3311 	
       
  3312 	/**
       
  3313 	 * style for posts (and categories) list
       
  3314 	 * 
       
  3315 	 *
       
  3316 	 */
       
  3317 	function print_styles_posts_list () {
       
  3318 		
       
  3319 	 	if ( get_current_screen()->base == "upload" )
       
  3320 		 		$this->insert_news_pointer ( 'media_language' ); // 2.6.3
       
  3321 	 	
       
  3322 	   $insert_flags = ( $this->xili_settings['external_xl_style'] == "on" );
       
  3323 	   echo "<!---- xl css --->\n";
       
  3324 	   echo '<style type="text/css" media="screen">'."\n";
       
  3325 	   		echo ".langquickedit { background: #E4EAF8; padding:0 5px 4px !important; border:1px solid #ccc; width:140px !important; float:right !important;}\n";
       
  3326 	   		echo ".toppost { margin: 0 20px 2px 7px; }  \n";
       
  3327 	   		echo ".toppage { margin: -40px 20px 2px 7px; } \n";
       
  3328 	   		echo "span.curlang a { display:inline-block; font-size:80%; height:18px; width:60px; } \n";
       
  3329 	   		$listlanguages = $this->get_listlanguages();
       
  3330 	   		
       
  3331 	   		if (  $this->style_folder == get_stylesheet_directory_uri() ) {
       
  3332 	 			$folder_url = $this->style_folder . '/images/flags/' ;
       
  3333 	 		} else {
       
  3334 	 			$folder_url = $this->style_folder . '/xili-css/flags/' ;
       
  3335 	 		}
       
  3336 	   		
       
  3337 	   		foreach ($listlanguages as $language)  {
       
  3338 	   			
       
  3339 	 			if ( $insert_flags && file_exists( $this->style_flag_folder_path . $language->slug .'.png' ) ) {
       
  3340 	 				echo "span.lang-". $language->slug ." { background: url(". $folder_url . $language->slug .'.png' .") no-repeat 0% center } \n";
       
  3341 	 				echo "span.curlang.lang-" . $language->slug ." a { color:#f5f5f5; text-indent:-9999px ;}\n";
       
  3342 	 				
       
  3343 	 				if ( class_exists( 'xili_tidy_tags' ) ) {
       
  3344 	 					echo "div#xtt-edit-tag span.curlang.lang-" . $language->slug ." { margin-left:5px; color:#f5f5f5; display:inline-block; height:18px; width:25px; text-indent:-9999px ; }\n";
       
  3345 	 				
       
  3346 	 				}
       
  3347 	 				
       
  3348 	 			} else {
       
  3349 	 				echo "span.curlang.lang-" . $language->slug ." a { font-size:100%; text-align: left; }\n";
       
  3350 	 			}
       
  3351 	   		}
       
  3352 	   echo "</style>\n";
       
  3353 	   
       
  3354 	   if ( $this->exists_style_ext && $this->xili_settings['external_xl_style'] == "on" ) wp_enqueue_style( 'xili_language_stylesheet' );
       
  3355 	}
       
  3356 	
       
  3357 	/**
       
  3358 	 * Insert popup in quickedit at end (filter quick_edit_custom_box - template.php)
       
  3359 	 *
       
  3360 	 * @since 1.8.9
       
  3361 	 *
       
  3362 	 * hook with only two params - no $post_id - populated by.. || $type != 'post' || $type != 'page'
       
  3363 	 * 
       
  3364 	 */
       
  3365 	function languages_custom_box ( $col, $type ) {
       
  3366 		if ( 'edit-tags' == $type ) 
       
  3367 			return;
       
  3368 		if( $col != TAXONAME ) 
       
  3369           return;
       
  3370     	
       
  3371     	$listlanguages = $this->get_listlanguages();
       
  3372     	$margintop = ($type == 'page' ) ? 'toppage' : 'toppost';
       
  3373 		?>
       
  3374 		
       
  3375 		<fieldset class="langquickedit <?php echo $margintop; ?>" ><legend><em><?php _e('Language','xili-language') ?></em></legend>
       
  3376 			<select name="xlpop" id="xlpop">
       
  3377 			<option value=""> <?php _e('undefined','xili-language') ?> </option>
       
  3378 			<?php foreach ($listlanguages as $language)  {
       
  3379 				echo '<option value="'.$language->slug.'">'.__($language->description, 'xili-language').'</option>';
       
  3380 			// no preset values now (see below)	
       
  3381 			}
       
  3382 			?>
       
  3383 			</select>
       
  3384 		</fieldset>
       
  3385 		
       
  3386 		
       
  3387 	<?php
       
  3388 	}
       
  3389 	
       
  3390 	/**
       
  3391 	 * workaround for insert value popup in quickedit
       
  3392 	 *
       
  3393 	 * @since 1.8.9
       
  3394 	 * keep value in hidden input in column see xili_manage_column
       
  3395 	 * setTimeout mandatory for popup DOM - adapted from http://nerdlife.net/boston-wordpress-meetup-example-code/
       
  3396 	 *
       
  3397 	 */
       
  3398 	function quick_edit_add_script () {
       
  3399 		?>
       
  3400 		<script type="text/javascript">
       
  3401 			jQuery(document).ready(function() {
       
  3402     			jQuery('a.editinline').live('click', function() {
       
  3403        			var id = inlineEditPost.getId(this);
       
  3404         		if ( jQuery('#<?php echo QUETAG ?>-' + id ).length ) {
       
  3405         			var val = jQuery('#<?php echo QUETAG ?>-' + id ).val();
       
  3406         			 
       
  3407         			 setTimeout( 'jQuery("#xlpop").val("'+val+'")',.1);
       
  3408         			 
       
  3409         		}
       
  3410     			});
       
  3411     			
       
  3412 			});
       
  3413 		</script>
       
  3414 		<?php 
       
  3415 	}
       
  3416 	
       
  3417 	
       
  3418 	/**
       
  3419 	 * Insert popup in BULK quickedit at end (filter bulk_edit_custom_box - template.php)
       
  3420 	 *
       
  3421 	 * @since 1.8.9.3
       
  3422 	 *
       
  3423 	 * hook with only two params - no $post_id - populated by.. || $type != 'post' || $type != 'page'
       
  3424 	 * 
       
  3425 	 */
       
  3426 	 function hidden_languages_custom_box ( $col, $type ) { 
       
  3427 		if( $col != TAXONAME ) {
       
  3428          return;
       
  3429     	} 
       
  3430     	$listlanguages = $this->get_listlanguages();
       
  3431     	$margintop = ($type == 'page' ) ? '-40px' : '0';
       
  3432 		?>
       
  3433 		
       
  3434 		<label class="alignright">
       
  3435 			<span class="title"><?php _e( 'Language','xili-language' ); ?></span>
       
  3436 			<select name="xlpop" id="xlpop">
       
  3437 			<option value="-1"> <?php _e('&mdash; No Change &mdash;') ?> </option>
       
  3438 			<option value="*"> <?php _e('undefined','xili-language') ?> </option>
       
  3439 			<?php foreach ($listlanguages as $language)  {
       
  3440 				echo '<option value="'.$language->slug.'">'.__($language->description, 'xili-language').'</option>';
       
  3441 			// no preset values now (see below)	
       
  3442 			}
       
  3443 			?>
       
  3444 			</select>
       
  3445 		</label>
       
  3446 	<?php
       
  3447 	}
       
  3448 	
       
  3449 	/**
       
  3450 	 * Add Languages selector in edit.php edit after Category Selector (hook: restrict_manage_posts)
       
  3451 	 *
       
  3452 	 * @since 1.8.9
       
  3453 	 *
       
  3454 	 */
       
  3455 	function restrict_manage_languages_posts () {
       
  3456 		$listlanguages = $this->get_listlanguages();
       
  3457 		?>
       
  3458 		<select name="<?php echo QUETAG ?>" id="<?php echo QUETAG ?>" class='postform'>
       
  3459 			<option value=""> <?php _e('View all languages','xili-language') ?> </option>
       
  3460 			
       
  3461 			<option value="<?php echo LANG_UNDEF ?>" <?php echo ( isset ( $_GET[QUETAG] ) && $_GET[QUETAG] == LANG_UNDEF ) ? "selected=selected" : "" ; ?> > <?php _e('Without language','xili-language') ?> </option>
       
  3462 			
       
  3463 			<?php foreach ($listlanguages as $language)  {
       
  3464 				$selected = ( isset ( $_GET[QUETAG] ) && $language->slug == $_GET[QUETAG] ) ? "selected=selected" : "" ;
       
  3465 				echo '<option value="'.$language->slug.'" '.$selected.' >'.__($language->description, 'xili-language').'</option>';
       
  3466 			}
       
  3467 			?>
       
  3468 			</select>
       
  3469 		<?php
       
  3470 	}
       
  3471 	
       
  3472 /******************************* TAXONOMIES ****************************/	
       
  3473 	
       
  3474 	function xili_manage_tax_column_name ( $cols ) {
       
  3475 		
       
  3476 		$ends = array('posts');
       
  3477 		$end = array();
       
  3478 		foreach( $cols AS $k=>$v ) {
       
  3479 			if(in_array($k, $ends)) {
       
  3480 				$end[$k] = $v;
       
  3481 				unset($cols[$k]);
       
  3482 			}
       
  3483 		}
       
  3484 		$cols[TAXONAME] = __('Language','xili-language');
       
  3485 		$cols = array_merge($cols, $end);
       
  3486 		
       
  3487 		
       
  3488 		$this->local_theme_mos = $this->get_localmos_from_theme() ;
       
  3489 		
       
  3490 		return $cols;
       
  3491 	}
       
  3492 	
       
  3493 	function xili_manage_tax_column ( $content, $name, $id ) {
       
  3494 		if( $name != TAXONAME )
       
  3495 			return $content; // to have more than one added column 2.8.1
       
  3496 		
       
  3497 		global $taxonomy ;
       
  3498 		$tax = get_term((int)$id , $taxonomy ) ;
       
  3499 		$a = '<div class="taxinmos" >';
       
  3500 		$a .= __( 'translated in:', 'xili-language' )." ";
       
  3501 		
       
  3502 		$res = $this->is_msg_saved_in_localmos ( $tax->name, 'msgid' );
       
  3503 		
       
  3504 		$a .= $res[0];
       
  3505 		$a .= '</div>';	
       
  3506 	  	return $content.$a; // 2.8.1 - to have more than one filter for this column ! #21222 comments...
       
  3507 	}
       
  3508 	
       
  3509 	function xili_manage_tax_action ( $actions, $tag ) {
       
  3510 		return $actions;
       
  3511 	}
       
  3512 	
       
  3513 	function show_translation_msgstr ( $tag, $taxonomy ) {
       
  3514 		
       
  3515 		?>
       
  3516 		<tr class="form-field">
       
  3517 			<th scope="row" valign="top"><label for="description"><?php _e('Translated in', 'xili-language'); ?></label></th>
       
  3518 			<td>
       
  3519 			<?php
       
  3520 			echo '<fieldset class="taxinmos" ><legend>'.__('Name').'</legend>';
       
  3521 			$a = $this->is_msg_saved_in_localmos ( $tag->name, 'msgid', '', 'single' ); echo $a[0];
       
  3522 			
       
  3523 			if ( class_exists('xili_dictionary' ) && current_user_can ('xili_dictionary_set')) {
       
  3524 				$link = admin_url().'/edit.php?s='.str_replace (' ', '+', $tag->name ).'&post_status=all&post_type=xdmsg&action=-1&m=0&lang&writer_name=0&paged=1&action2=-1';
       
  3525 			
       
  3526 				printf( '<a href="%1$s" title="%2$s" >%3$s</a>', $link, __('Link to edit translations', 'xili-language') , __('Edit translations', 'xili-language') );
       
  3527 			}
       
  3528 			
       
  3529 			echo '</fieldset><br /><fieldset class="taxinmos" ><legend>'.__('Description').'</legend>';
       
  3530 			$a = $this->is_msg_saved_in_localmos ( $tag->description, 'msgid', '', 'single' ); echo $a[0];
       
  3531 			
       
  3532 			if ( class_exists('xili_dictionary' ) && current_user_can ('xili_dictionary_set')) {
       
  3533 				$link = admin_url().'/edit.php?s='.str_replace (' ', '+', $tag->description ).'&post_status=all&post_type=xdmsg&action=-1&m=0&lang&writer_name=0&paged=1&action2=-1';
       
  3534 			
       
  3535 				printf( '<a href="%1$s" title="%2$s" >%3$s</a>', $link, __('Link to edit translations', 'xili-language') , __('Edit translations', 'xili-language') );
       
  3536 			}
       
  3537 			
       
  3538 			echo '</fieldset>';
       
  3539 			
       
  3540 			
       
  3541 			?>
       
  3542 			<p><em><?php _e( 'This list above gathers the translations of name and description saved in current local-xx_XX.mo files of the current theme.', 'xili-language'); ?></em></p>
       
  3543 			</td>
       
  3544 		</tr>
       
  3545 		
       
  3546 		<?php
       
  3547 	}
       
  3548 	
       
  3549 	function update_xd_msgid_list ( $taxonomy ) {
       
  3550 		if ( class_exists ('xili_dictionary') ) {
       
  3551 			global $xili_dictionary;
       
  3552 			$nbterms = $xili_dictionary->xili_read_catsterms_cpt( $taxonomy, $xili_dictionary->local_tag );
       
  3553 			if ( $nbterms != array( 0, 0) ) 
       
  3554 				echo '<p>' . sprintf( __( 'xili-dictionary: msgid list updated (n=%1s, d=%2s', 'xili-dictionary' ), $nbterms[0], $nbterms[1] ) . ')</p>';	
       
  3555 		} else {
       
  3556 			echo '<p><strong>' . __( 'xili-dictionary plugin is not active to prepare language local .po files.', 'xili-dictionary' ). '</strong></p>';
       
  3557 		}
       
  3558 	}
       
  3559 	
       
  3560 	
       
  3561 /******************************* MO TOOLS FOR TAXONOMIES AND LOCAL VALUES ****************************/	
       
  3562 	
       
  3563 	/**
       
  3564 	 * test if line is in entries
       
  3565 	 * @since 2.6.0
       
  3566 	 */
       
  3567 	function is_msg_in_entries ( $msg, $type, $entries, $context ) {
       
  3568 		foreach ($entries as $entry) {
       
  3569 			$diff = 1;
       
  3570 			switch ( $type ) {
       
  3571 		 		case 'msgid' :
       
  3572 		 			$diff = strcmp( $msg , $entry->singular );
       
  3573 		 			if ( $context != "" ) {
       
  3574 		 				if ( $entry->context != null ) {
       
  3575 		 					$diff += strcmp( $context , $entry->context ); 
       
  3576 		 				}
       
  3577 		 			}
       
  3578 					break;
       
  3579 				case 'msgid_plural' :
       
  3580 					$diff = strcmp( $msg , $entry->plural );
       
  3581 					break;	
       
  3582 				case 'msgstr' :
       
  3583 				 if ( isset ( $entry->translations[0] ) )
       
  3584 					$diff = strcmp( $msg , $entry->translations[0] );
       
  3585 					break;
       
  3586 				default:
       
  3587 					if ( false !== strpos ( $type, 'msgstr_'  ) ) {
       
  3588 						$indice = (int) substr ( $type, -1) ;
       
  3589 						if ( isset ( $entry->translations[$indice] ) )
       
  3590 							$diff = strcmp( $msg , $entry->translations[$indice] );
       
  3591 					}
       
  3592 			}
       
  3593 			
       
  3594 			//if ( $diff != 0) { echo $msg.' i= '.strlen($msg); echo $entry->singular.') e= '.strlen($entry->singular); }
       
  3595 			if ( $diff == 0) return true;
       
  3596 		}	
       
  3597 	return false;
       
  3598 	}
       
  3599 	
       
  3600 	function get_msg_in_entries ( $msg, $type, $entries, $context ) {
       
  3601 		foreach ($entries as $entry) {
       
  3602 			$diff = 1;
       
  3603 			switch ( $type ) {
       
  3604 		 		case 'msgid' :
       
  3605 		 			$diff = strcmp( $msg , $entry->singular );
       
  3606 		 			if ( $context != "" ) {
       
  3607 		 				if ( $entry->context != null ) {
       
  3608 		 					$diff += strcmp( $context , $entry->context ); 
       
  3609 		 				}
       
  3610 		 			} 
       
  3611 					break;
       
  3612 				case 'msgid_plural' :
       
  3613 					$diff = strcmp( $msg , $entry->plural );
       
  3614 					break;	
       
  3615 				case 'msgstr' :
       
  3616 				 if ( isset ( $entry->translations[0] ) )
       
  3617 					$diff = strcmp( $msg , $entry->translations[0] );
       
  3618 					break;
       
  3619 				default:
       
  3620 					if ( false !== strpos ( $type, 'msgstr_'  ) ) {
       
  3621 						$indice = (int) substr ( $type, -1) ;
       
  3622 						if ( isset ( $entry->translations[$indice] ) )
       
  3623 							$diff = strcmp( $msg , $entry->translations[$indice] );
       
  3624 					}
       
  3625 			}
       
  3626 			
       
  3627 			//if ( $diff != 0) { echo $msg.' i= '.strlen($msg); echo $entry->singular.') e= '.strlen($entry->singular); }
       
  3628 			if ( $diff == 0) {
       
  3629 				if ( isset ( $entry->translations[0] ) ) {
       
  3630 					return array( 'msgid' => $entry->singular , 'msgstr' => $entry->translations[0] );
       
  3631 				} else {
       
  3632 					return array() ;
       
  3633 				}
       
  3634 			}
       
  3635 		}	
       
  3636 	return array() ;
       
  3637 	}
       
  3638 	
       
  3639 	
       
  3640 	/**
       
  3641 	 * Detect if cpt are saved in theme's languages folder
       
  3642 	 * @since 2.0
       
  3643 	 * 
       
  3644 	 */
       
  3645 	function is_msg_saved_in_localmos ( $msg, $type, $context = "", $mode = "list" ) {
       
  3646 		$thelist = array();
       
  3647 		$thelistsite = array();
       
  3648 		$outputsite = "";
       
  3649 		$output = "";
       
  3650 		
       
  3651 			$listlanguages = $this->get_listlanguages();
       
  3652 			
       
  3653 		 	foreach ($listlanguages as $reflanguage) {
       
  3654 		 		if ( isset($this->local_theme_mos[$reflanguage->slug]) ) { 
       
  3655 		 			if ( $mode == "list"  && $this->is_msg_in_entries ( $msg, $type, $this->local_theme_mos[$reflanguage->slug], $context ) ) {
       
  3656 		 				$thelist[] = '<span class="lang-'. $reflanguage->slug .'" >'. $reflanguage->name .'</span>';
       
  3657 		 			} else if ( $mode == "single" ) {
       
  3658 		 				$res = $this->get_msg_in_entries ( $msg, $type, $this->local_theme_mos[$reflanguage->slug], $context ) ;
       
  3659 		 				if ( $res != array () ) 
       
  3660 		 					$thelist[$reflanguage->name] = $res ;
       
  3661 		 			}		 							 			
       
  3662 		 		}
       
  3663 		 		
       
  3664 		 		if ( is_multisite() ) {
       
  3665 		 			if ( isset($this->local_site_mos[$reflanguage->slug]) ) { 
       
  3666 		 				if ( $this->is_msg_in_entries ( $msg, $type, $this->local_site_mos[$reflanguage->slug], $context ) )
       
  3667 		 					$thelistsite[] = '<span class="lang-'. $reflanguage->slug .'" >'. $reflanguage->name .'</span>';		 							 			
       
  3668 		 			}
       
  3669 		 		}
       
  3670 		 		
       
  3671 		 	}
       
  3672 		 	
       
  3673 		 	if ( $mode == "list" ) {
       
  3674 		 	
       
  3675 			$output = ($thelist == array()) ? '<br /><small><span style="color:black" title="'.__("No translations saved in theme's .mo files","xili-dictionary").'">**</span></small>' : '<br /><small><span style="color:green" title="'.__("Original with translations saved in theme's files: ","xili-dictionary").'" >'. implode(' ',$thelist).'</small></small>';
       
  3676 			
       
  3677 			if ( is_multisite() ) {
       
  3678 				
       
  3679 				$outputsite = ($thelistsite == array()) ? '<br /><small><span style="color:black" title="'.__("No translations saved in site's .mo files","xili-dictionary").'">**</span></small>' : '<br /><small><span style="color:green" title="'.__("Original with translations saved in site's files: ","xili-dictionary").'" >'. implode(', ',$thelistsite).'</small></small>';
       
  3680 				
       
  3681 			}
       
  3682 			
       
  3683 		 	} else if ( $mode == "single" ) {
       
  3684 		 		
       
  3685 		 		if  ($thelist == array()) {
       
  3686 		 			
       
  3687 		 			$output = __('Not yet translated in any language','xili-language') .'<br />';
       
  3688 		 		} else {
       
  3689 		 			$output = '';
       
  3690 		 			foreach ( $thelist as $key => $msg ) {
       
  3691 		 				
       
  3692 		 				$output .=  '<span class="lang-'. strtolower ( $key ) .'" >' . $key . '</span> : ' . $msg['msgstr'] . '<br />';
       
  3693 		 			}
       
  3694 		 		}
       
  3695 		 	}
       
  3696 			
       
  3697 			return array ( $output, $outputsite ) ;
       
  3698 		
       
  3699 	}
       
  3700 	
       
  3701 	/** 
       
  3702 	 * create an array of local mos content of theme 	
       
  3703 	 *
       
  3704 	 * @since 2.6.0
       
  3705 	 */
       
  3706 	 function get_localmos_from_theme() {
       
  3707 	 	$local_theme_mos = array();
       
  3708 	 	
       
  3709 	 		$listlanguages = $this->get_listlanguages();
       
  3710 	 		
       
  3711 	 		if ( is_multisite() ) {
       
  3712 	 			if ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) {
       
  3713 					$folder = $uploads['basedir']."/languages";
       
  3714 	 			}
       
  3715 	 		}
       
  3716 	 		
       
  3717 	 		foreach ( $listlanguages as $reflanguage ) {
       
  3718 	 			if ( is_multisite() ) {
       
  3719 	 				$folder_file = $folder . '/local-' . $reflanguage->name . '.mo';
       
  3720 	 			} else {
       
  3721 	 				$folder_file = '';
       
  3722 	 			}
       
  3723 	 			
       
  3724 	     		$res = $this->pomo_import_MO ( $reflanguage->name, $folder_file, true ); // local only
       
  3725 	     		if ( false !== $res ) $local_theme_mos[$reflanguage->slug] = $res->entries;
       
  3726 	 		}
       
  3727 	 	
       
  3728 	 	return $local_theme_mos;	
       
  3729 	 }	
       
  3730 	
       
  3731 	/**
       
  3732 	 * Import MO file in class PO 
       
  3733 	 *
       
  3734 	 *
       
  3735 	 * @since 1.0.2 - only WP >= 2.8.4
       
  3736 	 * @updated 1.0.5 - for wpmu
       
  3737 	 * @param lang
       
  3738 	 * @param $mofile since 1.0.5
       
  3739 	 */
       
  3740 	function pomo_import_MO ( $lang = "", $mofile = "", $local = false ) {
       
  3741 		$mo = new MO();
       
  3742 		
       
  3743 		if ( $mofile == "" &&  $local == true ) {
       
  3744 			$mofile = $this->get_template_directory.$this->xili_settings['langs_folder'] .'/'.'local-'.$lang.'.mo';
       
  3745 		} else if ( '' == $mofile ) {
       
  3746 			$mofile = $this->get_template_directory.$this->xili_settings['langs_folder'] .'/'.$lang.'.mo';
       
  3747 		}
       
  3748 		
       
  3749 		if ( file_exists($mofile) ) {
       
  3750 			if ( !$mo->import_from_file( $mofile ) ) {
       
  3751 				return false;
       
  3752 			} else { 
       
  3753 				
       
  3754 				return $mo;
       
  3755 			}
       
  3756 		} else {
       
  3757 			return false;
       
  3758 		}
       
  3759 	}
       
  3760 	
       
  3761 /******************************* LINKS ****************************/
       
  3762 	
       
  3763 	/**
       
  3764 	 * @updated 1.8.0 
       
  3765 	 */
       
  3766 	function add_custom_box_in_link() {
       
  3767 		
       
  3768  		add_action( 'add_meta_boxes_link', array( &$this,'new_box' ) );
       
  3769 	}
       
  3770 	
       
  3771 	
       
  3772 
       
  3773 	/**
       
  3774 	 * Box, action and function to set language in edit-link-form
       
  3775 	 * @ since 1.8.5
       
  3776 	 */
       
  3777 	function new_box () {
       
  3778 		add_meta_box('linklanguagediv', __("Link's language","xili-language"), array(&$this,'link_language_meta_box'), 'link', 'side', 'core');
       
  3779 	}
       
  3780 	
       
  3781 	function link_language_meta_box( $link) {
       
  3782 		
       
  3783 		$theid = '['.$link->link_id.'] '; 
       
  3784 		$ress = wp_get_object_terms($link->link_id, 'link_'.TAXONAME);
       
  3785 		$curlangname = ""; 
       
  3786 		if ( $ress ) {
       
  3787 			$obj_term = $ress[0];
       
  3788 			if ( '' != $obj_term->name ) :
       
  3789 				$curlangname = $obj_term->name;
       
  3790 			endif;
       
  3791 		}
       
  3792 		
       
  3793 		echo '<h4>'.__('Check the language for this link','xili-language').'</h4><div style="line-height:1.7em;">';
       
  3794 		// built the check series with saved check if edit
       
  3795 		$listlanguages = get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC' );
       
  3796 		$l = 2;
       
  3797 		foreach ( $listlanguages as $language ) { 
       
  3798 			if ( $l % 3 == 0 && $l != 3) { echo '<br />'; }
       
  3799 			?> 
       
  3800 		
       
  3801 				<label class="check-lang selectit" for="xili_language_check_<?php echo $language->slug ; ?>"><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 _e($language->description, 'xili-language'); ?></label>
       
  3802 			  
       
  3803 				<?php } /*link to top of sidebar*/?> 
       
  3804 				<br /><label class="check-lang selectit" for="xili_language_check" ><input id="xili_language_check_ever" name="xili_language_set" type="radio" value="ev_er" <?php if($curlangname=="ev_er") echo 'checked="checked"' ?> /> <?php _e('Ever','xili-language') ?></label>
       
  3805 				<label class="check-lang selectit" for="xili_language_check" ><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 /></div>
       
  3806 			  	<br /><small>© xili-language <?php echo XILILANGUAGE_VER; ?></small>
       
  3807 		<?php
       
  3808 		
       
  3809 	}
       
  3810 	
       
  3811 	function print_styles_link_edit () {
       
  3812 		echo "<!---- xl options css links  ----->\n";
       
  3813 	 	echo '<style type="text/css" media="screen">'."\n";
       
  3814 	 		echo ".check-lang { border:solid 1px grey; margin:1px 0px; padding:3px 4px; width:45%; display:inline-block; }\n";
       
  3815 	 	echo "</style>\n";
       
  3816 	 	
       
  3817 	 	if ( $this->exists_style_ext && $this->xili_settings['external_xl_style'] == "on" ) wp_enqueue_style( 'xili_language_stylesheet' );
       
  3818 	}
       
  3819 	
       
  3820 	/**
       
  3821 	 * Action and filter to add language column in link-manager page
       
  3822 	 * @ since 1.8.5
       
  3823 	 */
       
  3824 	
       
  3825 	
       
  3826 	function xili_manage_link_column_name ( $cols ) {
       
  3827 				$ends = array('rel', 'visible', 'rating'); // insert language before rel
       
  3828 				$end = array();
       
  3829 				foreach($cols AS $k=>$v) {
       
  3830 					if(in_array($k, $ends)) {
       
  3831 						$end[$k] = $v;
       
  3832 						unset($cols[$k]);
       
  3833 					}
       
  3834 				}
       
  3835 				$cols[TAXONAME] = __('Language','xili-language');
       
  3836 				$cols = array_merge($cols, $end);
       
  3837 				return $cols;
       
  3838 	} 
       
  3839 	 
       
  3840 	function manage_link_lang_column ( $column_name, $link_id ) {
       
  3841 		
       
  3842 		if ( $column_name != TAXONAME )
       
  3843 					return;
       
  3844 		$ress = wp_get_object_terms($link_id, 'link_'.TAXONAME);
       
  3845 		if ( $ress ) {
       
  3846 			$obj_term = $ress[0];
       
  3847 			echo $obj_term->name ;
       
  3848 		}
       
  3849 	}
       
  3850 		
       
  3851 	/**
       
  3852 	 * To edit language when submit in edit-link-form
       
  3853 	 * @ since 1.8.5
       
  3854 	 */
       
  3855 	function edit_link_set_lang ( $link_id ) {
       
  3856 		// create relationships with link_language taxonomy
       
  3857 				$sellang = $_POST['xili_language_set'];
       
  3858 				// test if exist in link taxinomy or create it
       
  3859 				$linklang = term_exists($sellang,'link_'.TAXONAME);
       
  3860 				if ( !$linklang ) {
       
  3861 					$lang = term_exists($sellang,TAXONAME);
       
  3862 					$lang_term = get_term($lang[ 'term_id' ], TAXONAME );
       
  3863 					wp_insert_term( $lang_term -> name, 'link_'.TAXONAME , array ( 'alias_of' => '', 'description' => $lang_term -> description, 'parent' => 0, 'slug' => $lang_term->slug )  );
       
  3864 				}
       
  3865 				
       
  3866 				if ("" != $sellang) {
       
  3867 					wp_set_object_terms($link_id, $sellang, 'link_'.TAXONAME);
       
  3868 				} else {
       
  3869 					wp_delete_object_term_relationships( $link_id, 'link_'.TAXONAME ); 	
       
  3870 				}
       
  3871 	}
       
  3872 
       
  3873 	/**
       
  3874 	 * Contextual help
       
  3875 	 *
       
  3876 	 * @since 1.7.0
       
  3877 	 * @updated 2.4.1, 2.6.2
       
  3878 	 */
       
  3879 	 function add_help_text( $contextual_help, $screen_id, $screen ) { 
       
  3880 	  	if ( in_array ( $screen->id , array ('settings_page_language_page', 'settings_page_language_front_set',  'settings_page_language_expert','settings_page_language_support') ) ) {
       
  3881 	  		
       
  3882 	  		$page_title[ 'settings_page_language_page' ] = __( 'Languages page', 'xili-language' ) ;
       
  3883 	  		$page_title[ 'settings_page_language_front_set' ] = __( 'Languages front-end settings', 'xili-language' ) ;
       
  3884 	  		$page_title[ 'settings_page_language_expert' ] = __( 'Settings for experts', 'xili-language' ) ;
       
  3885 	  		$page_title[ 'settings_page_language_support' ] = __( 'xili-language support', 'xili-language' ) ;
       
  3886 	  		
       
  3887 	  		$line[ 'settings_page_language_page' ] = __('In this page, the list of languages used by the multilingual website is set.','xili-language');
       
  3888 	  		$line[ 'settings_page_language_front_set' ] = __('Here, you decide what happens when a visitor arrives on the website homepage with his browser commonly set according to his mother language. Xili-language offers multiple ways according your content strategy.','xili-language');
       
  3889 	  		$line[ 'settings_page_language_expert' ] = __('This sub-page will present how to set navigation menu in multilingual context with xili-language.','xili-language');
       
  3890 	  		$line[ 'settings_page_language_support' ] = __('This form to email to dev.xiligroup.com team your observations.','xili-language');
       
  3891 	  		
       
  3892 	  		$wiki_page[ 'settings_page_language_page' ] = '/index.php/Xili-language_settings:_the_list_of_languages,_line_by_line';
       
  3893 	  		$wiki_page[ 'settings_page_language_front_set' ] = '/index.php/Xili-language_settings:_Home_page_and_more...';
       
  3894 	  		$wiki_page[ 'settings_page_language_expert' ] = '/index.php/Xili-language:_navigation_menu';
       
  3895 	  		$wiki_page[ 'settings_page_language_support' ] = '/index.php/Xili-language_settings:_Assistance,_support_form';
       
  3896 	  		
       
  3897 	   	  $this_tab =
       
  3898 	   	  '<p><strong>' . sprintf( __('About this tab %s:','xili-language'), $page_title[$screen->id] ) . '</strong></p>' .
       
  3899 	   	  '<ul>' . 
       
  3900 	      '<li>' . $line[$screen->id] .'</li>' .
       
  3901 	      '<li>' . sprintf(__('<a href="%s" target="_blank">Xili Wiki Post</a>','xili-language'), $this->wikilink . $wiki_page[$screen->id] ) . '</li>' .
       
  3902 	   	  '</ul>' ;
       
  3903 	   	  
       
  3904 	   	  $to_remember = 
       
  3905 	      '<p><strong>' . __('Things to remember to set xili-language:','xili-language') . '</strong></p>' .
       
  3906 	      '<ul>' .
       
  3907 	      '<li>' . __('Verify that the theme is localizable (like kubrick, fusion or twentyten or others...).','xili-language') . '</li>' .
       
  3908 	      '<li>' . __('Define the list of targeted languages.','xili-language') . '</li>' .
       
  3909 	      '<li>' . __('Prepare .po and .mo files for each language with poEdit or xili-dictionary plugin.','xili-language') . '</li>' .
       
  3910 	      '<li>' . __('If your website contains custom post type: check those which need to be multilingual. xili-language will add automatically edit meta boxes.','xili-language') . '</li>' .
       
  3911 	      '</ul>' ;
       
  3912 	      
       
  3913 	      $more_infos = 
       
  3914 	      '<p><strong>' . __('For more information:') . '</strong></p>' .
       
  3915 	      '<p>' . __('<a href="http://dev.xiligroup.com/xili-language" target="_blank">Xili-language Plugin Documentation</a>','xili-language') . '</p>' .
       
  3916 	      '<p>' . sprintf(__('<a href="%s" target="_blank">Xili Wiki Documentation</a>','xili-language'), $this->wikilink ) . '</p>' .
       
  3917 	      '<p>' . __('<a href="http://forum2.dev.xiligroup.com/" target="_blank">Support Forums</a>','xili-language') . '</p>' .
       
  3918 	      '<p>' . __('<a href="http://codex.wordpress.org/" target="_blank">WordPress Documentation</a>','xili-language') . '</p>' ;
       
  3919 	      
       
  3920 	      $screen->add_help_tab( array(
       
  3921  				'id'      => 'this-tab',
       
  3922 				'title'   => __('About this tab','xili-language'),
       
  3923 				'content' => $this_tab,
       
  3924 		  ));
       
  3925 	      
       
  3926 	      $screen->add_help_tab( array(
       
  3927  				'id'      => 'to-remember',
       
  3928 				'title'   => __('Things to remember','xili-language'),
       
  3929 				'content' => $to_remember,
       
  3930 		  ));
       
  3931 	      
       
  3932 	      $screen->add_help_tab( array(
       
  3933  				'id'      => 'more-infos',
       
  3934 				'title'   => __('For more information', 'xili-language'),
       
  3935 				'content' => $more_infos,
       
  3936 		  ));
       
  3937 
       
  3938 	  }
       
  3939 	  return $contextual_help;
       
  3940 	}
       
  3941 	
       
  3942 } 
       
  3943  
       
  3944 
       
  3945 ?>