web/wp-content/plugins/xili-dictionary/xili-dictionary.php
changeset 194 32102edaa81b
parent 170 8e3a5a6fc63e
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /*
     2 /*
     3 Plugin Name: xili-dictionary
     3 Plugin Name: xili-dictionary
     4 Plugin URI: http://dev.xiligroup.com/xili-dictionary/
     4 Plugin URI: http://dev.xiligroup.com/xili-dictionary/
     5 Description: ONLY for >= WP 2.8. This plugin is a tool using wordpress's taxonomy for localized themes or multilingual themes managed by xili-language - a powerful tool to create .mo file(s) on the fly in the theme's folder and more... -
     5 Description: A tool using wordpress's CPT and taxonomy for localized themes or multilingual themes managed by xili-language - a powerful tool to create .mo file(s) on the fly in the theme's folder and more... - ONLY for >= WP 3.2.1 - 
     6 Author: MS
     6 Author: dev.xiligroup - MS
     7 Version: 1.0.3
     7 Version: 2.2.0
     8 Author URI: http://dev.xiligroup.com
     8 Author URI: http://dev.xiligroup.com
       
     9 License: GPLv2
       
    10 Text Domain: xili-dictionary
       
    11 Domain Path: /languages/
     9 */
    12 */
    10 
    13 
    11 # beta 1.0.3 - fixes some directories issues in (rare) xamp servers and in theme's terms import. Create .po with empty translations.
    14 # 2.2.0 - 120922 - fixes issues with .mo and .po inserts - better messages and warning
    12 # beta 1.0.2 - JS and vars, create lang list, if xili-language absent, for international themes - lot of fixes
    15 # 2.1.3 - 120728 - fixes
    13 # beta 1.0.1 - add scripts for form with plural msg (id or str)
    16 # 2.1.2 - 120715 - list in msg edit - new query - new metabox - new pointers - ...
    14 # beta 1.0.0 - use pomo libraries and classes - ONLY >= 2.8
    17 # 2.1.1 - 120710 - fixes - new icons
    15 # beta 0.9.9 - fixes existing msgid terms - better log display when importing theme's terms
    18 # 2.1.0 - 120507 - options to save on new local-xx_XX.mo and more... needs XL 2.6
    16 # beta 0.9.8.2 - more html tags in msg str or id
    19 # 2.0.0 - 120417 - repository as current
    17 # beta 0.9.8.1 - some fixes for IIS server and PHP 5.2.1
    20 # beta 2.0.0-rc4 - 120415 - fixes
    18 # beta 0.9.8 - WP 2.8 - fix query error
    21 # beta 2.0.0-rc3 - 120406 - pre-tests  WP3.4: fixes metaboxes columns, conditional edit link in list
    19 # beta 0.9.7.3 <- to - see readme.txt - from  0.9.4
    22 # beta 2.0.0-rc2 - 120402 - latest fixes (writers)
       
    23 # beta 2.0.0-rc1 - 120318 - before svn
       
    24 # beta 2.0.0 - 120219 - new way of saving lines in CPT
       
    25 
       
    26 
       
    27 #
       
    28 # now msg lines full commented as in .po
       
    29 # now translated lines (msgstr) attached to same taxonomy as xili-language
       
    30 # before upgrading from 1.4.4 to 2.0, export all the dictionary in .po files and empty the dictionary.
       
    31 #
       
    32 # beta 1.4.4 - 111221 - fixes
       
    33 # between 0.9.3 and 1.4.4 see version 1.4.4 - 20120219
    20 # beta 0.9.3 - first published - 090131 MS
    34 # beta 0.9.3 - first published - 090131 MS
    21 
    35 
    22 
    36 
    23 # This plugin is free software; you can redistribute it and/or
    37 define('XILIDICTIONARY_VER','2.2.0');
    24 # modify it under the terms of the GNU Lesser General Public
       
    25 # License as published by the Free Software Foundation; either
       
    26 # version 2.1 of the License, or (at your option) any later version.
       
    27 #
       
    28 # This plugin is distributed in the hope that it will be useful,
       
    29 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
       
    31 # Lesser General Public License for more details.
       
    32 #
       
    33 # You should have received a copy of the GNU Lesser General Public
       
    34 # License along with this plugin; if not, write to the Free Software
       
    35 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
       
    36 
       
    37 define('XILIDICTIONARY_VER','1.0.3');
       
    38 
    38 
    39 include_once(ABSPATH . WPINC . '/pomo/po.php'); /* not included in wp-settings */
    39 include_once(ABSPATH . WPINC . '/pomo/po.php'); /* not included in wp-settings */
    40 
    40 
       
    41 // the class
    41 class xili_dictionary {
    42 class xili_dictionary {
    42 	
    43 	
       
    44 	var $plugin_url = ''; // Url to this plugin - see construct
       
    45 	var $plugin_path = ''; // The path to this plugin - see construct
       
    46 	
    43 	var $subselect = ''; /* used to subselect by msgid or languages*/
    47 	var $subselect = ''; /* used to subselect by msgid or languages*/
       
    48 	var $searchtranslated = ''; /* used to search untranslated - 2.1.2 */
       
    49 	var $languages_key_slug = array(); // used for slug to other items
       
    50 	var $msg_action_message = '';
    44 	var $xililanguage = ''; /* neveractive isactive wasactive */
    51 	var $xililanguage = ''; /* neveractive isactive wasactive */
       
    52 	var $xililanguage_ms = false;  // xlms
    45 	var $tempoutput = "";
    53 	var $tempoutput = "";
    46 	var $langfolder ='/'; /* where po or mo files */
    54 	var $langfolder =''; /* where po or mo files */
    47 	var $xili_settings; /* saved in options */
    55 	var $xili_settings; /* saved in options */
    48 	var $ossep = "/"; /* for recursive file search in xamp */
    56 	var $ossep = "/"; /* for recursive file search in xamp */
    49 	
    57 		
    50 	function xili_dictionary($langsfolder = '/') {
    58 	// 2.0 new vars
       
    59 	var $xdmsg = "xdmsg";
       
    60 	var $xd_settings_page = "edit.php?post_type=xdmsg&amp;page=dictionary_page"; // now in CPT menu
       
    61 	
       
    62 	// post meta
       
    63 	var $ctxt_meta = '_xdmsg_ctxt'; // to change to xdctxt
       
    64 	var $msgtype_meta = '_xdmsg_msgtype'; // to hidden
       
    65 	var $msgchild_meta = '_xdmsg_msgchild';
       
    66 	var $msglang_meta = '_xdmsg_msglangs';
       
    67 	var $msgidlang_meta = '_xdmsg_msgid_id'; // origin of the msgstr
       
    68 	var $msg_extracted_comments = '_xdmsg_extracted_comments';
       
    69 	var $msg_translator_comments = '_xdmsg_translator_comments';
       
    70 	var $msg_flags = '_xdmsg_flags';
       
    71 	
       
    72 	var $origin_theme = ""; // used when importing
       
    73 	var $local_tag = '[local]';
       
    74 	var $exists_style_ext = false;  // wp_enqueue_style( 'xili_dictionary_stylesheet' ); 
       
    75 	var $style_message = '';
       
    76 	var $xilidev_folder = '/xilidev-libraries'; //must be in plugins
       
    77 	
       
    78 	var $theme_mos = array(); // $this->get_pomo_from_theme();
       
    79  	var $local_mos = array() ; // $this->get_pomo_from_theme( true ); // 2.1
       
    80  	//	is_multisite
       
    81  	var $file_site_mos = array() ; // $this->get_pomo_from_site(); // since 1.2.0 - mo of site
       
    82  	var $file_site_local_mos = array() ; // $this->get_pomo_from_site( true ); 
       
    83  	
       
    84 	var $default_langs_array = array(); // default languages
       
    85 	var $internal_list = false; // created by xl or xd
       
    86 	
       
    87 	var $importing_mode = false ; // for new action by hand ( action save when new )
       
    88 	var $msg_str_labels = array (
       
    89 		'msgid' => 'msgid', 'msgid_plural' => 'msgid_plural', 
       
    90 		'msgstr' => 'msgstr', 'msgstr_0' => 'msgstr[0]', 
       
    91 		'msgstr_1' => 'msgstr[1]', 'msgstr_2' => 'msgstr[2]', 
       
    92 		'msgstr_3' => 'msgstr[3]', 'msgstr_4' => 'msgstr[4]'  
       
    93 		) ;
       
    94 	var $importing_po_comments = '' ;	// mode replace or append 2.0-rc2
       
    95 	var $create_line_lang = ''; // line between box
       
    96 	
       
    97 	var $langs_group_id; /* group ID and Term Taxo ID */
       
    98 	var $langs_group_tt_id;
       
    99 	
       
   100 	
       
   101 	
       
   102 	public function xili_dictionary( $langsfolder = '/' ) { // ?? php4
       
   103 		$this->__construct( $langsfolder );
       
   104 	}
       
   105 		
       
   106 	public function __construct( $langsfolder = '/' ) {	
       
   107 		global $wp_version;
    51 		/* activated when first activation of plug */
   108 		/* activated when first activation of plug */
    52 		register_activation_hook(__FILE__,array(&$this,'xili_dictionary_activation'));
   109 		// 2.0
       
   110 		define ( 'XDMSG', $this->xdmsg ); // CPT to change from msg to xdmsg (less generic) 20120217
       
   111 		
       
   112 		$this->plugin_path = plugin_dir_path(__FILE__) ;
       
   113 		$this->plugin_url = plugins_url('', __FILE__) ; 
       
   114 		
       
   115 		register_activation_hook( __FILE__, array( &$this,'xili_dictionary_activation') );
       
   116 		
    53 		$this->ossep = strtoupper(substr(PHP_OS,0,3)=='WIN')?'\\':'/'; /* for rare xamp servers*/
   117 		$this->ossep = strtoupper(substr(PHP_OS,0,3)=='WIN')?'\\':'/'; /* for rare xamp servers*/
       
   118 		
    54 		/* get current settings - name of taxonomy - name of query-tag */
   119 		/* get current settings - name of taxonomy - name of query-tag */
    55 		$this->xililanguage_state();
   120 		$this->xililanguage_state();
    56 		$this->xili_settings = get_option('xili_dictionary_settings');
   121 		$this->xili_settings = get_option('xili_dictionary_settings'); 
    57 		if(empty($this->xili_settings)) {
   122 		if(empty($this->xili_settings) || $this->xili_settings['taxonomy'] != 'dictionary') { // to fix
    58 			$this->xili_dictionary_activation();
   123 			$this->xili_dictionary_activation();
    59 			$this->xili_settings = get_option('xili_dictionary_settings');			
   124 			$this->xili_settings = get_option('xili_dictionary_settings');			
    60 		}
   125 		}
    61 		define('DTAXONAME',$this->xili_settings['taxonomy']);
       
    62 		define('XDDICTLANGS','xl-'.DTAXONAME.'-langs');
       
    63 		/** * @since 1.0 */
       
    64 		define('XPLURAL','[XPLURAL]'); /* to separate singular and plural entries */
       
    65 		
       
    66 		
       
    67 		/* add new taxonomy in available taxonomies here dictionary terms */
       
    68 		register_taxonomy( DTAXONAME, 'post',array('hierarchical' => true, 'update_count_callback' => ''));
       
    69 		/* groups of terms by langs */
       
    70 		register_taxonomy( XDDICTLANGS, 'term',array('hierarchical' => false, 'update_count_callback' => ''));
       
    71 		
   126 		
    72 		/* test if version changed */
   127 		/* test if version changed */
    73 		$version = $this->xili_settings['version'];
   128 		$version = $this->xili_settings['version'];
    74 		if ($version <= '0.2') {
   129 		if ( $version <= '0.2' ) {
    75 				/* update relationships for grouping existing dictionary terms */
   130 				/* update relationships for grouping existing dictionary terms */
    76 			$this->update_terms_langs_grouping();
   131 			$this->update_terms_langs_grouping();
    77 			$this->xili_settings['version'] = '1.0';
   132 			$this->xili_settings['version'] = '1.0';
    78 			update_option('xili_dictionary_settings', $this->xili_settings);
   133 			update_option('xili_dictionary_settings', $this->xili_settings);
    79 		}
   134 		} 
       
   135 		if ( $version == '1.0' ) {
       
   136 			$this->xili_settings['external_xd_style'] = "off";
       
   137 			$this->xili_settings['version'] = '2.0';
       
   138 			update_option('xili_dictionary_settings', $this->xili_settings);
       
   139 		} 
       
   140 		if ( $version == '2.0' ) { 
       
   141 			$this->update_postmeta_msgid();
       
   142 			$this->xili_settings['version'] = '2.1';
       
   143 			update_option('xili_dictionary_settings', $this->xili_settings);
       
   144 		}
       
   145 		
    80 		$this->fill_default_languages_list();
   146 		$this->fill_default_languages_list();
    81 		/* Actions */
   147 		/* Actions */
    82 		add_action('admin_menu', array(&$this,'xili_add_dict_pages'));
   148 		/* admin */
    83 		add_action('init', array(&$this, 'init_textdomain'));
   149 		add_action( 'admin_init', array(&$this,'admin_init') ); // 1.3.0
    84 		add_filter('plugin_action_links',  array(&$this,'xilidict_filter_plugin_actions'), 10, 2);						
   150 		add_action( 'admin_init', array(&$this,'ext_style_init') ); // 2.1
    85 	}
   151 		add_action( 'admin_menu', array(&$this,'xili_add_dict_pages') );
       
   152 		
       
   153 		add_action( 'add_meta_boxes', array(&$this, 'add_custom_box_in_post_msg') ); // 2.1.2
       
   154 		
       
   155 		add_action( 'init', array(&$this, 'xili_dictionary_register_taxonomies')); // and init
       
   156 	
       
   157 		add_action( 'init', array(&$this, 'post_type_msg') ); 
       
   158 		
       
   159 		if ( is_admin() ) {
       
   160 		 	add_filter( 'manage_posts_columns', array(&$this,'xili_manage_column_name') ,9 , 1);
       
   161 			add_filter( "manage_pages_custom_column", array(&$this,'xili_manage_column_row'), 9, 2); // hierarchic
       
   162 			add_filter( 'manage_edit-'.XDMSG.'_sortable_columns', array(&$this,'msgcontent_column_register_sortable') );
       
   163 			add_filter( 'request', array(&$this,'msgcontent_column_orderby' ) );
       
   164 			
       
   165 			if ( !class_exists ('xili_language' ) )
       
   166 				add_action( 'restrict_manage_posts', array(&$this,'restrict_manage_languages_posts') );
       
   167 			
       
   168 			add_action( 'restrict_manage_posts', array(&$this,'restrict_manage_writer_posts'), 11 );
       
   169 			add_action( 'restrict_manage_posts', array(&$this,'restrict_manage_origin_posts'), 10 );
       
   170 			add_action( 'pre_get_posts', array(&$this,'wpse6066_pre_get_posts' ) );
       
   171 			
       
   172 			
       
   173 			add_action( 'wp_print_scripts', array(&$this,'auto_save_unsetting' ), 2 ); // before other
       
   174 			
       
   175 			add_filter( 'user_can_richedit', array(&$this, 'disable_richedit_for_cpt') );
       
   176 			
       
   177 			if ( defined ('WP_DEBUG') &&  WP_DEBUG != true ) {
       
   178 				add_filter( 'page_row_actions', array(&$this, 'remove_quick_edit'), 10, 1); // before to solve metas column
       
   179 			}
       
   180 			add_action( 'save_post', array(&$this, 'custom_post_type_title'),11 ,2); // 
       
   181 			add_action( 'save_post', array(&$this, 'msgid_post_new_create'),12 ,2 );
       
   182 			add_action( 'save_post', array(&$this, 'update_msg_comments'),13, 2 ); // comments and contexts
       
   183 			add_filter( 'post_updated_messages', array(&$this, 'msg_post_messages'));
       
   184 			
       
   185 			add_action( 'before_delete_post', array(&$this, 'msgid_post_links_delete') );
       
   186 			add_action( 'admin_print_styles-post.php', array(&$this, 'print_styles_xdmsg_edit') );
       
   187 			add_action( 'admin_print_styles-post-new.php', array(&$this, 'print_styles_xdmsg_edit') );
       
   188 			
       
   189 			add_action( 'admin_print_styles-post.php', array(&$this,'admin_enqueue_styles') );
       
   190 			add_action( 'admin_print_scripts-post.php', array(&$this,'admin_enqueue_scripts') );	
       
   191 			
       
   192 			add_action( 'admin_print_styles-edit.php', array(&$this, 'print_styles_xdmsg_list') ); // list of msgs
       
   193 			
       
   194 			add_action( 'admin_print_styles-xdmsg_page_dictionary_page', array(&$this, 'print_styles_xdmsg_tool') );
       
   195 			
       
   196 			
       
   197 			add_action( 'add_meta_boxes_' . XDMSG, array(&$this, 'msg_update_action')); // to locally update files from editing...
       
   198 		}
       
   199 		
       
   200 		add_filter( 'plugin_action_links',  array(&$this,'xilidict_filter_plugin_actions'), 10, 2);
       
   201 		
       
   202 		/* special to detect theme changing since 1.1.9 */
       
   203 		add_action( 'switch_theme', array(&$this,'xd_theme_switched') );
       
   204 		
       
   205 		add_action( 'contextual_help', array(&$this,'add_help_text'), 10, 3 ); /* 1.2.2 */
       
   206 		
       
   207 		
       
   208 		if ( class_exists('xili_language_ms') ) $this->xililanguage_ms = true; // 1.3.4
       
   209 										
       
   210 	}
       
   211 	
       
   212 		
       
   213 	/* wp 3.0 WP-net */
       
   214 	function xili_dictionary_register_taxonomies () {
       
   215 		
       
   216 		if ( is_admin() ) {
       
   217 			global $wp_roles;
       
   218 			
       
   219 			if ( current_user_can ('activate_plugins') ) {
       
   220 				$wp_roles->add_cap ('administrator', 'xili_dictionary_set');
       
   221 			}
       
   222 		}
       
   223 		if (function_exists('is_child_theme') && is_child_theme() ) { // move here from init 1.4.1
       
   224 			if ( isset( $this->xili_settings['langs_in_root_theme'] ) && $this->xili_settings['langs_in_root_theme'] == 'root' ) { // for future uses
       
   225 				$this->get_template_directory = get_template_directory();
       
   226 			} else {
       
   227 				$this->get_template_directory = get_stylesheet_directory();
       
   228 			}
       
   229 		} else {
       
   230 			$this->get_template_directory = get_template_directory();
       
   231 		}
       
   232 		$this->init_textdomain();
       
   233 		
       
   234 		// new method for languages 2.0
       
   235 		$this->internal_list = $this->default_language_taxonomy ();
       
   236 	
       
   237 		if ( $this->internal_list ) { // test if empty
       
   238 			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
       
   239 			if ( $listlanguages == array() ) {
       
   240 				$this->create_default_languages();
       
   241 			}
       
   242 		}
       
   243 		$thegroup = get_terms( TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group'));
       
   244 		if ( $thegroup != array() ) { // notice on first start
       
   245 			$this->langs_group_id = $thegroup[0]->term_id;
       
   246 			$this->langs_group_tt_id = $thegroup[0]->term_taxonomy_id;
       
   247 		}	
       
   248 	}	
    86 	
   249 	
    87 	function xili_dictionary_activation() {
   250 	function xili_dictionary_activation() {
    88 		$this->xili_settings = get_option('xili_dictionary_settings');
   251 		$this->xili_settings = get_option('xili_dictionary_settings'); 
    89 		if(empty($this->xili_settings)) { 
   252 		if ( empty($this->xili_settings) || $this->xili_settings['taxonomy'] != 'dictionary') { // to fix
    90 			$submitted_settings = array(
   253 			$submitted_settings = array(
    91 		    	'taxonomy'		=> 'dictionary',
   254 		    	'taxonomy'		=> 'dictionary',
    92 		    	'langs_folder' => '',
   255 		    	'langs_folder' => '',
    93 		    	'version' 		=> '1.0'
   256 		    	'external_xd_style' => 'off',
       
   257 		    	'version' 		=> '2.1'
    94 	    	);
   258 	    	);
    95 			update_option('xili_dictionary_settings', $submitted_settings);	
   259 			update_option('xili_dictionary_settings', $submitted_settings);	
    96 		} 			 	    
   260 		} 			 	    
    97 	}
   261 	}
    98 	
   262 	
    99 	/** * add js in admin * @updated 1.0.2 */
   263 	function post_type_msg() {
   100 	function xili_add_js() {
   264 	
   101 		wp_enqueue_script( 'xd-plural', '/'.PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/plural.php?var='.XPLURAL, array('jquery'), XILIDICTIONARY_VER);
   265 		$labels = array(
   102 	}
   266 	    'name' => _x('xili-dictionary©', 'post type general name', 'xili-dictionary'),
   103 	
   267 	    'singular_name' => _x('Msg', 'post type singular name', 'xili-dictionary'),
   104 	/** *add admin menu and associated page */
   268 	    'add_new' => __('New msgid', 'xili-dictionary'),
       
   269 	    'add_new_item' => __('Add New Msgid', 'xili-dictionary'),
       
   270 	    'edit_item' => __('Edit Msg', 'xili-dictionary'),
       
   271 	    'new_item' => __('New Msg', 'xili-dictionary'),
       
   272 	    'view_item' => __('View Msg', 'xili-dictionary'),
       
   273 	    'search_items' => __('Search Msg', 'xili-dictionary'),
       
   274 	    'not_found' =>  __('No Msg found', 'xili-dictionary'),
       
   275 	    'not_found_in_trash' => __('No Msg found in Trash', 'xili-dictionary'), 
       
   276 	    'parent_item_colon' => ''
       
   277 	  );
       
   278 	  
       
   279 	  // impossible to see in front-end (no display in edit list)
       
   280 	  $args = array(
       
   281 	    'labels' => $labels,
       
   282 	    'public' => false,
       
   283 	    'publicly_queryable' => false,
       
   284 	    '_edit_link' => 'post.php?post=%d',
       
   285 		'_builtin' => false, 
       
   286 	    'show_ui' => true, 
       
   287 	    'query_var' => true,
       
   288 	    'rewrite' => false,
       
   289 	    'capability_type' => 'post',
       
   290 	    'show_in_menu' => current_user_can ('xili_dictionary_set'), // ?? if not admin
       
   291 	    'hierarchical' => true,
       
   292 	    'menu_position' => null,
       
   293 	    'supports' => array('author','editor', 'excerpt','custom-fields','page-attributes'),
       
   294 	    'taxonomies' => array ('appearance', 'writer', 'origin' ),
       
   295 	    'rewrite' => array( 'slug' => XDMSG, 'with_front' => FALSE, ),
       
   296 	    'menu_icon' => plugins_url( 'images/xilidico-logo-16.jpg', __FILE__ ) // 16px16
       
   297 	 ); 
       
   298 	  	register_post_type(XDMSG,$args);
       
   299 		
       
   300 	 	register_taxonomy( 'writer', array(XDMSG), 
       
   301 	 		array( 'hierarchical' => true, 
       
   302 	 			'label' => __('Writer','xili-dictionary'), 
       
   303 	 			'rewrite' => true,
       
   304 	 			'query_var' => 'writer_name',
       
   305 	 			'public' => false,
       
   306 				'show_ui' => true,
       
   307 	 			) 
       
   308 	 	);
       
   309 	 	/*
       
   310 	 	register_taxonomy( 'appearance', array(XDMSG), 
       
   311 	 		array( 'hierarchical' => true,  // theme and child 
       
   312 	 			'label' => __('Theme','xili-dictionary'), 
       
   313 	 			'rewrite' => true,
       
   314 	 			'query_var' => 'theme_slug',
       
   315 	 			'public' => false,
       
   316 				'show_ui' => true,
       
   317 	 			) 
       
   318 	 	);
       
   319 	 	*/
       
   320 		register_taxonomy( 'origin', array(XDMSG),
       
   321 			array('hierarchical' => false,
       
   322 			 	'label' => __('Origin','xili-dictionary'),
       
   323 			 	'query_var' => 'origin',
       
   324 			 	'rewrite' => array('slug' => 'origin' )
       
   325 			)
       
   326 		);	
       
   327 	}
       
   328 
       
   329 	/**
       
   330 	 * register language taxonomy if no xili_language - 'update_count_callback' => array(&$this, '_update_post_lang_count'),
       
   331 	 *
       
   332 	 *
       
   333 	 */
       
   334 	function default_language_taxonomy () {
       
   335 		if ( ! defined ( 'TAXONAME' )  ) {
       
   336 			if ( ! defined ( 'QUETAG' ) ) define ('QUETAG', 'lang');
       
   337 			define ('TAXONAME', 'language');
       
   338 			register_taxonomy( TAXONAME, 'post', array('hierarchical' => false, 'label' => false, 'rewrite' => false ,  'show_ui' => false, '_builtin' => false, 'query_var' => QUETAG ));
       
   339 			define('TAXOLANGSGROUP', 'languages_group');
       
   340 			register_taxonomy( TAXOLANGSGROUP, 'term', array('hierarchical' => false, 'update_count_callback' => '', 'show_ui' => false, 'label'=>false, 'rewrite' => false, '_builtin' => false ));
       
   341 			$thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group'));
       
   342 			if ( array() == $thegroup ) { 
       
   343 				$args = array( 'alias_of' => '', 'description' => 'the group of languages', 'parent' => 0, 'slug' =>'the-langs-group');
       
   344 				wp_insert_term( 'the-langs-group', TAXOLANGSGROUP, $args); /* create and link to existing langs */
       
   345 			}	
       
   346 			return true;
       
   347 		} else {
       
   348 			return false;
       
   349 		}	
       
   350 	}
       
   351 	
       
   352 	/**
       
   353 	 * add styles in edit msg screenstyle="clear:both; border-top:1px solid #666;"
       
   354 	 *
       
   355 	 */
       
   356 	 function print_styles_xdmsg_edit ( ) { 
       
   357 	 	global $post; 
       
   358 	 	if ( get_post_type( $post->ID ) == XDMSG ) {
       
   359 			echo '<!---- xd css ----->'."\n";
       
   360 			echo '<style type="text/css" media="screen">'."\n";
       
   361 			
       
   362 			echo '#msg-states { width:69%;  float:left; border:0px solid red; padding-bottom: 10px}'."\n";
       
   363 			echo '#msg-states-comments { width:27%; margin-left: 70%; border-left:0px #666 solid;  padding:10px 10px 0;  }'."\n";
       
   364 			echo '#msg-states-actions { background:#ffffff; clear:left; padding: 8px 5px; margin-top:5px; }'."\n";
       
   365 			echo '.xdversion { font-size:80%; text-align:right; }'."\n";
       
   366 			echo '.msg-states-actions-left { float:left; padding: 8px 0px; overflow:hidden; width:50% }'."\n";
       
   367 			echo '.msg-states-actions-right { float:left; padding: 8px 0px; width:50% }'."\n";
       
   368 			echo '.alert { color:red;}'."\n";
       
   369 			echo '.editing { color:blue; background:yellow;}'."\n";
       
   370 			echo '.msgidstyle { line-height:200% !important; font-size:120%; padding:4px 10px 6px;}'."\n";
       
   371 			echo '.msgstrstyle { line-height:180% !important; font-size:110%; }'."\n";
       
   372 			echo '.msg-saved { background:#ffffff !important; border:1px dotted #999; padding:5px; margin-bottom:5px;}'."\n";
       
   373 			echo '.column-msgtrans {width: 20%;}'."\n";
       
   374 			
       
   375 			// buttons
       
   376 			echo '.action-button {text-decoration:none; text-align:center; display:block; width:70%; margin:0px 1px 1px 30px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;}'."\n";
       
   377 			echo '.blue-button {border:1px #33f solid;}'."\n";
       
   378 			echo '.grey-button {border:1px #ccc solid;}'."\n";
       
   379 			
       
   380 			echo '</style>'."\n";
       
   381 			if ( $this->exists_style_ext && $this->xili_settings['external_xd_style'] == "on" ) wp_enqueue_style( 'xili_dictionary_stylesheet' ); 
       
   382 	 	}
       
   383 	 }
       
   384 	 
       
   385 	 /**
       
   386 	 * add styles in list of msgs screen icon32-posts-xdmsg
       
   387 	 *
       
   388 	 */
       
   389 	 function print_styles_xdmsg_list ( ) { 
       
   390 	 	 
       
   391 	 	if ( isset( $_GET['post_type']) && $_GET['post_type'] == XDMSG ) { 
       
   392 	 
       
   393 	 		echo '<!---- xd css ----->'."\n";
       
   394 			echo '<style type="text/css" media="screen">'."\n";
       
   395 			
       
   396 	 		echo '.alert { color:red;}'."\n";
       
   397 	 		echo '.column-language { width: 80px; }'."\n";
       
   398 	 		echo '.column-msgcontent { width: 40%; }'."\n";
       
   399 	 		echo '.column-msgpostmeta { width: 150px; }'."\n";
       
   400 	 		echo '.column-author { width: 80px !important; }'."\n";
       
   401 	 		echo '.column-title { width: 160px !important; }'."\n";
       
   402 	 
       
   403 	 		echo '#icon-edit.icon32-posts-xdmsg { background:transparent url('.plugins_url( 'images/xilidico-logo-32.jpg', __FILE__ ) . ') no-repeat !important ; }'."\n";
       
   404 			echo '</style>'."\n";
       
   405 			if ( $this->exists_style_ext && $this->xili_settings['external_xd_style'] == "on" ) wp_enqueue_style( 'xili_dictionary_stylesheet' );
       
   406  	    
       
   407 	 	}	
       
   408 	 }
       
   409 	 
       
   410 	 /**
       
   411 	 * add styles in tool screen
       
   412 	 *
       
   413 	 */
       
   414 	 function print_styles_xdmsg_tool ( ) {
       
   415 	 	echo '<!---- xd css ----->'."\n";
       
   416 		echo '<style type="text/css" media="screen">'."\n";
       
   417 		
       
   418 		echo '.dialoglang { float:left; width:25%; border:0px solid grey; margin: 5px; }'."\n";
       
   419 		echo '.dialogfile { float:left; width:37%; min-height:80px; border:0px solid grey; padding: 10px 5px 10px 20px; } '."\n";
       
   420 		echo '.dialogorigin { float:left; width:32%; min-height:80px; border:0px solid grey; padding: 10px 5px 10px 10px; } '."\n";
       
   421 		echo '.dialogbbt {clear:left; text-align:right; }'."\n";
       
   422 		echo 'table.checktheme { width:95%; margin-left:10px;}'."\n";
       
   423 	 	echo 'table.checktheme>tr>td { width:45% }'."\n";
       
   424 	 	
       
   425 	 	
       
   426 	 	// buttons
       
   427 		echo '.action-button {text-decoration:none; text-align:center; display:block; width:70%; margin:0px 1px 1px 30px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;}'."\n";
       
   428 		echo '.small-action-button {text-decoration:none; text-align:center; display:inline-block; width:16%; margin:0px 1px 1px 10px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;  border:1px #ccc solid;}'."\n";
       
   429 		echo '.blue-button {border:1px #33f solid;}'."\n";
       
   430 		echo '.grey-button {border:1px #ccc solid;}'."\n";
       
   431 	 	
       
   432 	 	echo '</style>'."\n";
       
   433 	 	if ( $this->exists_style_ext && $this->xili_settings['external_xd_style'] == "on" ) wp_enqueue_style( 'xili_dictionary_stylesheet' );
       
   434 	 }
       
   435 	 
       
   436 	 
       
   437 	/** 
       
   438 	 * style for new dashboard
       
   439 	 * @since 2.1
       
   440 	 * 
       
   441 	 */	
       
   442 	function ext_style_init () {  
       
   443 				// test successively style file in theme, plugins, current plugin subfolder
       
   444 		if ( file_exists ( get_stylesheet_directory().'/xili-css/xd-style.css' ) ) { // in child theme
       
   445 				$this->exists_style_ext = true; 
       
   446 				$this->style_folder = get_stylesheet_directory_uri();
       
   447 				$this->style_flag_folder_path = get_stylesheet_directory () . '/images/flags/';
       
   448 				$this->style_message = __( 'xd-style.css is in sub-folder xili-css of current theme folder', 'xili-dictionary' );
       
   449 		} elseif ( file_exists( WP_PLUGIN_DIR . $this->xilidev_folder . '/xili-css/xd-style.css' ) ) { // in plugin xilidev-libraries
       
   450 				$this->exists_style_ext = true;
       
   451 				$this->style_folder = plugins_url() . $this->xilidev_folder;
       
   452 				$this->style_flag_folder_path = WP_PLUGIN_DIR . $this->xilidev_folder . '/xili-css/flags/' ;
       
   453 				$this->style_message = sprintf( __( 'xd-style.css is in sub-folder xili-css of %s folder', 'xili-dictionary' ), $this->style_folder ); 
       
   454 		} elseif ( file_exists ( $this->plugin_path.'/xili-css/xd-style.css' ) ) { // in current plugin
       
   455 				$this->exists_style_ext = true;
       
   456 				$this->style_folder = $this->plugin_url ;
       
   457 				$this->style_flag_folder_path = $this->plugin_path . '/xili-css/flags/' ;
       
   458 				$this->style_message = __( 'xd-style.css is in sub-folder xili-css of xili-dictionary plugin folder (example)', 'xili-dictionary' );
       
   459 		} else {
       
   460 				$this->style_message = __( 'no xd-style.css', 'xili-dictionary' );
       
   461 		}
       
   462 		if ( $this->exists_style_ext ) wp_register_style( 'xili_dictionary_stylesheet', $this->style_folder . '/xili-css/xd-style.css' );
       
   463 	} 
       
   464 	 
       
   465 	
       
   466 	/**
       
   467 	 * create default languages if no xili_language
       
   468 	 *
       
   469 	 *
       
   470 	 */
       
   471 	function create_default_languages () {
       
   472 		
       
   473 		$this->default_langs_array = array( 
       
   474 			'en_us' => array('en_US', 'english'),
       
   475 			'fr_fr' => array('fr_FR', 'french'),
       
   476 			'de_de' => array('de_DE', 'german'),
       
   477 			'es_es' => array('es_ES', 'spanish'),
       
   478 			'it_it' => array('it_IT', 'italian'),
       
   479 			'pt_pt' => array('pt_PT', 'portuguese'),
       
   480 			'ru_ru' => array('ru_RU', 'russian'),
       
   481 			'zh_cn' => array('zh_CN', 'chinese'),
       
   482 			'ja' => array('ja', 'japanese'),
       
   483 			'ar_ar' => array('ar_AR', 'arabic')
       
   484 		);
       
   485 		
       
   486 		$term = 'en_US';
       
   487 		$args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'en_us');
       
   488 		$theids = $this->safe_lang_term_creation ( $term, $args );
       
   489 		wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
   490 		
       
   491 		/* default values */
       
   492 		if ( ''!= WPLANG && ( strlen( WPLANG )==5 || strlen( WPLANG ) == 2 ) ) : // for japanese
       
   493 			$this->default_lang = WPLANG;
       
   494 		else:
       
   495 			$this->default_lang = 'en_US';
       
   496 		endif;
       
   497 		
       
   498 		$term = $this->default_lang;
       
   499 		$desc = $this->default_lang;
       
   500  		$slug = strtolower( $this->default_lang ) ; // 2.3.1
       
   501  		if (!defined('WPLANG') || $this->default_lang == 'en_US' || $this->default_lang == '' ) {
       
   502  			$term = 'fr_FR'; $desc = 'French'; $slug = 'fr_fr' ;
       
   503  		}
       
   504  		$args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug);
       
   505  		
       
   506  		$theids = $this->safe_lang_term_creation ( $term, $args ) ;
       
   507  		wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
       
   508 		
       
   509 	}
       
   510 	
       
   511 	/**
       
   512 	 * Safe language term creation (if XL inactive)
       
   513 	 *
       
   514 	 * @since 2.0 (from XL 2.4.1) 
       
   515 	 */
       
   516 	 function safe_lang_term_creation ( $term, $args ) {
       
   517 	 	global $wpdb ;
       
   518 		// test if exists with other slug or name 
       
   519 		if ( $term_id = term_exists( $term ) ) { 
       
   520 			$existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name, slug FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A );
       
   521 			if ( $existing_term['slug'] != $args['slug'] ) {
       
   522 				$res = wp_insert_term( $term.'xl', TAXONAME, $args); // temp insert with temp other name
       
   523 				$args['name'] = $term ;
       
   524 				$res = wp_update_term( $res['term_id'], TAXONAME, $args);
       
   525 			} else {
       
   526 				return new WP_Error('term_exists', __('A term with the name provided already exists.'), $term_id );
       
   527 			}
       
   528 		} else {
       
   529 			$res = wp_insert_term( $term, TAXONAME, $args);
       
   530 		}
       
   531 		if (is_wp_error($res)) { 
       
   532 			return $res ;
       
   533 		} else { 
       
   534 			$theids = $res;
       
   535 		}
       
   536 		return $theids ;		
       
   537 	 }
       
   538 	 
       
   539 	/**
       
   540 	 * call from filter disable_richedit
       
   541 	 *
       
   542 	 * disable rich editor in msg cpt
       
   543 	 *
       
   544 	 * @since 2.0
       
   545 	 *
       
   546 	 */ 
       
   547 	function disable_richedit_for_cpt ( $default ) {
       
   548     	global $post;
       
   549     	if ( XDMSG == get_post_type( $post ) )
       
   550         	return false;
       
   551     	return $default;
       
   552 	}
       
   553 	function remove_quick_edit( $actions ) {
       
   554 		if ( isset ( $_GET['post_type'] ) &&  $_GET['post_type'] == XDMSG ) 
       
   555 			unset($actions['inline hide-if-no-js']);
       
   556 		
       
   557 		return $actions;
       
   558 	}
       
   559 
       
   560 	
       
   561 	/**
       
   562 	 * call from filter save_post
       
   563 	 *
       
   564 	 * save content in title - fixes empty msgid
       
   565 	 *
       
   566 	 * @since 2.0
       
   567 	 *
       
   568 	 */
       
   569 	function custom_post_type_title ( $post_id, $post ) {
       
   570     	global $wpdb;
       
   571     	if ( get_post_type( $post_id ) == XDMSG ) {
       
   572     		$where = array( 'ID' => $post_id );
       
   573         	$what = array ();
       
   574         	
       
   575         	if ( false === strpos( $post->post_title, 'MSG:' ) ) {
       
   576         		$title = 'MSG:'.$post_id;
       
   577         		$what['post_title'] = $title ;
       
   578         	}
       
   579         	
       
   580         	if ( $post->post_content == '' )  {
       
   581         		$what['post_content'] = "XD say: do not save empty ".$post_id;
       
   582         	}
       
   583         	if ( $what != array() ) 
       
   584         			$wpdb->update( $wpdb->posts, $what, $where );
       
   585     	}
       
   586 	}
       
   587 	
       
   588 	/** 
       
   589 	 * clean msgid postmeta before deleting
       
   590 	 */
       
   591 	function msgid_post_links_delete ( $post_id ) {
       
   592 		// type of msg
       
   593 		if ( get_post_type( $post_id ) == XDMSG ) {
       
   594 			$type  = get_post_meta ( $post_id, $this->msgtype_meta, true);
       
   595 			
       
   596 			if ( $type == 'msgid_plural' ) {
       
   597 				
       
   598 				$parent = get_post($post_id)->post_parent;
       
   599 				$res = get_post_meta ( $parent, $this->msgchild_meta, false );     
       
   600 				$thechilds =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
   601 				if ( $res != '' ) {
       
   602 					unset ( $thechilds['msgid']['plural'] ) ;
       
   603 					update_post_meta ( $parent, $this->msgchild_meta, $thechilds );
       
   604 				}
       
   605 				
       
   606 			} elseif ( $type != 'msgid' ) {
       
   607 				$langs = get_the_terms( $post_id, TAXONAME ); 
       
   608 				$target_lang = $langs[0]->name ; 
       
   609 				// id of msg id or parent
       
   610 				if ( $type == 'msgstr' && $target_lang != '' ) {
       
   611 					$msgid_ID = get_post_meta ( $post_id, $this->msgidlang_meta , true);
       
   612 					$res = get_post_meta ( $msgid_ID, $this->msglang_meta, false );
       
   613 					$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
   614 					if ( $res != '' && is_array ( $thelangs ) ) { 
       
   615 						
       
   616 						unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr'] ) ;
       
   617 						update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta
       
   618 					}	
       
   619 				} elseif ( false !== strpos( $type, 'msgstr_' ) && $target_lang != '' ) {
       
   620 					$indices = explode ('_', $type);
       
   621 					$msgid_ID = get_post_meta ( $post_id, $this->msgidlang_meta , true);
       
   622 					if ( $indices[1] == 0 ) {
       
   623 						$res = get_post_meta ( $msgid_ID, $this->msglang_meta, false );
       
   624 						$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
   625 						if ( $res != '' && is_array ( $thelangs ) ) {
       
   626 							unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] ) ;
       
   627 							// delete childs or trash ??
       
   628 							// ?? recursive 
       
   629 							update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta
       
   630 						}
       
   631 					} else {
       
   632 						$res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); 
       
   633 						$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
   634 						if ( $res != '' && is_array ( $thelangs )  ) {
       
   635 							if ( isset ( $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] ) ) {
       
   636 								$parent = $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] ;
       
   637 								$res = get_post_meta ( $parent, $this->msgchild_meta, false );     
       
   638 								$thechilds =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
   639 								if ( $res != '' ) { 
       
   640 									unset ( $thechilds['msgstr']['plural'][$indices[1]] ) ;
       
   641 									update_post_meta ( $parent, $this->msgchild_meta, $thechilds );
       
   642 								}
       
   643 							}
       
   644 						}	
       
   645 					} // indice > 0
       
   646 				} // str plural
       
   647 			} // msgstr
       
   648 		} // XDMSG
       
   649 	}
       
   650 	
       
   651 	/** 
       
   652 	 * a new msgid is created manually
       
   653 	 */
       
   654 	function msgid_post_new_create ( $post_id, $post ) {
       
   655 		global $wpdb;
       
   656 		if ( isset($_POST['_inline_edit']) ) return;
       
   657 		if ( isset( $_GET['bulk_edit']) ) return;
       
   658 		if ( get_post_type( $post_id ) == XDMSG ) {
       
   659 			if ( !wp_is_post_revision( $post_id ) && $this->importing_mode != true ) {
       
   660 				
       
   661 				//$temp_post = $this->temp_get_post ( $post_id );
       
   662 				$type = get_post_meta ( $post_id, $this->msgtype_meta, true ) ;
       
   663 				if (  $type == "" ) {
       
   664 					update_post_meta ( $post_id, $this->msgtype_meta, 'msgid' );
       
   665 					update_post_meta ( $post_id, $this->msglang_meta, array() );
       
   666 					update_post_meta ( $post_id, $this->msg_extracted_comments, $this->local_tag . ' '); // 2.2.0 local by default if hand created
       
   667 				}
       
   668 				$result = $this->msgid_exists ( $post->post_content );
       
   669 				if ( $result === false ||  $result[0] == $post_id ) {
       
   670 					return ;
       
   671 				} else {
       
   672 					if ( $type ==  get_post_meta ( $result[0], $this->msgtype_meta, true ) && $type == 'msgid') {
       
   673  						$newcontent = sprintf( __('msgid exists as %d with content: %s','xili-dictionary'), $result[0], $post->post_content ) ;
       
   674 						$where = array( 'ID' => $post_id );
       
   675 	        			$wpdb->update( $wpdb->posts, array( 'post_content' => $newcontent ), $where );
       
   676 					}
       
   677 				}
       
   678 			}
       
   679 		}
       
   680 	}
       
   681 	
       
   682 	/**
       
   683 	 * Main "dashboard" box in msg edit to display and link the series of msg
       
   684 	 *
       
   685 	 * @since 2.0
       
   686 	 * @updated 2.1.2 - called by action add_meta_boxes
       
   687 	 *
       
   688 	 */
       
   689 	function add_custom_box_in_post_msg () {
       
   690 		$singular_name = __('series','xili-dictionary');
       
   691 		
       
   692 		add_meta_box('msg_state', sprintf(__("msg %s",'xili-dictionary'), $singular_name), array(&$this,'msg_state_box'), XDMSG , 'normal','high');
       
   693 		if ( get_current_screen()->action != 'add' ) { // only for edit not new
       
   694 			add_meta_box('msg_untranslated_list', sprintf(__("List of MSG %s to translate",'xili-dictionary'), $singular_name), array(&$this,'msg_untranslated_list_box'), XDMSG , 'normal','high');
       
   695 			add_meta_box('msg_tools_shortcuts', __("Shortcuts to update mo files",'xili-dictionary'), array(&$this,'msg_tools_shortcuts_box'), XDMSG , 'side','high');
       
   696 		}
       
   697 	}
       
   698 	
       
   699 	function mo_files_array () {
       
   700 		$this->theme_mos = $this->get_pomo_from_theme();
       
   701  		$this->local_mos = $this->get_pomo_from_theme( true ); // 2.1
       
   702  		if ( is_multisite() ) {
       
   703  			$this->file_site_mos = $this->get_pomo_from_site(); // since 1.2.0 - mo of site
       
   704  			$this->file_site_local_mos = $this->get_pomo_from_site( true ); 
       
   705  		}	
       
   706 	}
       
   707 	
       
   708 	function get_list_languages () {
       
   709 		$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' );
       
   710 		$this->languages_key_slug = array();
       
   711 	  	foreach ( $listlanguages as $language ) {
       
   712 	  		$this->languages_key_slug[$language->slug] = array ('name'=>$language->name, 'description'=>$language->description );
       
   713 	  	}
       
   714 	  	return $listlanguages;
       
   715 	}
       
   716 	
       
   717 	
       
   718 	/**
       
   719 	 * display shortcut links to update mo
       
   720 	 *
       
   721 	 * called add_meta_box('msg_tools_shortcuts'
       
   722 	 *
       
   723 	 * 
       
   724 	 */
       
   725 	function msg_tools_shortcuts_box ( $post ) {
       
   726 		$post_ID = $post->ID;
       
   727 		$lang = $this->cur_lang ( $post_ID );
       
   728 		
       
   729 	  	if ( $lang ) {
       
   730 	  		$link_theme_mo = wp_nonce_url (admin_url().'post.php?post='.$post_ID.'&action=edit&msgupdate=updatetheme&langstr='.$lang->name.'&message=33', 'xd-updatemo');
       
   731 	  		$link_local_mo = wp_nonce_url (admin_url().'post.php?post='.$post_ID.'&action=edit&msgupdate=updatelocal&langstr='.$lang->name.'&message=34', 'xd-updatemo');
       
   732 	  		if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0
       
   733 				$theme_name = get_option("stylesheet"); 
       
   734 			} else {
       
   735 				$theme_name = get_option("template"); 
       
   736 			}
       
   737 	  		echo '<p>' . sprintf(__('This msg translation is in %1$s (%2$s)','xili-dictionary'),$lang->description, $lang->name).'</p>';
       
   738 	  		echo '<h4>'. __('Updating shortcuts', 'xili-dictionary').'</h4>';
       
   739 	  		
       
   740 	  		if ( $this->count_msgids ( $lang->name, true ) > 0 ) {
       
   741 	  			echo '<p>' . sprintf('<a class="action-button blue-button" onClick="verifybefore(1)" href="%2$s" >'.__('Update','xili-dictionary').' local-%3$s.mo</a>','#', '#', $lang->name).'</p>';
       
   742 	  		} else {
       
   743 	  			echo '<p class="action-button grey-button">' . sprintf( __('No local translated msgid to be saved in %s','xili-dictionary'), ' local-'.$lang->name.'.mo' ) . '</p>';
       
   744 	  		}
       
   745 	  		
       
   746 	  		echo '<p>' . sprintf(__('It is possible to update the .mo files of current theme %s','xili-dictionary'), '<strong>'.$theme_name.'</strong>' ).'</p>';
       
   747 	  		echo '<p><em>' . __('Before to use this button, it is very important that you verify that your term list is quite achieved inside the dictionary. It is because the original .mo delivered with theme is updated (erased) !!!', 'xili-dictionary') .'</em></p>';
       
   748 	  		
       
   749 	  		if ( $this->count_msgids ( $lang->name, false, $theme_name ) > 0 ) {
       
   750 	  			echo '<p>' . sprintf('<a class="action-button grey-button" onClick="verifybefore(0)" href="%1$s" >'.__('Update','xili-dictionary').' %3$s.mo</a>','#', '#', $lang->name).'</p>'; 
       
   751 	  		} else {
       
   752 	  			echo '<p class="action-button grey-button">' . sprintf( __('No translated msgid to be saved in %s','xili-dictionary'), $lang->name.'.mo' ) . '</p>';
       
   753 	  		}
       
   754 	  		
       
   755 	  		//echo '<p>- ' . sprintf('<a href="%1$s" >%3$s.mo</a><br />- <a  href="%2$s" >'.__('local','xili-dictionary').'-%3$s.mo</a>',$link_theme_mo, $link_local_mo, $lang->name).'</p>';
       
   756 	  		echo '<small>'.$this->msg_action_message.'</small>';
       
   757 	  	} else {
       
   758 	  	
       
   759 	  		echo '<p>' . __('Links are available if a translation (msgstr) is edited.','xili-dictionary').'</p>';
       
   760 	  	}
       
   761 	  	
       
   762 	  	if ( $lang ) {
       
   763 		?>
       
   764 		
       
   765 		<p class="xdversion">XD v. <?php echo XILIDICTIONARY_VER; ?></p>
       
   766 		<script type="text/javascript">
       
   767 function verifybefore(id) {
       
   768   var link = new Array();
       
   769   
       
   770   link[0] = "<?php echo str_replace('amp;','', $link_theme_mo); ?>";
       
   771   link[1] = "<?php echo str_replace('amp;','', $link_local_mo); ?>";
       
   772   var confirmmessage = "<?php _e('Are you sure you want to update mo ? ', 'xili-dictionary'); ?>";
       
   773   var message = "Action Was Cancelled By User " ;
       
   774  
       
   775   if (confirm(confirmmessage)) {
       
   776  
       
   777       window.location = link[id];
       
   778  
       
   779   } else {
       
   780  
       
   781       // alert(message);
       
   782  
       
   783   }
       
   784  
       
   785 }
       
   786 </script>
       
   787 		<?php
       
   788 	  	}
       
   789 	}
       
   790 	
       
   791 	// add messages  called by add_filter( 'post_updated_messages' @since 2.1.2
       
   792 	function msg_post_messages ( $messages ) {
       
   793 		$messages['post'][33] = __('MO file updating started: see result in meta-box named - Shortcuts... - below buttons', 'xili-dictionary');
       
   794 		$messages['post'][34] = __('Local MO updating started: see result in meta-box named - Shortcuts... - below buttons', 'xili-dictionary');
       
   795 		return $messages;
       
   796 	}
       
   797 	
       
   798 	/**
       
   799 	 * update current .mo
       
   800 	 *
       
   801 	 * called add_action( 'add_meta_boxes_' . XDMSG
       
   802 	 *
       
   803 	 * to have values before metaboxes built
       
   804 	 */
       
   805 	function msg_update_action ( $post ) {
       
   806 		$extract_array = array();
       
   807 		$langfolderset = $this->xili_settings['langs_folder'];
       
   808 	  	$this->langfolder = ( $langfolderset !='' )  ? $langfolderset.'/' : '/';
       
   809 		// doublon 
       
   810 	  	$this->langfolder = str_replace ("//","/", $this->langfolder ); // upgrading... 2.0 and sub folder sub
       
   811 		if ( isset ($_GET['msgupdate'] ) && isset ($_GET['langstr']) ) { // shortcut to update .mo - 2.1.2
       
   812 			check_admin_referer( 'xd-updatemo' );
       
   813 			$filetype = $_GET['msgupdate'];
       
   814 			$selectlang = $_GET['langstr'];
       
   815 			
       
   816 			if ( is_multisite() ) {
       
   817 				if (($uploads = xili_upload_dir()) && false === $uploads['error'] ) {
       
   818   						
       
   819  					if ( $filetype == 'updatelocal' ) { // only current site - need tools for other superadmin place
       
   820  						$local = 'local-';
       
   821      					$extract_array [ $this->msg_extracted_comments ] = $this->local_tag;
       
   822 	     				$extract_array [ 'like-'.$this->msg_extracted_comments ] = true;
       
   823      					$file = $uploads['path']."/local-".$selectlang.".mo" ;
       
   824      					 
       
   825      				} else {
       
   826      					if ( is_child_theme() ) { 
       
   827 							$theme_name = get_option("stylesheet"); 
       
   828 						} else {
       
   829 							$theme_name = get_option("template"); 
       
   830 						}
       
   831 			     		$extract_array [ 'origin' ] = array( $theme_name ); // only if assigned to current theme domain
       
   832      					
       
   833      					$local = '';
       
   834      					$file = $uploads['path']."/".$selectlang.".mo" ;
       
   835 		     			
       
   836      				}
       
   837   					$mo = $this->from_cpt_to_POMO_wpmu ( $selectlang, 'mo', true, $extract_array );  // do diff if not superadmin
       
   838   				} 
       
   839 				
       
   840 				
       
   841 			} else { // standalone
       
   842 	     	
       
   843 		     	if ( $filetype == 'updatelocal' ) {
       
   844 		     		$local = 'local-';
       
   845 		     		$extract_array [ $this->msg_extracted_comments ] = $this->local_tag;
       
   846 		     		$extract_array [ 'like-'.$this->msg_extracted_comments ] = true;
       
   847 		     		$file = $this->get_template_directory.$this->langfolder.'local-'.$selectlang.'.mo' ;
       
   848 		     		
       
   849 		     	} else {
       
   850 		     		if ( is_child_theme() ) { 
       
   851 						$theme_name = get_option("stylesheet"); 
       
   852 					} else {
       
   853 						$theme_name = get_option("template"); 
       
   854 					}
       
   855 		     		$extract_array [ 'origin' ] = array( $theme_name );
       
   856 		     		$local = '';
       
   857 		     		$file = '';
       
   858 		     	}
       
   859 		     	$mo = $this->from_cpt_to_POMO ( $selectlang, 'mo', $extract_array );
       
   860    			}
       
   861 	     	
       
   862 	     	if ( count ($mo->entries) > 0 ){
       
   863 	     	
       
   864 	     		if ( false === $this->Save_MO_to_file ( $selectlang , $mo, $file ) ) {
       
   865 					$this->msg_action_message = sprintf('<span class="alert">'.__('Error with File %s !', 'xili-dictionary').'</span> ('.$file.')', $local.$selectlang.'.mo');
       
   866 	     		} else {
       
   867 	     			$this->msg_action_message = sprintf(__('File %1s updated with %2s msgids', 'xili-dictionary'), $local.$selectlang.'.mo', count ($mo->entries) );
       
   868 	     		}
       
   869 		
       
   870 	     	} else {
       
   871 	     		$this->msg_action_message = sprintf('<span class="alert">'.__('Nothing modified in %s, file not updated', 'xili-dictionary').'</span>', $local.$selectlang.'.mo');
       
   872 	     	}
       
   873 		}
       
   874 	}
       
   875 
       
   876 	
       
   877 	// the first lang of msgstr or false for msgid
       
   878 	function cur_lang ( $post_ID ) {
       
   879 		$langs = wp_get_object_terms( $post_ID, TAXONAME);
       
   880 		if ( ! is_wp_error( $langs ) && ! empty( $langs ) ) {
       
   881 			return $langs[0];
       
   882 		}
       
   883 		return false;
       
   884 	}
       
   885 	
       
   886 	/**
       
   887 	 * Normal metabox : List to display untranslated msgid in target lang like msgstr currently displayed
       
   888 	 *
       
   889 	 * @since 2.1.2
       
   890 	 */
       
   891 	function msg_untranslated_list_box ( $post ) {
       
   892 		$post_ID = $post->ID;
       
   893 	  	$type  = get_post_meta ( $post_ID, $this->msgtype_meta, true);
       
   894 	  	$msglang = '';
       
   895  		$message = '';
       
   896  		$arraylink = array();
       
   897  		$sortparent = (($this->subselect == '') ? '' : '&amp;tagsgroup_parent_select='.$this->subselect );
       
   898 		$listlanguages = $this->get_list_languages();
       
   899 	  	foreach ( $listlanguages as $language ) {
       
   900 	  		$arraylink[] = sprintf( '<a href="%s" >'.$language->name.'</a>', 'post.php?post='.$post_ID.'&action=edit&workinglang='.$language->slug );
       
   901 	  	}
       
   902 	  	$listlink = implode (' ', $arraylink );
       
   903 	  	$working_lang = ( isset ($_GET['workinglang']) ) ? $_GET['workinglang'] : '' ;
       
   904 	  	
       
   905 	  	if ( $type == 'msgstr' ) {
       
   906 	  		
       
   907 	  		$lang = $this->cur_lang ( $post_ID );
       
   908 	  		
       
   909 	  		if ( $lang ) $msglang = $lang->slug ;
       
   910 	  		
       
   911 	  		$this->subselect = ( $working_lang == '' ) ? $msglang : $working_lang ;
       
   912 			$this->searchtranslated = 'not';
       
   913 			$message = sprintf(__('MSGs not translated in %1$s. <em>Sub-select in %2$s</em>', 'xili-dictionary' ), $this->languages_key_slug[$this->subselect]['name'], $listlink ) ;
       
   914 			
       
   915 	  	} else { // msgid
       
   916 	  		
       
   917 	  		$this->subselect = $working_lang;
       
   918 	  		
       
   919 	  		$message = ( $working_lang == '' ) ? sprintf( __('No selection: Sub-select in %s', 'xili-dictionary' ), $listlink ) : sprintf(__('MSGs not translated in %1$s. <em>Sub-select in %2$s</em>', 'xili-dictionary' ), $_GET['workinglang'], $listlink );
       
   920 			$this->searchtranslated = ( $working_lang == '' ) ? '' : 'not' ;
       
   921 	  	}
       
   922 	  	
       
   923 	?>
       
   924 		<p><?php echo $message ; ?></p>
       
   925 		<div id="topbanner">
       
   926 		</div>
       
   927 		<div id="tableupdating">
       
   928 		</div>
       
   929 		
       
   930 		<table class="display" id="linestable">
       
   931 			<thead>
       
   932 				<tr>
       
   933 					<th scope="col" class="center colid"><a href="<?php echo $this->xd_settings_page; ?>" ><?php _e('ID') ?></a></th>
       
   934 					<th scope="col" class="coltexte"><a href="<?php echo $this->xd_settings_page.'&amp;orderby=name'.$sortparent; ?>"><?php _e('Text') ?></a>
       
   935 					</th>
       
   936 					<th scope="col" class="colslug"><?php _e('Metas','xili-dictionary') ?></th>
       
   937 					<th scope="col" class="colgroup center"><?php _e('Save status','xili-dictionary') ?></th>
       
   938 					<th colspan="2"><?php _e('Action') ?></th>
       
   939 				</tr>
       
   940 			</thead>
       
   941 			<tbody id="the-list">
       
   942 					<?php 
       
   943 					
       
   944 					$this->xili_dict_cpt_row(); /* the lines */
       
   945 					?>
       
   946 			</tbody>
       
   947 		</table>
       
   948 		<div id="bottombanner">
       
   949 		</div> 
       
   950 		<?php
       
   951 		$this->insert_js_for_datatable( array('swidth2'=>'50%') );
       
   952 	}
       
   953 	
       
   954 	/**
       
   955 	 * insert js for datatable - used in post and in tools
       
   956 	 *
       
   957 	 * @since 2.1.2
       
   958 	 *
       
   959 	 */
       
   960 	
       
   961 	function insert_js_for_datatable( $args ) {
       
   962 		?>
       
   963 		<script type="text/javascript">
       
   964 				
       
   965 			//<![CDATA[
       
   966 			jQuery(document).ready( function($) {
       
   967 				
       
   968 				var termsTable = $('#linestable').dataTable( {
       
   969 					"iDisplayLength": 20,
       
   970 					"bStateSave": true,
       
   971 					"bAutoWidth": false,
       
   972 					"sDom": '<"topbanner"ipf>rt<"bottombanner"lp><"clear">',
       
   973 					"sPaginationType": "full_numbers",
       
   974 					"aLengthMenu": [[20, 30, 60, -1], [20, 30, 60, "<?php _e('All lines','xili-dictionary') ?>"]],
       
   975 					"oLanguage": {
       
   976 						"oPaginate": {
       
   977 							"sFirst": "<?php _e('First','xili-dictionary') ?>",
       
   978 							"sLast": "<?php _e('Last page','xili-dictionary') ?>",
       
   979 							"sNext": "<?php _e('Next','xili-dictionary') ?>",
       
   980 							"sPrevious": "<?php _e('Previous','xili-dictionary') ?>"
       
   981 						},
       
   982 						"sInfo": "<?php _e('Showing (_START_ to _END_) of _TOTAL_ entries','xili-dictionary') ?>",
       
   983 						"sInfoFiltered": "<?php _e('(filtered from _MAX_ total entries)','xili-dictionary') ?>",
       
   984 						"sLengthMenu": "<?php _e('Show _MENU_ entries','xili-dictionary') ?>",
       
   985 						"sSearch": "<?php _e('Filter terms:','xili-dictionary') ?>"
       
   986 
       
   987 					},	
       
   988 					"aaSorting": [[1,'asc']],
       
   989 					"aoColumns": [ 
       
   990 						{ "bSearchable": false, "sWidth" : "30px" },
       
   991 						{ "sWidth" : "<?php echo $args['swidth2']; ?>" },
       
   992 						{ "bSortable": false, "bSearchable": false  },
       
   993 						{ "bSortable": false, "bSearchable": false,  "sWidth" : "105px" },
       
   994 						{ "bSortable": false, "bSearchable": false, "sWidth" : "70px" } ]
       
   995 				} );
       
   996 				
       
   997 				// close postboxes that should be closed
       
   998 				$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
       
   999 				// postboxes setup
       
  1000 				postboxes.add_postbox_toggles('<?php echo $this->thehook; ?>');
       
  1001 				// for text_area list
       
  1002 				});
       
  1003 			//]]>
       
  1004 		</script> 
       
  1005 		
       
  1006 		<?php
       
  1007 		
       
  1008 	}
       
  1009 	
       
  1010 	
       
  1011 	function msg_state_box () {
       
  1012 	  global $post_ID, $post ;
       
  1013 	  
       
  1014 	  $type  = get_post_meta ( $post_ID, $this->msgtype_meta, true);
       
  1015 	  //error_log (  '----'.$this->langfolder);
       
  1016 	  //$langfolderset = $this->xili_settings['langs_folder'];
       
  1017 	  //$this->langfolder = ( $langfolderset !='' )  ? $langfolderset.'/' : '/';
       
  1018 		// doublon 
       
  1019 	  //$this->langfolder = str_replace ("//","/", $this->langfolder ); // upgrading... 2.0 and sub folder sub
       
  1020 	  $this->mo_files_array (); //error_log( serialize( $this->theme_mos ));
       
  1021 	  
       
  1022 	  ?>
       
  1023 <div id="msg-states">
       
  1024 	  <?php
       
  1025 	  
       
  1026 	  $this->msg_status_display ( $post_ID ); 
       
  1027 	  
       
  1028 	  ?>
       
  1029 </div>
       
  1030 <div id="msg-states-comments">
       
  1031 	  <?php
       
  1032 	  $for_bottom_box = $this->msg_status_comments ( $post_ID );
       
  1033 	 	?>
       
  1034 </div>
       
  1035 <div id="msg-states-actions" >
       
  1036 	<strong><?php _e( 'Informations and actions about files .po / mo', 'xili-dictionary' ); echo ':</strong><br />'; ?>
       
  1037 	<div class="msg-states-actions-left" >
       
  1038 	<?php echo $for_bottom_box['link'] .'<br />'; ?>
       
  1039 	<?php $origins = get_the_terms( $post_ID, 'origin' ); 
       
  1040 	$names = array();
       
  1041 	if ( $origins ) {
       
  1042 		foreach ( $origins as $origin ) {
       
  1043 			$names[] = $origin->name;
       
  1044 		}
       
  1045 		echo __( 'Come from theme(s):', 'xili-dictionary') .' '. implode (' ', $names).'<br />';;
       
  1046 	} else {
       
  1047 		if ( !$for_bottom_box['state'] ) {
       
  1048 			if ( $type == 'msgid' ) _e ( 'Not yet assigned', 'xili-dictionary') ;
       
  1049 		}
       
  1050 	} ?>
       
  1051 	</div>
       
  1052 	<div class="msg-states-actions-right" >
       
  1053 	<?php
       
  1054  		$context  = get_post_meta ( $post_ID, $this->ctxt_meta, true);
       
  1055  		$res = $this->is_saved_cpt_in_theme( htmlspecialchars_decode ($post->post_content), $type, $context );
       
  1056 		$save_state = '<br />'. ( ( false === strpos ( $res[0], '**</span>' ) ) ? sprintf( __('theme folder %s','xili-dictionary') ,$res[0]) : ''  ) . ( ( false == strpos ( $res[2], '?</span>' ) ) ? ' (local: '.$res[2].')' : '' ); 
       
  1057  		if ( is_multisite() ) $save_state .= '<br />'. __('this site','xili-dictionary') . ( ( false === strpos ( $res[1], '**</span>' ) ) ? sprintf( __('folder %s','xili-dictionary') ,$res[1]) : ' ' )  . ( ( false == strpos ( $res[3], '?</span>' ) ) ? ' (local: '.$res[3].')' : '' );
       
  1058  		
       
  1059  		echo $type.' <em>' . $post->post_content . '</em> ' . __('saved in ','xili-dictionary') . $save_state;
       
  1060 		
       
  1061 	?>
       
  1062 	</div>
       
  1063 	<p class="xdversion">XD v. <?php echo XILIDICTIONARY_VER; ?></p>
       
  1064 </div>
       
  1065 	  <?php
       
  1066 	}
       
  1067 	
       
  1068 	/**
       
  1069 	 * test unique content for msgid + context
       
  1070 	 *
       
  1071 	 * @since 2.0
       
  1072 	 * @return ID is true
       
  1073 	 */
       
  1074 	function msgid_exists ( $content = "", $ctxt = null ) {
       
  1075 		global $wpdb;
       
  1076 		if ( $content != "" ) {
       
  1077 			if ( null == $ctxt) {
       
  1078 				$posts_query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_content = %s AND post_type = %s", $content, XDMSG );
       
  1079 				
       
  1080 			} else {
       
  1081 				$posts_query = $wpdb->prepare("SELECT ID FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) INNER JOIN $wpdb->postmeta as mt1 ON ($wpdb->posts.ID = mt1.post_id) WHERE post_content = %s AND post_type = %s AND $wpdb->postmeta.meta_key= '{$this->ctxt_meta}' AND mt1.meta_key= '{$this->ctxt_meta}' AND mt1.meta_value = %s ", $content, XDMSG, $ctxt);
       
  1082 			}
       
  1083 			// 2.2.0
       
  1084 			$found_posts = $wpdb->get_col($posts_query);
       
  1085 			if ( empty($found_posts) ) {
       
  1086 			   return false;	  
       
  1087 			} else {
       
  1088 			   return $found_posts;
       
  1089 			}
       
  1090 		}
       
  1091 		 
       
  1092 	}
       
  1093 	/**
       
  1094 	 * test unique content for msgstr + msgid + language
       
  1095 	 *
       
  1096 	 * @since 2.0
       
  1097 	 * @return ID is true
       
  1098 	 */
       
  1099 	function msgstr_exists ( $content = "", $msgid, $curlang ) {
       
  1100 		global $wpdb;
       
  1101 		if ( "" != $content) {
       
  1102 			$posts_query = $wpdb->prepare("SELECT ID FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) INNER JOIN $wpdb->postmeta as mt1 ON ($wpdb->posts.ID = mt1.post_id) WHERE post_content = %s AND post_type = %s AND $wpdb->postmeta.meta_key='{$this->msgidlang_meta}' AND mt1.meta_key='{$this->msgidlang_meta}' AND mt1.meta_value = %s ", $content, XDMSG, $msgid);
       
  1103 		
       
  1104 		
       
  1105 			$found_posts = $wpdb->get_col($posts_query);
       
  1106 			if ( empty($found_posts) ) {
       
  1107 		   		return false;	  
       
  1108 			} else {
       
  1109 				
       
  1110 				if ( in_array ( $curlang , wp_get_object_terms( $found_posts, TAXONAME, array ( 'fields' => 'names' ) ) ) ) {
       
  1111 					// select only this with $curlang 
       
  1112 					return $found_posts ;
       
  1113 					
       
  1114 				} else {
       
  1115 		   			return false;
       
  1116 				}
       
  1117 		   		
       
  1118 			}	
       
  1119 		}
       
  1120 		return false;  
       
  1121 	}
       
  1122 	
       
  1123 	/**
       
  1124 	 * import po and mo in cpts series
       
  1125 	 *
       
  1126 	 * @since 2.0
       
  1127 	 * @return 
       
  1128 	 */
       
  1129 	function from_pomo_to_cpts ( $po, $curlang = 'en_US' ) {
       
  1130 		$nblines = array( 0, 0); // id, str count
       
  1131 		$this->importing_mode = true ;
       
  1132 		foreach ( $po->entries as $pomsgid => $pomsgstr ) {
       
  1133 			// test if msgid exists
       
  1134 			$result = $this->msgid_exists ( $pomsgstr->singular, $pomsgstr->context ) ;
       
  1135 			
       
  1136 			if ( $result === false ) {
       
  1137 				// create the msgid
       
  1138 				$type = 'msgid';
       
  1139 				$msgid_post_ID = $this->insert_one_cpt_and_meta( $pomsgstr->singular, $pomsgstr->context, $type, 0, $pomsgstr ) ;
       
  1140 				$nblines[0]++ ;
       
  1141 			} else {
       
  1142 				$msgid_post_ID = $result[0];
       
  1143 				if ( $this->importing_po_comments != '' ) {
       
  1144 					$this->insert_comments( $msgid_post_ID, $pomsgstr, $this->importing_po_comments );
       
  1145 				}
       
  1146 				
       
  1147 			}
       
  1148 			
       
  1149 			// add origin taxonomy
       
  1150 			if ( ''!= $this->origin_theme ) 
       
  1151 				wp_set_object_terms( $msgid_post_ID, $this->origin_theme, 'origin', true ); // true to append to existing
       
  1152 			
       
  1153 			if ( $pomsgstr->is_plural != null ) {
       
  1154 				// create msgid plural (child of msgid)
       
  1155 				// $pomsgstr->plural, $msgid_post_ID
       
  1156 				$result = $this->msgid_exists ( $pomsgstr->plural ) ;
       
  1157 				if ( $result === false ) 
       
  1158 				      $msgid_post_ID_plural = $this->insert_one_cpt_and_meta( $pomsgstr->plural, null, 'msgid_plural' , $msgid_post_ID, $pomsgstr );
       
  1159 				
       
  1160 			}
       
  1161 			
       
  1162 			// create msgstr - taxonomy 
       
  1163 			
       
  1164 			if ( $pomsgstr->is_plural == null ) {
       
  1165 				
       
  1166 				$msgstr_content = ( isset( $pomsgstr->translations[0]) ) ? $pomsgstr->translations[0] : "" ;
       
  1167 				if ( $msgstr_content != "" ) {
       
  1168 					// test exists with taxo before
       
  1169 					$result = $this->msgstr_exists ( $msgstr_content, $msgid_post_ID, $curlang ) ;
       
  1170 					if ( $result === false ) {
       
  1171 						$msgstr_post_ID = $this->insert_one_cpt_and_meta( $msgstr_content, null, 'msgstr', 0, $pomsgstr );
       
  1172 						wp_set_object_terms( $msgstr_post_ID, $curlang, TAXONAME );
       
  1173 						$nblines[1]++ ;
       
  1174 					} else {
       
  1175 						$msgstr_post_ID = $result[0];
       
  1176 					}
       
  1177 				
       
  1178 				// create link according lang
       
  1179 				
       
  1180 					$res = get_post_meta ( $msgid_post_ID, $this->msglang_meta, false );
       
  1181 					$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  1182 					$thelangs['msgstrlangs'][$curlang]['msgstr'] = $msgstr_post_ID;
       
  1183 					update_post_meta ( $msgid_post_ID, $this->msglang_meta, $thelangs );
       
  1184 					update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $msgid_post_ID );
       
  1185 				}
       
  1186 				
       
  1187 				
       
  1188 			} else {
       
  1189 				// $pomsgstr->translations 
       
  1190 				$i=0; $parentplural = 0;
       
  1191 				foreach ( $pomsgstr->translations as $onetranslation ) {
       
  1192 					$msgstr_plural = 'msgstr_' . $i ;
       
  1193 					$parent = ( $i == 0 ) ? 0 : $parentplural ;
       
  1194 					if ( $onetranslation != "" ) {
       
  1195 						// test exists with taxo before
       
  1196 						$result = $this->msgstr_exists ( $onetranslation, $msgid_post_ID, $curlang ) ;
       
  1197 						if ( $result === false ) {
       
  1198 					 		$msgstr_post_ID_plural = $this->insert_one_cpt_and_meta( $onetranslation, null, $msgstr_plural , $parent, $pomsgstr );
       
  1199 							wp_set_object_terms( $msgstr_post_ID_plural, $curlang, TAXONAME );
       
  1200 							$nblines[1]++ ;
       
  1201 						} else {
       
  1202 							$msgstr_post_ID_plural = $result[0];
       
  1203 						}
       
  1204 						update_post_meta ( $msgstr_post_ID_plural, $this->msgidlang_meta, $msgid_post_ID );
       
  1205 					}
       
  1206 			 
       
  1207 					if ( $i == 0 ) { 
       
  1208 						$parentplural = $msgstr_post_ID_plural; 
       
  1209 						
       
  1210 						// create link according lang in msgid
       
  1211 						$res = get_post_meta ( $msgid_post_ID, $this->msglang_meta, false );
       
  1212 						$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  1213 						$thelangs['msgstrlangs'][$curlang][$msgstr_plural] = $msgstr_post_ID_plural;
       
  1214 						update_post_meta ( $msgid_post_ID, $this->msglang_meta, $thelangs );
       
  1215 												
       
  1216 					} // only first str
       
  1217 					
       
  1218 					$i++;
       
  1219 				}
       
  1220 			}
       
  1221 			
       
  1222 		}
       
  1223 		$this->importing_mode = false ;
       
  1224 		return $nblines;	
       
  1225 	}
       
  1226 	
       
  1227 	/**
       
  1228 	 * import a msg line 
       
  1229 	 *
       
  1230 	 * @since 2.0
       
  1231 	 *
       
  1232 	 * @updated 2.1.2
       
  1233 	 *
       
  1234 	 * @return ID
       
  1235 	 */
       
  1236 	function insert_one_cpt_and_meta ( $content, $context = null, $type , $parent = 0, $entry = null  ) {
       
  1237 		global $user_ID;
       
  1238 		/* 	if (!empty($entry->translator_comments)) $po[] = PO::comment_block($entry->translator_comments);
       
  1239 				if (!empty($entry->extracted_comments)) $po[] = PO::comment_block($entry->extracted_comments, '.');
       
  1240 				if (!empty($entry->references)) $po[] = PO::comment_block(implode(' ', $entry->references), ':');
       
  1241 				if (!empty($entry->flags)) $po[] = PO::comment_block(implode(", ", $entry->flags), ',');
       
  1242 			*/
       
  1243 		if ( null != $entry ) {
       
  1244 			$references = (!empty($entry->references)) ? implode ( ' #: ' ,  $entry->references ) : '' ;
       
  1245 			$flags = (!empty($entry->flags)) ? implode ( ', ' ,  $entry->flags ) : '' ;
       
  1246 			$extracted_comments =  (!empty($entry->extracted_comments)) ? $entry->extracted_comments : '' ;
       
  1247 			$translator_comments = (!empty($entry->translator_comments)) ? $entry->translator_comments : '' ;
       
  1248 		} else {
       
  1249 			$references = "";
       
  1250 			$flags = "";
       
  1251 			$extracted_comments = "";
       
  1252 			$translator_comments = "";
       
  1253 			
       
  1254 		} 
       
  1255 		
       
  1256 		$params = array('post_status' => 'publish', 'post_type' => XDMSG, 'post_author' => $user_ID,
       
  1257 		'ping_status' => get_option('default_ping_status'), 'post_parent' => $parent,
       
  1258 		'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',
       
  1259 		'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => $references, 'import_id' => 0,
       
  1260 		'post_content' => $content, 'post_title' => '');
       
  1261 		
       
  1262 		$post_id = wp_insert_post( $params ) ;
       
  1263 		
       
  1264 		if ( $post_id != 0 ) {
       
  1265 			if ( $context != null ) // postmeta
       
  1266 				update_post_meta ( $post_id, $this->ctxt_meta, $context );
       
  1267 		
       
  1268 		// type postmeta
       
  1269 		
       
  1270 			update_post_meta ( $post_id, $this->msgtype_meta, $type );
       
  1271 			
       
  1272 			if ( $type == 'msgid' ) {
       
  1273 				if ( $extracted_comments != "" ) update_post_meta ( $post_id, $this->msg_extracted_comments, $extracted_comments );
       
  1274 				if ( $translator_comments != "") update_post_meta ( $post_id, $this->msg_translator_comments, $translator_comments );
       
  1275 				if ( $flags != "") 
       
  1276 					update_post_meta ( $post_id, $this->msg_flags, $flags );
       
  1277 				update_post_meta ( $post_id, $this->msglang_meta, array() ); // 2.1.2
       
  1278 			}
       
  1279 			
       
  1280 			if ( $type == 'msgstr' || $type == 'msgstr_0' ) {
       
  1281 				if ( $translator_comments != "") update_post_meta ( $post_id, $this->msg_translator_comments, $translator_comments );
       
  1282 			}
       
  1283 		// update postmeta children
       
  1284 		// create array
       
  1285 			if ( $parent != 0 ) {
       
  1286 				
       
  1287 				$res = get_post_meta ( $parent, $this->msgchild_meta, false );
       
  1288 				$thechilds =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  1289 				if ( $type == 'msgid_plural' ) {
       
  1290 					$thechilds['msgid']['plural'] = $post_id;
       
  1291 					
       
  1292 				} elseif ( $type != 'msgstr' ){
       
  1293 					$indices = explode ('_', $type);
       
  1294 					$thechilds['msgstr']['plural'][$indices[1]] = $post_id;
       
  1295 				}	
       
  1296 		
       
  1297 				update_post_meta ( $parent, $this->msgchild_meta, $thechilds );
       
  1298 				
       
  1299 			}
       
  1300 		}
       
  1301 		return $post_id;
       
  1302 	}
       
  1303 	
       
  1304 	/**
       
  1305 	 * insert comments of msgid / msgstr
       
  1306 	 *
       
  1307 	 * called by from_pomo_to_cpts
       
  1308 	 *
       
  1309 	 */
       
  1310 	function insert_comments( $post_id, $entry, $import_comment_mode = 'replace' ) {
       
  1311 		
       
  1312 		$references = (!empty($entry->references)) ? implode ( ' #: ' ,  $entry->references ) : '' ;
       
  1313 		$flags = (!empty($entry->flags)) ? implode ( ', ' ,  $entry->flags ) : '' ;
       
  1314 		$extracted_comments =  (!empty($entry->extracted_comments)) ? $entry->extracted_comments : '' ;
       
  1315 		$translator_comments = (!empty($entry->translator_comments)) ? $entry->translator_comments : '' ;
       
  1316 		
       
  1317 		if ( $import_comment_mode == 'replace' ) {
       
  1318 			// update references in excerpt
       
  1319 			$postarr = wp_get_single_post( $post_id, ARRAY_A ) ;
       
  1320 			
       
  1321 			$postarr['post_excerpt'] = $references;
       
  1322 			
       
  1323 			wp_insert_post( $postarr );
       
  1324 			
       
  1325 			// update comments in meta
       
  1326 			if ( $extracted_comments != "" ) update_post_meta ( $post_id, $this->msg_extracted_comments, $extracted_comments );
       
  1327 			if ( $translator_comments != "") update_post_meta ( $post_id, $this->msg_translator_comments, $translator_comments );
       
  1328 			if ( $flags != "") update_post_meta ( $post_id, $this->msg_flags, $flags );
       
  1329 		
       
  1330 		} elseif ( $import_comment_mode == 'append' ) { // don't erase existing comments - can be risked
       
  1331 			
       
  1332 			
       
  1333 		}
       
  1334 		
       
  1335 	}
       
  1336 	
       
  1337 	/**
       
  1338 	 * new columns in cpt list
       
  1339 	 *
       
  1340 	 */
       
  1341 	function xili_manage_column_name( $columns ) { // must be verified
       
  1342 	
       
  1343 		if ( isset ( $_GET['post_type'] ) &&  $_GET['post_type'] == XDMSG )   { 
       
  1344 		 	$ends = array('author', 'date', 'rel', 'visible');
       
  1345 			$end = array(); 
       
  1346 			foreach( $columns AS $k=>$v ) {
       
  1347 				if ( in_array($k, $ends) ) {
       
  1348 					$end[$k] = $v;
       
  1349 					unset($columns[$k]);
       
  1350 				}
       
  1351 			}
       
  1352 			$columns['msgcontent'] = __('Content','xili-dictionary'); // ? sortable ?
       
  1353 			$columns['msgpostmeta'] = __('Metas','xili-dictionary');
       
  1354 			if ( !class_exists ( 'xili_language' ) ) {
       
  1355 				$columns[TAXONAME] = __('Language','xili-dictionary');
       
  1356 			}
       
  1357 			$columns = array_merge($columns, $end);
       
  1358 		}
       
  1359 		return $columns;
       
  1360 		
       
  1361 	}
       
  1362 	
       
  1363 	function xili_manage_column_row  ( $column , $id ) {
       
  1364 		global $post;
       
  1365 		
       
  1366 		if ($column == 'msgcontent' && $post->post_type == XDMSG ) 
       
  1367 			echo htmlspecialchars( $post->post_content );
       
  1368 		if ($column == 'msgpostmeta' && $post->post_type == XDMSG ) {	
       
  1369 			
       
  1370 			$this->msg_link_display ( $id );
       
  1371 		}
       
  1372 		if ($column == 'language' && $post->post_type == XDMSG ) {
       
  1373 			if ( !class_exists ( 'xili_language' ) ) {
       
  1374 				
       
  1375 				$lang = $this->cur_lang( $id );
       
  1376  				echo $lang->name;	
       
  1377 				
       
  1378 			}
       
  1379 		}
       
  1380 		
       
  1381 		return;
       
  1382 		
       
  1383 	}
       
  1384 	
       
  1385 	// Register the column as sortable
       
  1386 	function msgcontent_column_register_sortable( $columns ) {
       
  1387 		$columns['msgcontent'] = 'msgcontent';
       
  1388  		$columns['msgpostmeta'] = 'msgpostmeta';	
       
  1389 		return $columns;
       
  1390 	}
       
  1391 	
       
  1392 	function msgcontent_column_orderby( $vars ) {
       
  1393 		if ( isset( $vars['orderby'] ) && 'msgpostmeta' == $vars['orderby'] ) {
       
  1394 			$vars = array_merge( $vars, array(
       
  1395 				'meta_key' => $this->msgtype_meta,
       
  1396 				'orderby' => 'meta_value'
       
  1397 			) );
       
  1398 		}
       
  1399  
       
  1400 		return $vars;
       
  1401 	}	
       
  1402 	
       
  1403 	/**
       
  1404 	 * Add Languages selector in edit.php edit after Category Selector (hook: restrict_manage_posts) only if no XL
       
  1405 	 *
       
  1406 	 * @since 2.0
       
  1407 	 *
       
  1408 	 */
       
  1409 	function restrict_manage_languages_posts () {
       
  1410 		$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
       
  1411 		?>
       
  1412 <select name="lang" id="lang" class='postform'>
       
  1413 	<option value=""> <?php _e('View all languages','xili-dictionary') ?> </option>
       
  1414 			
       
  1415 			<?php foreach ($listlanguages as $language)  {
       
  1416 				$selected = ( isset ( $_GET[QUETAG] ) && $language->slug == $_GET[QUETAG] ) ? "selected=selected" : "" ;
       
  1417 				echo '<option value="'.$language->slug.'" '.$selected.' >'.__($language->description, 'xili-dictionary').'</option>';
       
  1418 			}
       
  1419 			?>
       
  1420 </select>
       
  1421 		<?php
       
  1422 	}
       
  1423 	
       
  1424 	/**
       
  1425 	 * Add Origin selector in edit.php edit 
       
  1426 	 *
       
  1427 	 * @since 2.0
       
  1428 	 *
       
  1429 	 */
       
  1430 	function restrict_manage_origin_posts () {
       
  1431 		if ( isset ( $_GET['post_type'] ) && $_GET['post_type'] == XDMSG ) {
       
  1432 			$listorigins = get_terms('origin', array('hide_empty' => false));
       
  1433 			if ( $listorigins != array() )  {
       
  1434 				$selected = "";
       
  1435 				if ( isset ( $_GET['origin'] )  ) { 
       
  1436 					$selected = $_GET['origin'];
       
  1437 				}
       
  1438 				$dropdown_options = array(
       
  1439 						'taxonomy' => 'origin',
       
  1440 						'show_option_all' => __( 'View all origins', 'xili-dictionary' ),
       
  1441 						'hide_empty' => 0,
       
  1442 						'hierarchical' => 1,
       
  1443 						'show_count' => 0,
       
  1444 						'orderby' => 'name',
       
  1445 						'name' => 'origin',
       
  1446 						'selected' => $selected
       
  1447 					);
       
  1448 				wp_dropdown_categories( $dropdown_options );
       
  1449 			}
       
  1450 		}
       
  1451 	}
       
  1452 	
       
  1453 	/**
       
  1454 	 * Add writer selector in edit.php edit 
       
  1455 	 *
       
  1456 	 * @since 2.0
       
  1457 	 *
       
  1458 	 */
       
  1459 	function restrict_manage_writer_posts () {
       
  1460 		if ( isset ( $_GET['post_type'] ) && $_GET['post_type'] == XDMSG ) {
       
  1461 			$listwriters = get_terms('writer', array('hide_empty' => false));
       
  1462 			if ( $listwriters != array() )  {
       
  1463 				$selected = "";
       
  1464 				if ( isset ( $_GET['writer_name'] )  ) { 
       
  1465 					$selected = $_GET['writer_name'];
       
  1466 				}
       
  1467 				$dropdown_options = array(
       
  1468 						'taxonomy' => 'writer',
       
  1469 						'show_option_all' => __( 'View all writers', 'xili-dictionary' ),
       
  1470 						'hide_empty' => 0,
       
  1471 						'hierarchical' => 1,
       
  1472 						'show_count' => 0,
       
  1473 						'orderby' => 'name',
       
  1474 						'name' => 'writer_name',
       
  1475 						'selected' => $selected
       
  1476 					);
       
  1477 				wp_dropdown_categories( $dropdown_options );
       
  1478 			}
       
  1479 		}
       
  1480 	}
       
  1481 	
       
  1482 	/** 
       
  1483 	 * to fixes wp_dropdown_categories id value in option
       
  1484 	 * thanks to http://wordpress.stackexchange.com/questions/6066/query-custom-taxonomy-by-term-id 
       
  1485 	 */
       
  1486 	function wpse6066_pre_get_posts( &$wp_query ) {
       
  1487 		
       
  1488     	if ( $wp_query->is_tax ) {  ;
       
  1489         	if ( is_numeric( $wp_query->get( 'writer_name' ) ) ) {
       
  1490             	// Convert numberic terms to term slugs for dropdown
       
  1491             	
       
  1492             	$term = get_term_by( 'term_id', $wp_query->get( 'writer_name' ), 'writer' );
       
  1493          
       
  1494             	if ( $term ) {
       
  1495                 	$wp_query->set( 'writer_name', $term->slug );
       
  1496             	}
       
  1497         	} 
       
  1498         	
       
  1499         	if ( is_numeric( $wp_query->get( 'origin' ) ) ) {
       
  1500         		
       
  1501         		// Convert numberic terms to term slugs for dropdown
       
  1502             	
       
  1503             	$term = get_term_by( 'term_id', $wp_query->get( 'origin' ), 'origin' );
       
  1504          
       
  1505             	if ( $term ) {
       
  1506                 	$wp_query->set( 'origin', $term->slug );
       
  1507             	}
       
  1508         	}
       
  1509     	}
       
  1510 	}
       
  1511 
       
  1512 	
       
  1513 	/**
       
  1514 	 * display msg comments
       
  1515 	 *
       
  1516 	 * @param post ID 
       
  1517 	 *
       
  1518 	 */
       
  1519 	function msg_status_comments ( $id ) {
       
  1520 		
       
  1521 		$type  = get_post_meta ( $id, $this->msgtype_meta, true);
       
  1522 		// search msgid
       
  1523 		if ( $type == 'msgid' ) {
       
  1524 			$target_id = $id;
       
  1525 		} elseif ( $type == 'msgid_plural' ) {
       
  1526 			$temp_post = $this->temp_get_post ( $id );
       
  1527 			$target_id = $temp_post->post_parent;
       
  1528 		} else {
       
  1529 			$target_id = get_post_meta ( $id, $this->msgidlang_meta, true);	
       
  1530 		}
       
  1531 		$for_bottom_box = array('link'=> '','state' => false );
       
  1532 		if ( $temp_post = $this->temp_get_post ( $target_id ) ) {
       
  1533 		
       
  1534 			$ctxt = get_post_meta ( $target_id, $this->ctxt_meta, true );
       
  1535 			if ( $ctxt != "" && $type != 'msgid' ) printf ( '<strong>ctxt:</strong> %s <br /><br />'  , $ctxt );
       
  1536 			if ( $type == 'msgid' ) {
       
  1537 				if ( isset ($_GET['msgaction'] ) && $_GET['msgaction'] == 'addctxt' ) {
       
  1538 					?>
       
  1539 <label for="add_ctxt"><?php _e('Context','xili-dictionary') ; ?></label>
       
  1540 <input id="add_ctxt" name="add_ctxt"  value="<?php echo $ctxt; ?>" style="width:80%" />
       
  1541 					<?php
       
  1542 					
       
  1543 				} else {
       
  1544 					if ( $ctxt != "" ) { 
       
  1545 						printf ( '<strong>ctxt:</strong> %s <br /><br />'  , $ctxt );
       
  1546 						printf( __('&nbsp;<a href="%s" >Edit context</a>', 'xili-dictionary'), 'post.php?post='.$id.'&action=edit&msgaction=addctxt' );
       
  1547 					} else {
       
  1548 						// link to add ctxt
       
  1549 						printf( __('&nbsp;<a href="%s" >Create context</a>', 'xili-dictionary'), 'post.php?post='.$id.'&action=edit&msgaction=addctxt' );
       
  1550 						
       
  1551 					}
       
  1552 				}
       
  1553 			}
       
  1554 			// local or not
       
  1555 			$linktotax ='';
       
  1556 			$extracted_comments = get_post_meta ( $target_id, $this->msg_extracted_comments, true );
       
  1557 			if ( $extracted_comments != "" ) {
       
  1558 				
       
  1559 				$pattern = '/([^local\]].*?)from\s(.*?)\swith/';
       
  1560 				$matches = array();
       
  1561 				if ( 1 == preg_match($pattern, $extracted_comments, $matches) ) {
       
  1562 					
       
  1563 					$search = '';
       
  1564 					if ( $type == 'msgid' && false !== strpos( $extracted_comments, 'name from' ) )
       
  1565 						$search = '&s='.str_replace(' ', '+', $temp_post->post_content );
       
  1566 					
       
  1567 					$linktotax = sprintf('<a href="%1s" >%2s</a>', 'edit-tags.php?taxonomy='.$matches[2].'&post_type=post'.$search, sprintf(__('Return to %s list', 'xili-dictionary'), $matches[2] ));
       
  1568 				
       
  1569 				}
       
  1570 			}
       
  1571 			
       
  1572 			echo '<p>';
       
  1573 				
       
  1574 				if ( $extracted_comments != "" )  
       
  1575 					printf ( __('Extracted comments: %s', 'xili-dictionary').'<br />', $extracted_comments );
       
  1576 				
       
  1577 				$translator_comments = get_post_meta ( $target_id, $this->msg_translator_comments, true );
       
  1578 				if ( $translator_comments != "") printf ( __('Translator comments: %s', 'xili-dictionary').'<br />', $translator_comments );
       
  1579 				$flags = get_post_meta ( $target_id, $this->msg_flags, true );
       
  1580 				if ( $flags != "") printf ( __('Flags: %s', 'xili-dictionary').'<br />', $flags );
       
  1581 			
       
  1582 			echo '</p>';	
       
  1583 			if ( $type == 'msgstr' || $type == 'msgstr_0' ) {
       
  1584 				$translator_comments = get_post_meta ( $id, $this->msg_translator_comments, true );
       
  1585 				//if ( $translator_comments != "") printf ( __('Msgstr Translator comments: %s', 'xili-dictionary').'<br />', $translator_comments );
       
  1586 				
       
  1587 				?>
       
  1588 <label for="add_translator_comments"><?php _e('msgstr Translator comments','xili-dictionary') ; ?></label>
       
  1589 <input id="add_translator_comments" name="add_translator_comments"  value="<?php echo $translator_comments; ?>" style="width:80%" />
       
  1590 				<?php
       
  1591 			}
       
  1592 			
       
  1593 			
       
  1594 			$lines = $temp_post->post_excerpt;
       
  1595 			if ( $lines != "") {
       
  1596 				echo '<p>'; 
       
  1597 				printf ( __('Lines: %s', 'xili-dictionary').'<br />', $lines ); 
       
  1598 				echo '</p>';
       
  1599 			}
       
  1600 			echo '<p><strong>'.sprintf(__('Return to <a href="%s" title="Go to msg list">msg list</a>','xili-dictionary'), $this->xd_settings_page).'</strong> '.$linktotax.'</p>';
       
  1601 			echo ( $this->create_line_lang != "" ) ? '<p><strong>'.$this->create_line_lang.'</strong></p>' : "-";
       
  1602 			
       
  1603 			
       
  1604 			if ( $type == 'msgid' ) { 
       
  1605 				if ( ( $extracted_comments == "" ) ||  ( $extracted_comments != "" && false === strpos( $extracted_comments, $this->local_tag .' ' ) ) ) {
       
  1606 					
       
  1607 					$nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=setlocal', 'xd-setlocal'  ) ;
       
  1608 					
       
  1609  					$for_bottom_box['link'] = sprintf( __('Set in theme (<a href="%s" >set local</a>)', 'xili-dictionary'), $nonce_url );
       
  1610 					
       
  1611 				} else {
       
  1612 					$nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=unsetlocal', 'xd-setlocal'  ) ;
       
  1613 					
       
  1614 					$for_bottom_box['link'] = sprintf( __('Set in local (<a href="%s" >unset</a>)', 'xili-dictionary'), $nonce_url );
       
  1615 					$for_bottom_box['state'] = true; // false by default
       
  1616 				}
       
  1617 			}
       
  1618 			
       
  1619 			
       
  1620 		} else {
       
  1621 			printf ( __('The msgid (%d) was deleted. The msg series must be recreated and commented.','xili-dictionary' ), $target_id );
       
  1622 			echo '<p><strong>'.sprintf(__('Return to <a href="%s" title="Go to msg list">msg list</a>','xili-dictionary'), $this->xd_settings_page).'</strong></p>';
       
  1623 		}
       
  1624 		return $for_bottom_box ;
       
  1625 	}
       
  1626 	
       
  1627 	function update_msg_comments ( $post_id ) {
       
  1628 		if ( get_post_type( $post_id ) == XDMSG ) {
       
  1629 			// only visible if msgstr
       
  1630 			$translator_comments = ( isset ( $_POST['add_translator_comments'] )) ? $_POST['add_translator_comments'] : "" ;
       
  1631 			if ( '' != $translator_comments ) {
       
  1632 				update_post_meta ( $post_id, $this->msg_translator_comments, $translator_comments );
       
  1633 			}
       
  1634 			// add_ctxt
       
  1635 			
       
  1636 			if ( isset ( $_POST['add_ctxt'] ) ) {
       
  1637 				$ctxt = $_POST['add_ctxt'] ;
       
  1638 				if ( '' != $ctxt ) {
       
  1639 					update_post_meta ( $post_id, $this->ctxt_meta, $ctxt );
       
  1640 				} else {
       
  1641 					delete_post_meta ( $post_id, $this->ctxt_meta);
       
  1642 				}
       
  1643 			}
       
  1644 		}
       
  1645 	}
       
  1646 	
       
  1647 	/**
       
  1648 	 * msg dashboard left
       
  1649 	 *
       
  1650 	 * @since 2.0
       
  1651 	 *
       
  1652 	 */
       
  1653 	function msg_status_display ( $id ) {
       
  1654 		global $post;
       
  1655 		$spanred = '<span class="alert">';
       
  1656 		$spanend = '</span>';
       
  1657 		
       
  1658 		$type  = get_post_meta ( $id, $this->msgtype_meta, true);
       
  1659 		// search msgid
       
  1660 		if ( $type == 'msgid' ) {
       
  1661 			$msgid_id = $id;
       
  1662 		} elseif ( $type == 'msgid_plural' ) {
       
  1663 			$temp_post_msg_id_plural = $this->temp_get_post ( $id );
       
  1664 			$msgid_id = $temp_post_msg_id_plural->post_parent;
       
  1665 			$temp_post_msg_id = $this->temp_get_post ( $msgid_id );
       
  1666 		} else {
       
  1667 			$msgid_id = get_post_meta ( $id, $this->msgidlang_meta, true);	
       
  1668 		}
       
  1669 		
       
  1670 		if ( $temp_post_msg_id = $this->temp_get_post ( $msgid_id ) ) {
       
  1671 			if ( defined ('WP_DEBUG') &&  WP_DEBUG == true ) {
       
  1672 				//echo '<div class="msg-saved" >';
       
  1673 				//printf( __('%s saved as: <em>%s</em>', 'xili-dictionary'), $this->msg_str_labels[$type], $post->post_content );
       
  1674 				//echo '</div>';
       
  1675 			}
       
  1676 			$res = get_post_meta ( $msgid_id, $this->msgchild_meta, false ); 
       
  1677 			$thechilds =  ( is_array ( $res ) &&  array() != $res  ) ? $res[0]  : array();
       
  1678 			
       
  1679 			$res = get_post_meta ( $msgid_id, $this->msglang_meta, false );
       
  1680 			$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  1681 			
       
  1682 			if ( isset ($_GET['msgaction'] ) && isset ($_GET['langstr']) ) { // action to create child and default line - single or plural...
       
  1683 				check_admin_referer( 'xd-langstr' );	
       
  1684 				$target_lang = $_GET['langstr'];
       
  1685 				if ( $_GET['msgaction'] == 'msgstr'  && !isset( $thelangs['msgstrlangs'][$target_lang] ) )  {
       
  1686 				// create post
       
  1687 					if ( !isset ( $thechilds['msgid']['plural'] ) ) {
       
  1688 						
       
  1689 						$msgstr_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate:', 'xili-dictionary').$temp_post_msg_id->post_content , null, 'msgstr' , 0 );
       
  1690 						wp_set_object_terms( $msgstr_post_ID, $target_lang, TAXONAME );
       
  1691 						$thelangs['msgstrlangs'][$target_lang]['msgstr'] = $msgstr_post_ID;
       
  1692 						update_post_meta ( $msgid_id, $this->msglang_meta, $thelangs );
       
  1693 						update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $msgid_id );
       
  1694 					 	
       
  1695 					 	$translated_post_ID = $msgstr_post_ID;
       
  1696 						//printf( 'msgstr created in %s <br/>', $target_lang ) ;
       
  1697 					
       
  1698 					} else {
       
  1699 						// create msgstr_0
       
  1700 						$msgstr_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate (msgstr[0]): ', 'xili-dictionary').$temp_post_msg_id->post_content , null, 'msgstr_0' , 0 );
       
  1701 						wp_set_object_terms( $msgstr_post_ID, $target_lang, TAXONAME );
       
  1702 						$thelangs['msgstrlangs'][$target_lang]['msgstr_0'] = $msgstr_post_ID;
       
  1703 						update_post_meta ( $msgid_id, $this->msglang_meta, $thelangs );
       
  1704 						update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $msgid_id );
       
  1705 						
       
  1706 						$translated_post_ID = $msgstr_post_ID;
       
  1707 						//printf( 'msgstr[0] created in %s <br/>', $target_lang ) ;
       
  1708 						
       
  1709 						// create msgstr_1
       
  1710 						$temp_post_msg_id_plural = $this->temp_get_post ( $thechilds['msgid']['plural']  );
       
  1711 						$content_plural = htmlspecialchars( $temp_post_msg_id_plural->post_content );
       
  1712 						$msgstr_1_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate (msgstr[1]): ', 'xili-dictionary'). $content_plural , null, 'msgstr_1' , $msgstr_post_ID );
       
  1713 						wp_set_object_terms( $msgstr_1_post_ID, $target_lang, TAXONAME );
       
  1714 						$thelangs['msgstrlangs'][$target_lang]['plural'][1] = $msgstr_1_post_ID;
       
  1715 						update_post_meta ( $msgid_id, $this->msglang_meta, $thelangs );
       
  1716 						update_post_meta ( $msgstr_1_post_ID, $this->msgidlang_meta, $msgid_id );
       
  1717 						
       
  1718 						//printf( 'msgstr[1] created in %s <br/>', $target_lang ) ;
       
  1719 					}
       
  1720 					// redirect
       
  1721 					
       
  1722 					//if ( $translated_post_ID > 0 && $this->xili_settings['creation_redirect'] == 'redirect') {
       
  1723 					$url_redir = admin_url().'post.php?post='.$translated_post_ID.'&action=edit';
       
  1724 			
       
  1725 				?>
       
  1726    <script type="text/javascript">
       
  1727    <!--
       
  1728       window.location= <?php echo "'" . $url_redir . "'"; ?>;
       
  1729    //-->
       
  1730    </script>
       
  1731 <?php
       
  1732 				//}
       
  1733 				}
       
  1734 			}  elseif ( isset ($_GET['msgaction']) && $_GET['msgaction'] == 'msgid_plural'  && !isset( $thelangs['msgstrlangs'] ) ) {
       
  1735 				check_admin_referer( 'xd-plural' );	
       
  1736 					$msgid_plural_post_ID = $this->insert_one_cpt_and_meta ( __('XD say id to plural: ', 'xili-dictionary').$temp_post_msg_id->post_content , null, 'msgid_plural' , $msgid_id );
       
  1737 					$res = get_post_meta ( $msgid_id, $this->msgchild_meta, false ); 
       
  1738 					$thechilds =  ( is_array ( $res ) &&  array() != $res  ) ? $res[0]  : array();	
       
  1739 							
       
  1740 			} elseif ( $type == 'msgid' && isset ($_GET['msgaction']) &&  $_GET['msgaction'] == 'setlocal' ) {
       
  1741 				check_admin_referer( 'xd-setlocal' );
       
  1742 				$extracted_comments = get_post_meta ( $msgid_id, $this->msg_extracted_comments, true );
       
  1743 				$extracted_comments = $this->local_tag .' '. $extracted_comments;
       
  1744 				update_post_meta ( $msgid_id, $this->msg_extracted_comments, $extracted_comments );
       
  1745 			
       
  1746 			} elseif ( $type == 'msgid' && isset ($_GET['msgaction']) &&  $_GET['msgaction'] == 'unsetlocal' ) {
       
  1747 				check_admin_referer( 'xd-setlocal' );
       
  1748 				$extracted_comments = get_post_meta ( $msgid_id, $this->msg_extracted_comments, true );
       
  1749 				$extracted_comments = str_replace ( $this->local_tag .' ', '', $extracted_comments);
       
  1750 				update_post_meta ( $msgid_id, $this->msg_extracted_comments, $extracted_comments );
       
  1751 			}
       
  1752 			
       
  1753 			
       
  1754 			// display current saved content
       
  1755 			
       
  1756 			//if ( $type != "msgid" ) {
       
  1757 				$line = __('msgid:', 'xili-dictionary'); 
       
  1758 				$line .=  '&nbsp;<strong>'. htmlspecialchars($temp_post_msg_id->post_content ) . '</strong>' ;
       
  1759 				if ( $post->ID != $msgid_id ) {
       
  1760 					$line .= sprintf( __('( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'),'post.php?post='.$msgid_id.'&action=edit', $msgid_id, __('Edit') ) ;
       
  1761 				} else {
       
  1762 					$line .= '<br />';
       
  1763 				}
       
  1764 				$this->hightlight_line ( $line, $type, 'msgid' );
       
  1765 			//}
       
  1766 			if ( isset ( $thechilds['msgid']['plural'] ) ) {
       
  1767 				$post_status = get_post_status ( $thechilds['msgid']['plural'] ) ;
       
  1768 				$line = "";
       
  1769 				if ( $post_status == "trash" || $post_status === false ) $line .= $spanred;
       
  1770 				$line .= '<span class="msgid_plural">'. __('msgid_plural:', 'xili-dictionary') . '</span>&nbsp;';
       
  1771 				if ( $post_status == "trash" || $post_status === false ) $line .= $spanend;
       
  1772 				$temp_post_msg_id_plural = $this->temp_get_post ( $thechilds['msgid']['plural']  );
       
  1773 				$content_plural = htmlspecialchars( $temp_post_msg_id_plural->post_content );
       
  1774 				$line .= '<strong>'. $content_plural . '</strong> ' ;
       
  1775 				if ( $post->ID != $thechilds['msgid']['plural'] ) 
       
  1776 					$line .= sprintf( __('( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'),'post.php?post='.$thechilds['msgid']['plural'].'&action=edit', $thechilds['msgid']['plural'], __('Edit') ) ;
       
  1777 				$this->hightlight_line ( $line, $type, 'msgid_plural'  );
       
  1778 				
       
  1779 				
       
  1780 			} else {
       
  1781 				if ( !isset ( $thelangs['msgstrlangs'] ) && !isset ( $thechilds['msgid']['plural'] ) ) { // not yet translated
       
  1782 					
       
  1783 					$nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgid_plural', 'xd-plural'  ) ;
       
  1784 					printf( __('&nbsp;<a href="%s" >Create msgid_plural</a>', 'xili-dictionary'), $nonce_url );
       
  1785 					echo '<br />';
       
  1786 				}
       
  1787 			}
       
  1788 			
       
  1789 			// display series
       
  1790 			$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
       
  1791 			if (isset ( $thelangs['msgstrlangs'] ) ) {
       
  1792 				$translated_langs = array ();
       
  1793 				echo '<br /><table class="widefat"><thead><tr><th class="column-msgtrans">';
       
  1794 				_e( 'translated in', 'xili-dictionary');
       
  1795 				echo '</th><th>‟msgstr”</th></tr></thead><tbody>';
       
  1796 				foreach ( $thelangs['msgstrlangs'] as $curlang => $msgtr ) {
       
  1797 							
       
  1798 					$strid = 0;
       
  1799 					if ( isset ( $msgtr['msgstr'] ) ) {
       
  1800 						$strid = $msgtr['msgstr'] ;
       
  1801 						$str_plural = false ;
       
  1802 						$translated_langs[] = $curlang;
       
  1803 						$typeref = 'msgstr';
       
  1804 					} elseif ( isset ( $msgtr['msgstr_0'] ) ) {
       
  1805 						$strid = $msgtr['msgstr_0'] ;
       
  1806 						$str_plural = true ;
       
  1807 						$translated_langs[] = $curlang;  // detect content empty
       
  1808 						$typeref = 'msgstr_0';
       
  1809 					}
       
  1810 							
       
  1811 					if ( $strid != 0 ) {
       
  1812 						$target_lang = implode ( ' ', wp_get_object_terms( $id, TAXONAME, $args = array( 'fields' => 'names')) );
       
  1813 						echo '<tr class="lang-'.strtolower($curlang).'" ><th><span>';
       
  1814 						printf( '%s : ', $curlang );
       
  1815 						echo '</span></th><td>';
       
  1816 						$temp_post = $this->temp_get_post ( $strid  );
       
  1817 						$content = htmlspecialchars( $temp_post->post_content );
       
  1818 						$line = "";			
       
  1819 						if ( $str_plural ) $line .= "[0] ";
       
  1820 									
       
  1821 						$line .= '‟<strong>'. $content . '</strong>”' ;
       
  1822 						$post_status = get_post_status ( $strid );
       
  1823 						if ( $post_status == "trash" || $post_status === false ) $line .= $spanred;
       
  1824 						if ( $post->ID != $strid ) {
       
  1825 							$line .= sprintf( ' ( <a href="%s" title="link to:%d">%s</a> )<br />', 'post.php?post='.$strid.'&action=edit', $strid, __('Edit') ) ;
       
  1826 						} else {
       
  1827 							$line .= '<br />';
       
  1828 						}
       
  1829 						if ( $post_status == "trash" || $post_status === false ) $line .= $spanend;
       
  1830 						
       
  1831 						$this->hightlight_line_str ( $line, $type, $typeref, $curlang, $target_lang ); 
       
  1832 									
       
  1833 						if ( $str_plural ) {
       
  1834 							$res = get_post_meta ( $strid, $this->msgchild_meta, false );
       
  1835 							$strthechilds =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  1836 							foreach ( $strthechilds['msgstr']['plural'] as $key => $strchildid ) {
       
  1837 								$temp_post = $this->temp_get_post ( $strchildid  );
       
  1838 								$content = htmlspecialchars( $temp_post->post_content );
       
  1839 								$line = "";
       
  1840 								$post_status = get_post_status ( $strchildid ); // fixed 2.1
       
  1841 								if ( $post_status == "trash" || $post_status === false ) $line .= $spanred;
       
  1842 								$line .= sprintf ( '[%s] ', $key );
       
  1843 								if ( $post_status == "trash" || $post_status === false ) $line .= $spanend;
       
  1844 								if ( $post->ID != $strchildid ) {
       
  1845 									$line .= sprintf ( '‟<strong>%s</strong>” ( %s )', $content, '<a href="post.php?post='.$strchildid.'&action=edit" title="link to:'.$strchildid.'">'.__('Edit').'</a>'  ) ;
       
  1846 								} else {
       
  1847 									$line .= sprintf ( '‟<strong>%s</strong>”', $content );
       
  1848 								}
       
  1849 								$this->hightlight_line_str ( $line, $type, 'msgstr_'.$key, $curlang, $target_lang );
       
  1850 								echo '<br />';		
       
  1851 							}
       
  1852 										// if possible against current lang add links - compare to count of $strthechilds['msgstr']['plural']
       
  1853 											
       
  1854 						}
       
  1855 						echo '</td></tr>';
       
  1856 					}
       
  1857 							
       
  1858 				}
       
  1859 				echo '</tbody></table>';
       
  1860 				$this->create_line_lang = "";
       
  1861 				if ( count ($translated_langs) !=  count ($listlanguages) )  {
       
  1862 							//echo '<br />';
       
  1863 					$this->create_line_lang = __('Create msgstr in: ', 'xili-dictionary');
       
  1864 					foreach ( $listlanguages as $tolang ) {
       
  1865 						if ( !in_array ( $tolang->name , $translated_langs )  ) {
       
  1866 							$nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgstr&langstr='.$tolang->name, 'xd-langstr'  ) ;					
       
  1867 							$this->create_line_lang .= sprintf( '&nbsp; <a class="lang-'. strtolower($tolang->name).'" href="%s" >'.$tolang->name.'</a>', $nonce_url );			}
       
  1868 					}
       
  1869 				}
       
  1870 			} else {
       
  1871 				$this->create_line_lang = "";
       
  1872 				if ( !isset ($_POST['msgaction'] ) || ( isset ($_GET['msgaction'] ) && $_GET['msgaction'] == 'msgid_plural' ) ) {
       
  1873 					 _e( 'not yet translated.', 'xili-dictionary'); 
       
  1874 					
       
  1875 					$this->create_line_lang = __('Create msgstr in: ', 'xili-dictionary');
       
  1876 					 foreach ( $listlanguages as $tolang ) {
       
  1877 					 	$nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgstr&langstr='.$tolang->name, 'xd-langstr'  ) ;
       
  1878 					 	$this->create_line_lang .= sprintf( '&nbsp; <a class="lang-'. strtolower( $tolang->name).'" href="%s" >'.$tolang->name.'</a>', $nonce_url  );					 }
       
  1879 				}
       
  1880 			}
       
  1881 		} else {
       
  1882 			
       
  1883 			printf ( __('The msgid (%d) was deleted. The msg series must be recreated.','xili-dictionary' ), $msgid_id );
       
  1884 		}
       
  1885 	}
       
  1886 	
       
  1887 	function hightlight_line ( $line, $cur_type, $type ) {
       
  1888 		if ( $cur_type == $type) {
       
  1889 			echo '<span class="editing msgidstyle">'. $line .'</span>';
       
  1890 		} else {
       
  1891 			echo '<span class="msgidstyle">'. $line .'</span>';
       
  1892 		}
       
  1893 	}
       
  1894 	
       
  1895 	function hightlight_line_str ( $line, $cur_type, $type, $cur_lang, $lang ) {
       
  1896 		if ( $cur_type == $type && $cur_lang == $lang ) {
       
  1897 			echo '<span class="editing msgstrstyle">'.$line.'</span>';
       
  1898 		} else {
       
  1899 			echo '<span class="msgstrstyle">'. $line .'</span>';
       
  1900 		}
       
  1901 	}
       
  1902 	
       
  1903 	
       
  1904 	/**
       
  1905 	 * display msg series linked together
       
  1906 	 *
       
  1907 	 * @param post ID, display (true for single edit)
       
  1908 	 *
       
  1909 	 */
       
  1910 	function msg_link_display ( $id , $display = false, $thepost = null ) {
       
  1911 			
       
  1912 			if ( $thepost != null ) {
       
  1913 				$post = $thepost ;
       
  1914 			} else { 
       
  1915 				global $post ;
       
  1916 			}
       
  1917 			
       
  1918 			$spanred = '<span class="alert">';
       
  1919 			$spanend = '</span>';
       
  1920 		// type
       
  1921 			$type  = get_post_meta ( $id, $this->msgtype_meta, true);
       
  1922 			
       
  1923 			$res = get_post_meta ( $id, $this->msgchild_meta, false ); 
       
  1924 			$thechilds =  ( is_array ( $res ) &&  array() != $res  ) ? $res[0]  : array();
       
  1925 			
       
  1926 			$res = get_post_meta ( $id, $this->msglang_meta, false );
       
  1927 			$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  1928 			
       
  1929 			if ( $type == 'msgid' ) {
       
  1930 				$ctxt = get_post_meta ( $id, $this->ctxt_meta, true ); 
       
  1931 				if ( $post->post_status == "trash" )  echo $spanred;
       
  1932 				if ( $display ) {
       
  1933 					echo '<div class="msg-saved" >';
       
  1934 					printf( __('msgid saved as: <em>%s</em>', 'xili-dictionary'), ( $post->post_content ) );
       
  1935 					echo '</div>';
       
  1936 				} else {
       
  1937 					echo 'msgid';
       
  1938 				}
       
  1939 				if ( $post->post_status == "trash" ) echo $spanend;
       
  1940 				echo '<br />';
       
  1941 				if ( $ctxt != "" && !$display ) printf ( 'ctxt: %s <br />'  , $ctxt ); 
       
  1942 				
       
  1943 				if ( isset ( $thechilds['msgid']['plural'] ) ) {
       
  1944 					$post_status = get_post_status ( $thechilds['msgid']['plural'] ) ;
       
  1945 					if ( !$display ) {
       
  1946 						if ( $post_status == "trash" || $post_status === false ) echo $spanred;
       
  1947 						printf( __('has plural: <a href="%s" >%d</a><br />', 'xili-dictionary'),'post.php?post='.$thechilds['msgid']['plural'].'&action=edit', $thechilds['msgid']['plural'] ) ;
       
  1948 						if ( $post_status == "trash" || $post_status === false ) echo $spanend;
       
  1949 					} else {
       
  1950 						if ( $post_status == "trash" || $post_status === false ) echo $spanred;
       
  1951 						_e('has plural:', 'xili-dictionary'); echo '&nbsp;';
       
  1952 						if ( $post_status == "trash" || $post_status === false ) echo $spanend;
       
  1953 						$temp_post = $this->temp_get_post ( $thechilds['msgid']['plural']  );
       
  1954 						$content_plural = htmlspecialchars( $temp_post->post_content );
       
  1955 						echo '<strong>'. $content_plural . '</strong> ' ;
       
  1956 						printf( __('( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'),'post.php?post='.$thechilds['msgid']['plural'].'&action=edit', $thechilds['msgid']['plural'], __('Edit') ) ;
       
  1957 					}
       
  1958 				} else {
       
  1959 					if ( $display && !isset ( $thelangs['msgstrlangs'] ) && !isset ( $thechilds['msgid']['plural'] ) ) { // not yet translated
       
  1960 						
       
  1961 				 		printf( __('&nbsp;<a href="%s" >Create msgid_plural</a>', 'xili-dictionary'), 'post.php?post='.$id.'&action=edit&msgaction=msgid_plural' );
       
  1962 				 		echo '<br />';
       
  1963 				 	}
       
  1964 				}
       
  1965 				$res = get_post_meta ( $id, $this->msglang_meta, false );
       
  1966 				$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  1967 				// action to create child and default line - single or plural...
       
  1968 				if ( isset ($_GET['msgaction'] ) && isset ($_GET['langstr']) && $display) {
       
  1969 					$target_lang = $_GET['langstr'];
       
  1970 					if ( $_GET['msgaction'] == 'msgstr'  && !isset( $thelangs['msgstrlangs'][$target_lang] ) )  {
       
  1971 					// create post
       
  1972 						if ( !isset ( $thechilds['msgid']['plural'] ) ) {
       
  1973 							
       
  1974 							$msgstr_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate: ', 'xili-dictionary').$post->post_content , null, 'msgstr' , 0 );
       
  1975 							wp_set_object_terms( $msgstr_post_ID, $target_lang, TAXONAME );
       
  1976 							$thelangs['msgstrlangs'][$target_lang]['msgstr'] = $msgstr_post_ID;
       
  1977 							update_post_meta ( $id, $this->msglang_meta, $thelangs );
       
  1978 							update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $id );
       
  1979 						 	
       
  1980 							sprintf( 'msgstr created in %s <br/>', $target_lang ) ;
       
  1981 						
       
  1982 						} else {
       
  1983 							// create msgstr_0
       
  1984 							$msgstr_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate (msgstr[0]): ', 'xili-dictionary').$post->post_content , null, 'msgstr_0' , 0 );
       
  1985 							wp_set_object_terms( $msgstr_post_ID, $target_lang, TAXONAME );
       
  1986 							$thelangs['msgstrlangs'][$target_lang]['msgstr_0'] = $msgstr_post_ID;
       
  1987 							update_post_meta ( $id, $this->msglang_meta, $thelangs );
       
  1988 							update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $id );
       
  1989 							
       
  1990 							sprintf( 'msgstr[0] created in %s <br/>', $target_lang ) ;
       
  1991 							
       
  1992 							// create msgstr_1
       
  1993 							$msgstr_1_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate (msgstr[1]): ', 'xili-dictionary'). $content_plural , null, 'msgstr_1' , $msgstr_post_ID );
       
  1994 							wp_set_object_terms( $msgstr_1_post_ID, $target_lang, TAXONAME );
       
  1995 							$thelangs['msgstrlangs'][$target_lang]['plural'][1] = $msgstr_1_post_ID;
       
  1996 							update_post_meta ( $id, $this->msglang_meta, $thelangs );
       
  1997 							update_post_meta ( $msgstr_1_post_ID, $this->msgidlang_meta, $msgid_id );
       
  1998 							
       
  1999 							sprintf( 'msgstr[1] created in %s <br/>', $target_lang ) ;
       
  2000 						}
       
  2001 					} elseif ( $_GET['msgaction'] == 'msgid_plural'  && !isset( $thelangs['msgstrlangs'][$target_lang] ) ) {
       
  2002 						
       
  2003 						$msgid_plural_post_ID = $this->insert_one_cpt_and_meta ( __('XD say id to plural: ', 'xili-dictionary').$post->post_content , null, 'msgid_plural' , $id );
       
  2004 							
       
  2005 					}
       
  2006 				}
       
  2007 				$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
       
  2008 				if (isset ( $thelangs['msgstrlangs'] ) ) {
       
  2009 					//$thelangs['msgstrlangs'][$curlang]['msgstr'] = $msgstr_post_ID;
       
  2010 					
       
  2011 					$translated_langs = array ();
       
  2012 					if ( $display ) {
       
  2013 						echo '<br /><table class="widefat"><thead><tr><th class="column-msgtrans">';
       
  2014 						_e( 'translated in', 'xili-dictionary');
       
  2015 						echo '</th><th>msgstr</th></tr></thead><tbody>';
       
  2016 					} else {
       
  2017 						echo ( __( 'translated in', 'xili-dictionary').':<br />');
       
  2018 					}
       
  2019 					foreach ( $thelangs['msgstrlangs'] as $curlang => $msgtr ) {
       
  2020 						
       
  2021 						$strid = 0;
       
  2022 						if ( isset ( $msgtr['msgstr'] ) ) {
       
  2023 							$strid = $msgtr['msgstr'] ;
       
  2024 							$str_plural = false ;
       
  2025 							$translated_langs[] = $curlang;
       
  2026 						} elseif ( isset ( $msgtr['msgstr_0'] ) ) {
       
  2027 							$strid = $msgtr['msgstr_0'] ;
       
  2028 							$str_plural = true ;
       
  2029 							$translated_langs[] = $curlang;  // detect content empty
       
  2030 						}
       
  2031 						
       
  2032 						if ( $strid != 0 ) {
       
  2033 							if ( !$display ) {
       
  2034 							// get strid status  
       
  2035 								$post_status = get_post_status ( $strid );
       
  2036 								if ( $post_status == "trash" || $post_status === false ) echo $spanred;
       
  2037 							 	printf( '- %s : <a href="%s" >%d</a><br />', $curlang, 'post.php?post='.$strid.'&action=edit', $strid ) ;
       
  2038 								if ( $post_status == "trash" || $post_status === false ) echo $spanend;
       
  2039 							} else {
       
  2040 								echo '<tr><th>';
       
  2041 								printf( '%s : ', $curlang );
       
  2042 								echo '</th><td>';
       
  2043 								$temp_post = $this->temp_get_post ( $strid  );
       
  2044 								$content = htmlspecialchars( $temp_post->post_content );
       
  2045 								
       
  2046 								if ( $str_plural ) echo "[0] ";
       
  2047 								
       
  2048 								echo '<strong>'. $content . '</strong>' ;
       
  2049 								$post_status = get_post_status ( $strid );
       
  2050 								if ( $post_status == "trash" || $post_status === false ) echo $spanred;
       
  2051 							 		printf( ' ( <a href="%s" title="link to:%d">%s</a> )<br />', 'post.php?post='.$strid.'&action=edit', $strid, __('Edit') ) ;
       
  2052 								if ( $post_status == "trash" || $post_status === false ) echo $spanend;
       
  2053 								
       
  2054 								if ( $str_plural ) {
       
  2055 									$res = get_post_meta ( $strid, $this->msgchild_meta, false );
       
  2056 									$strthechilds =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  2057 									foreach ( $strthechilds['msgstr']['plural'] as $key => $strchildid ) {
       
  2058 										$temp_post = $this->temp_get_post ( $strchildid  );
       
  2059 										$content = htmlspecialchars( $temp_post->post_content );
       
  2060 										$post_status = get_post_status ( $strchildid );
       
  2061 										if ( $post_status == "trash" || $post_status === false ) echo $spanred;
       
  2062 										printf ( '[%s] ', $key );
       
  2063 										if ( $post_status == "trash" || $post_status === false ) echo $spanend;
       
  2064 										printf ( '<strong>%s</strong> ( %s )<br />', $content, '<a href="post.php?post='.$strchildid.'&action=edit" title="link to:'.$strchildid.'">'.__('Edit').'</a>' ) ;
       
  2065 									
       
  2066 									}
       
  2067 									// if possible against current lang add links - compare to count of $strthechilds['msgstr']['plural']
       
  2068 										
       
  2069 								}
       
  2070 								echo '</td></tr>';
       
  2071 							}
       
  2072 						}
       
  2073 						
       
  2074 					}
       
  2075 					if ( $display )  echo '</tbody></table>';
       
  2076 					$this->create_line_lang = "";
       
  2077 					if ( $display && ( count ($translated_langs) !=  count ($listlanguages) ) ) {
       
  2078 						//echo '<br />';
       
  2079 						$this->create_line_lang = __('Create msgstr in: ', 'xili-dictionary');
       
  2080 						foreach ( $listlanguages as $tolang ) {
       
  2081 							if ( !in_array ( $tolang->name , $translated_langs )  ) {
       
  2082 								$nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgstr&langstr='.$tolang->name, 'xd-langstr'  ) ;
       
  2083 				 				$this->create_line_lang .= sprintf( '&nbsp;<a href="%s" >'.$tolang->name.'</a>', $nonce_url );
       
  2084 							}				
       
  2085 				 		}
       
  2086 					}
       
  2087 						
       
  2088 				} else { // no translation
       
  2089 					if ( !isset ($_POST['msgaction'] ) || ( isset ($_GET['msgaction'] ) && $_GET['msgaction'] == 'msgid_plural' ) ) {
       
  2090 				 		_e( 'not yet translated.', 'xili-dictionary'); 
       
  2091 				 		echo '&nbsp';
       
  2092 				 		if ( $display ) { 
       
  2093 				 			_e('Create msgstr in: ', 'xili-dictionary');
       
  2094 				 				
       
  2095 				 			foreach ( $listlanguages as $tolang ) {
       
  2096 				 				$nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgstr&langstr='.$tolang->name, 'xd-langstr'  ) ;
       
  2097 				 				printf( '&nbsp;<a href="%s" >'.$tolang->name.'</a>', $nonce_url );				
       
  2098 				 			}
       
  2099 				 		}
       
  2100 					}
       
  2101 				}	
       
  2102 				
       
  2103 				
       
  2104 			} elseif (  $type != '' ) {
       
  2105 				
       
  2106 				$msgid_ID = get_post_meta ( $id, $this->msgidlang_meta , true);
       
  2107 				
       
  2108 			
       
  2109 				
       
  2110 				
       
  2111 				if ( $display  && ( $type == 'msgid_plural' || ( false !== strpos( $type, 'msgstr_' ) && substr( $type, -1 ) !='0')  ) ) {
       
  2112 					$temp_post = $this->temp_get_post ( $post->post_parent  );
       
  2113 					$content = htmlspecialchars( $temp_post->post_content ) ;
       
  2114 					$target_lang = implode ( ' ', wp_get_object_terms( $id, TAXONAME, $args = array( 'fields' => 'names')) );
       
  2115 					$is_plural = true;
       
  2116 				} elseif ( $display ) {
       
  2117 					$temp_post = $this->temp_get_post ( $msgid_ID  );
       
  2118 					$content = htmlspecialchars( $temp_post->post_content ) ;
       
  2119 					$target_lang = implode ( ' ', wp_get_object_terms( $id, TAXONAME, $args = array( 'fields' => 'names')) );
       
  2120 					$is_plural = false;
       
  2121 				}
       
  2122 				
       
  2123 				$span_msgid = ( get_post_status ( $msgid_ID ) == "trash" || get_post_status ( $msgid_ID ) === false ) ;
       
  2124 				$span_parent = ( get_post_status ( $post->post_parent ) == "trash" || get_post_status ( $post->post_parent ) === false ) ;
       
  2125 				
       
  2126 				if ( $display ) {
       
  2127 					echo '<div class="msg-saved" >';
       
  2128 					printf( __('%s saved as: <em>%s</em>', 'xili-dictionary'), $this->msg_str_labels[$type], $post->post_content );
       
  2129 					echo '</div>';
       
  2130 				}
       
  2131 				
       
  2132 				switch ( $type ) {
       
  2133 					case 'msgid_plural':
       
  2134 					
       
  2135 						if ( $span_parent ) echo $spanred ;
       
  2136 						if ( $display ) {
       
  2137 							printf( __('msgid plural of: <strong>%s</strong> ( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'), $content,'post.php?post='.$post->post_parent.'&action=edit', $post->post_parent, __('Edit')  );
       
  2138 						} else {
       
  2139 							printf( __('msgid plural of: <a href="%s" >%d</a><br />', 'xili-dictionary'),'post.php?post='.$post->post_parent.'&action=edit',$post->post_parent ) ;
       
  2140 						}
       
  2141 						if ( $span_parent ) echo $spanend ;
       
  2142 						
       
  2143 						
       
  2144 						break;
       
  2145 					case 'msgstr':
       
  2146 						if ( $display  ) echo '<strong>'.$target_lang."</strong> translation of: <strong>" . $content . '</strong> ';
       
  2147 						if ( $span_msgid ) echo $spanred ;
       
  2148 						if ( $display  ) {
       
  2149 							printf( __('( <a href="%s" title = "link of:%d">%s</a> )<br />', 'xili-dictionary'), 'post.php?post='.$msgid_ID.'&action=edit', $msgid_ID, __('Edit') );
       
  2150 						} else {
       
  2151 							
       
  2152 							printf( __('msgstr of: <a href="%s" >%d</a><br />', 'xili-dictionary'), 'post.php?post='.$msgid_ID.'&action=edit', $msgid_ID );
       
  2153 						}
       
  2154 						if ( $span_msgid ) echo $spanend ;
       
  2155 						//if ( $display ) echo  '<strong>'.$content .'</strong>';
       
  2156 						break;
       
  2157 					
       
  2158 					default:
       
  2159 						if ( false !== strpos( $type, 'msgstr_' ) ) {
       
  2160 							$indices = explode ('_', $type);
       
  2161 							$indice = $indices[1];
       
  2162 							$edit_id = ( $indice == 0 ) ? $msgid_ID : $post->post_parent ;
       
  2163 							
       
  2164 							if ( $display ) {
       
  2165 								if ( $is_plural ) {
       
  2166 									printf(__( '<strong>%s</strong> plural of: <strong>%s</strong>( <a href="%s" title="link to:%d">%s</a> )<br />', ''),$target_lang,  $content, 'post.php?post='.$edit_id.'&action=edit' , $edit_id, __('Edit') );
       
  2167 								} else {
       
  2168 									printf(__( '<strong>%s</strong> translation of: <strong>%s</strong>( <a href="%s" title="link to:%d">%s</a> )<br />', ''),$target_lang,  $content, 'post.php?post='.$edit_id.'&action=edit' , $edit_id, __('Edit') );
       
  2169 								}
       
  2170 							} else {
       
  2171 								if ( $indice == 0 ) {
       
  2172 									if ( $span_msgid ) echo $spanred ;
       
  2173 									printf( __('msgstr of: <a href="%s" >%d</a><br />', 'xili-dictionary'), 'post.php?post='.$msgid_ID.'&action=edit', $msgid_ID );
       
  2174 									if ( $span_msgid ) echo $spanend ;
       
  2175 								} else {
       
  2176 									if ( $span_parent ) echo $spanred ;
       
  2177 									printf( __('msgstr[%d] plural of: <a href="%s" >%d</a><br />', 'xili-dictionary'), $indice, 'post.php?post='.$post->post_parent.'&action=edit', $post->post_parent ) ;
       
  2178 									if ( $span_parent ) echo $spanend ;
       
  2179 								}
       
  2180 							}
       
  2181 							if ( $display && $indice > 0) { 
       
  2182 								printf(__('go to <a href="%s" title="link to:%d">msgid</a>', 'xili-dictionary'), 'post.php?post='.$msgid_ID.'&action=edit', $msgid_ID ) ;
       
  2183 							}
       
  2184 						}	
       
  2185 				}
       
  2186 				
       
  2187 			}
       
  2188 		return $type;
       
  2189 	}
       
  2190 	
       
  2191 	function temp_get_post ( $post_id ) {
       
  2192 		global $wpdb ;
       
  2193 		$res = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id)); 
       
  2194 		if ( $res && !is_wp_error($res) ) 
       
  2195 			return $res;
       
  2196 		else
       
  2197 			return false;		
       
  2198 	}
       
  2199 	
       
  2200 	/**
       
  2201 	 * unset autosave for msg
       
  2202 	 * @since 2.0
       
  2203 	 */
       
  2204 	function auto_save_unsetting() {
       
  2205 		global $hook_suffix, $post ;
       
  2206 		$type = '';
       
  2207 		if ( isset($_GET['post_type']) )
       
  2208 			$type = $_GET['post_type'];
       
  2209 		
       
  2210 		if ( ( $hook_suffix == 'post-new.php' && $type == XDMSG ) || ( $hook_suffix == 'post.php' && $post->post_type == XDMSG  )) {
       
  2211 						
       
  2212 						wp_dequeue_script('autosave');
       
  2213 						//wp_deregister_script('autosave');
       
  2214 						//$wp_scripts->queue = array_diff( $wp_scripts->queue , array('autosave')  );		
       
  2215 		}				
       
  2216 	}
       
  2217 	
       
  2218 	
       
  2219 	/**
       
  2220 	 * Reset values when theme was changed... updated by previous function
       
  2221 	 * @since 1.0.5
       
  2222 	 */ 
       
  2223 	function xd_theme_switched ($theme) {
       
  2224 		$this->xili_settings['langs_folder'] ="unknown";
       
  2225 		/* to force future search in new theme */
       
  2226 		update_option('xili_dictionary_settings', $this->xili_settings);
       
  2227 	}
       
  2228 	
       
  2229 	/**
       
  2230 	 * @since 1.3.0 for js in tools list
       
  2231 	 */
       
  2232 	function admin_enqueue_scripts() {
       
  2233 		wp_enqueue_script( 'datatables', plugins_url('js/jquery.dataTables.min.js', __FILE__ ) , array( 'jquery' ), '1.7.4', true );
       
  2234 	}
       
  2235 	
       
  2236 	function admin_enqueue_styles() {
       
  2237 		wp_enqueue_style('table_xdstyle'); // style of js table
       
  2238 	}
       
  2239 	
       
  2240 	function admin_init() {
       
  2241         /* Register our script. */
       
  2242         wp_register_script( 'datatables', plugins_url('js/jquery.dataTables.min.js', __FILE__ ) );
       
  2243         wp_register_style( 'table_xdstyle', plugins_url('/css/xd_table.css', __FILE__ ), array(), XILIDICTIONARY_VER, 'screen' );
       
  2244     }
       
  2245 	
       
  2246 	/** 
       
  2247 	 *add admin menu and associated page 
       
  2248 	 */
   105 	function xili_add_dict_pages() {
  2249 	function xili_add_dict_pages() {
   106 		 $this->thehook = add_management_page(__('Dictionary','xili-dictionary'), __('Dictionary','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings'));
  2250 		
   107 		  add_action('load-'.$this->thehook, array(&$this,'on_load_page'));
  2251 		//$this->thehook = add_management_page(__('Xili Dictionary','xili-dictionary'), __('xili Dictionary','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings'));
   108 		  add_action( "admin_print_scripts-".$this->thehook, array(&$this,'xili_add_js'));		 
  2252 		
       
  2253 		$this->thehook = add_submenu_page( 'edit.php?post_type='.XDMSG, __('Xili Dictionary','xili-dictionary'), __('Tools, Files po mo','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings') );
       
  2254 		
       
  2255 		 add_action('load-'.$this->thehook, array(&$this,'on_load_page'));
       
  2256 		  	
       
  2257 		 add_action( 'admin_print_scripts-'.$this->thehook, array(&$this,'admin_enqueue_scripts') );
       
  2258 		 add_action( 'admin_print_styles-'.$this->thehook, array(&$this,'admin_enqueue_styles') );	
       
  2259 		 
       
  2260 		 // Add to end of admin_menu action function
       
  2261 		global $submenu;
       
  2262 		$submenu['edit.php?post_type='.XDMSG][5][0] = __('Msg list','xili-dictionary'); // sub menu
       
  2263 		$post_type_object = get_post_type_object(XDMSG);
       
  2264 		$post_type_object->labels->name = __('XD Msg list','xili-dictionary'); // title list screen
       
  2265 		
       
  2266 		$this->insert_news_pointer ( 'xd_new_version' ); // pointer in menu for updated version
       
  2267 		add_action( 'admin_print_footer_scripts', array(&$this, 'print_the_pointers_js') );
   109 	}
  2268 	}
   110 	
  2269 	
   111 	function on_load_page() {
  2270 	function on_load_page() {
   112 			wp_enqueue_script('common');
  2271 			wp_enqueue_script('common');
   113 			wp_enqueue_script('wp-lists');
  2272 			wp_enqueue_script('wp-lists');
   114 			wp_enqueue_script('postbox');
  2273 			wp_enqueue_script('postbox');
   115 			
  2274 			
   116 			add_meta_box('xili-dictionary-sidebox-1', __('Message','xili-dictionary'), array(&$this,'on_sidebox_1_content'), $this->thehook , 'side', 'core');
  2275 			add_meta_box('xili-dictionary-sidebox-message', __('Message','xili-dictionary'), array(&$this,'on_sidebox_message_content'), $this->thehook , 'side', 'core');
   117 			add_meta_box('xili-dictionary-sidebox-2', __('Info','xili-dictionary'), array(&$this,'on_sidebox_2_content'), $this->thehook , 'side', 'core');
  2276 			add_meta_box('xili-dictionary-sidebox-info', __('Info','xili-dictionary'), array(&$this,'on_sidebox_info_content'), $this->thehook , 'side', 'core');
   118 			
  2277 			add_meta_box('xili-dictionary-sidebox-style', __('XD style settings','xili-dictionary'), array(&$this,'on_sidebox_style_content'), $this->thehook , 'side', 'core');		
   119 			
       
   120 	}
  2278 	}
   121 	
  2279 	
   122 	/**
  2280 	/**
   123 	 * Add action link(s) to plugins page
  2281 	 * Add action link(s) to plugins page
   124 	 * 
  2282 	 * 
   130 		static $this_plugin;
  2288 		static $this_plugin;
   131 
  2289 
   132 		if (!$this_plugin ) $this_plugin = plugin_basename(__FILE__);
  2290 		if (!$this_plugin ) $this_plugin = plugin_basename(__FILE__);
   133 
  2291 
   134 		if ($file == $this_plugin ) {
  2292 		if ($file == $this_plugin ) {
   135 			$settings_link = '<a href="tools.php?&amp;page=dictionary_page">' . __('Settings') . '</a>';
  2293 			$settings_link = '<a href="'.$this->xd_settings_page.'">' . __('Settings') . '</a>';
   136 			$links = array_merge( array($settings_link), $links); // before other links
  2294 			$links = array_merge( array($settings_link), $links); // before other links
   137 		}
  2295 		}
   138 		return $links;
  2296 		return $links;
   139 	}
  2297 	}
   140 	
  2298 	
   141 	function init_textdomain() {
  2299 	function init_textdomain() {
   142 	/*multilingual for admin pages and menu*/
  2300 	/*multilingual for admin pages and menu*/
   143 		load_plugin_textdomain('xili-dictionary',PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
  2301 		
   144 		
  2302 		load_plugin_textdomain('xili-dictionary', false, 'xili-dictionary/languages' );
   145 		if (!defined('THEME_LANGS_FOLDER')) { /* set or detect at least a .mo or .po */
  2303 		
   146 			if ($this->xili_settings['langs_folder'] == "") {
  2304 		if ( class_exists('xili_language') ) {
   147 				$this->find_files(get_template_directory(), '/.[mp]o$/', array(&$this,'searchpath'));
  2305 			global $xili_language ;
   148 				update_option('xili_dictionary_settings', $this->xili_settings);
  2306 			$langs_folder = $xili_language->xili_settings['langs_folder']; // set by override_load_textdomain filter
   149 			}
  2307 			if ( $this->xili_settings['langs_folder'] != $langs_folder ) { 
   150 			define('THEME_LANGS_FOLDER',$this->xili_settings['langs_folder']); // for bkwd compatibility with xili-dictionary
  2308 		 		$this->xili_settings['langs_folder'] = $langs_folder ;
   151 		}
  2309 		 		update_option('xili_dictionary_settings', $this->xili_settings);
   152 	}
  2310 		 	}
       
  2311 		} else {
       
  2312 			if ( file_exists( $this->get_template_directory ) ) // when theme was unavailable
       
  2313 				$this->find_files($this->get_template_directory, '/^.*\.(mo|po|pot)$/', array(&$this,'searchpath'));
       
  2314 		}
       
  2315 	}
       
  2316 	
       
  2317 	/* call by findfiles */
   153 	function searchpath($path, $filename) { 
  2318 	function searchpath($path, $filename) { 
   154 		$this->xili_settings['langs_folder'] = str_replace(get_template_directory(),'',$path);
  2319 		 $langs_folder = str_replace($this->get_template_directory,'',$path); // updated 1.2.0
   155 	}
  2320 		 if ( $this->xili_settings['langs_folder'] != $langs_folder ) { 
   156 	
  2321 		 	$this->xili_settings['langs_folder'] = $langs_folder ;
       
  2322 		 	update_option('xili_dictionary_settings', $this->xili_settings);
       
  2323 		 }
       
  2324 	}
       
  2325 		
   157 	function xililanguage_state() {
  2326 	function xililanguage_state() {
   158 	/* test if xili-language is present or was present */
  2327 	/* test if xili-language is present or was present */
   159 		if (class_exists('xili_language')) {
  2328 		if (class_exists('xili_language')) {
       
  2329 			
   160 			$this->xililanguage = 'isactive';
  2330 			$this->xililanguage = 'isactive';
       
  2331 			
   161 		} else {
  2332 		} else {
   162 			/* test if language taxonomy relationships are present */
  2333 			/* test if language taxonomy relationships are present */
   163 			$xl_settings = get_option('xili_language_settings');
  2334 			$xl_settings = get_option('xili_language_settings');
   164 			if (empty($xl_settings)) {
  2335 			if ( empty($xl_settings) ) {
   165 				$this->xililanguage = 'neveractive';
  2336 				$this->xililanguage = 'neveractive';
   166 			} else {
  2337 			} else {
   167 				$this->xililanguage = 'wasactive';
  2338 				$this->xililanguage = 'wasactive';
   168 			}			
  2339 			}			
   169 		}	
  2340 		}	
   170 	}
  2341 	}
   171 	/** * @since 1.02 */
  2342 	/** * @since 1.02 */
   172 	function fill_default_languages_list() {
  2343 	function fill_default_languages_list() {
   173 		if ($this->xililanguage == 'neveractive' || $this->xililanguage == 'wasactive') {
  2344 		if ( $this->xililanguage == 'neveractive' || $this->xililanguage == 'wasactive' ) {
   174 			
  2345 			
   175 			if 	(!$this->xili_settings[XDDICTLANGS]) {
  2346 			if 	( !isset( $this->xili_settings['xl-dictionary-langs'] ) ) {
       
  2347 				
   176 				$default_langs_array = array( 
  2348 				$default_langs_array = array( 
   177 					'en_us' => array('en_US', 'english'),
  2349 					'en_us' => array('en_US', 'english'),
   178 					'fr_fr' => array('fr_FR', 'french'),
  2350 					'fr_fr' => array('fr_FR', 'french'),
   179 					'de_de' => array('de_DE', 'german'),
  2351 					'de_de' => array('de_DE', 'german'),
   180 					'es_es' => array('es_ES', 'spanish'),
  2352 					'es_es' => array('es_ES', 'spanish'),
   181 					'it_it' => array('it_IT', 'italian')
  2353 					'it_it' => array('it_IT', 'italian'),
       
  2354 					'pt_pt' => array('pt_PT', 'portuguese'),
       
  2355 					'ru_ru' => array('ru_RU', 'russian'),
       
  2356 					'zh_cn' => array('zh_CN', 'chinese'),
       
  2357 					'ja' => array('ja', 'japanese'),
       
  2358 					'ar_ar' => array('ar_AR', 'arabic')
   182 				);
  2359 				);
   183 				/* add wp admin lang */
  2360 				/* add wp admin lang */
   184 				if (defined ('WPLANG')) { 
  2361 				if ( defined ('WPLANG') ) { 
   185 					$lkey = strtolower(WPLANG);
  2362 					$lkey = strtolower(WPLANG);
   186 					if (!array_key_exists($lkey, $default_langs_array)) $default_langs_array[$lkey] = array (WPLANG, WPLANG);
  2363 					if (!array_key_exists($lkey, $default_langs_array)) $default_langs_array[$lkey] = array (WPLANG, WPLANG);
   187 				}
  2364 				}
   188 				$this->xili_settings[XDDICTLANGS] = $default_langs_array;
  2365 				$this->xili_settings['xl-dictionary-langs'] = $default_langs_array;
   189 				update_option('xili_dictionary_settings', $this->xili_settings);
  2366 				update_option('xili_dictionary_settings', $this->xili_settings);
   190 			}
  2367 			}
   191 		}
  2368 		}
   192 	}
  2369 	}
   193 	
  2370 	
   194 	/**
  2371 	/**
   195 	 * private function to update grouping of terms if xili-language is active
  2372 	 * for slug with 5 (_fr_fr) or 2 letters (as japanese)
   196 	 *
  2373 	 * 
   197 	 *
  2374 	 */
   198 	 *
  2375  	function extract_extend ( $line_slug ) {
   199 	 */
  2376  		$end = substr($line_slug, -6 ) ;
   200 	function update_terms_langs_grouping() {
  2377  		if ( substr($end, 0, 1) == '_' && substr($end, 3, 1) == '_' ) {
   201 		if ($this->xililanguage == 'isactive') {
  2378  			return substr($line_slug, -5 );
   202 			
  2379  		} else {
   203 			$listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false,'get'=>'all'));
  2380  			return substr($line_slug, -2 ); // as ja
   204 			if (!empty($listdictiolines)) {
  2381  		}
   205 		    	foreach ($listdictiolines as $dictioline) {
  2382  	}
   206 		    		/* check slug before creating relationship if parent = O select msgid */
  2383  	
   207 		    		if ($dictioline->parent != 0) {
  2384  	function popupmenu_language_list ( $action = "" ) { ?>
   208 		    			$extend = substr($dictioline->slug,-5);
  2385 <select name="target_lang" ><?php
   209 			    		$lang = get_term_by('slug',$extend,TAXONAME,OBJECT);
  2386 	   			$extend = WPLANG;
   210 			    		if ($lang) { 
  2387 	   			$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
   211 			    			$term = $lang->name; 
  2388 	   			if ( $listlanguages ) {
   212 			    		} else { 
  2389 					foreach ($listlanguages as $reflanguage) {
   213 			    			$term = $extend; 
  2390 		     			echo '<option value="'.$reflanguage->name.'"'; 
   214 			    		}
  2391 		     			if ($extend == $reflanguage->name) { 
   215 						$args = array( 'alias_of' => '', 'description' => 'Dictionary Group in '.$term, 'parent' => 0, 'slug' =>$extend);
  2392 		     				echo ' selected="selected"';
   216 				    	$theids = wp_insert_term( $term, XDDICTLANGS, $args);
  2393 		     			} 
   217 			    		wp_set_object_terms((int) $dictioline->term_id, $extend, XDDICTLANGS,false);
  2394 		     				echo ">".__($reflanguage->description,'xili-dictionary').'</option>';	
   218 		    		}
  2395 		     			
   219 		    	}
  2396 		     		}
   220 		    }
  2397 	   			}
   221 		}	
  2398 	     		if ( $action=='import' ) { // to import .pot of current domain 1.0.5
   222 	}
  2399 	     			if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0
       
  2400 						$theme_name = get_option("stylesheet"); 
       
  2401 					} else {
       
  2402 						$theme_name = get_option("template"); 
       
  2403 					}
       
  2404 	     			if (function_exists('the_theme_domain')) {// in new xili-language
       
  2405 	     				echo '<option value="'.the_theme_domain().'" >'.the_theme_domain().'.pot</option>';
       
  2406 	    			} else {
       
  2407 						
       
  2408 						echo '<option value="'.$theme_name.'" >'.$theme_name.'.pot</option>';
       
  2409 					}	
       
  2410 	     		}
       
  2411 	     		?>
       
  2412 </select>
       
  2413  	<?php 
       
  2414  	}
   223 	
  2415 	
   224 	/**
  2416 	/**
   225 	 * private functions for dictionary_settings
  2417 	 * private functions for dictionary_settings
   226 	 * @since 0.9.3
  2418 	 * @since 0.9.3
   227 	 *
  2419 	 *
   228 	 * fill the content of the boxes (right side and normal)
  2420 	 * fill the content of the boxes (right side and normal)
   229 	 * 
  2421 	 * 
   230 	 */
  2422 	 */
   231 	
  2423 	
   232 	function  on_sidebox_1_content($data) { 
  2424 	function  on_sidebox_message_content($data) { 
   233 		extract($data);
  2425 		extract($data);
   234 		?>
  2426 		?>
   235 	 	<h4><?php _e('Note:','xili-dictionary') ?></h4>
  2427 <h4><?php _e('Note:','xili-dictionary') ?></h4>
   236 		<p><?php echo $message;?></p>
  2428 <p><?php echo $message; ?></p>
   237 		<?php
  2429 		<?php
   238 	}
  2430 	}
   239 	
  2431 	
   240 	function  on_sidebox_2_content() { ?>
  2432 	function get_theme_name () {
   241 	 	
  2433 		if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0
   242 		<p><?php _e('xili-dictionary is a plugin (compatible with xili-language) to build a multilingual dictionary saved in the taxonomy tables of WordPress. With this dictionary, it is possible to create and update .mo file in the current theme folder. And more...','xili-dictionary') ?></p>
  2434 			$theme_name = get_option("stylesheet").' '.__('child of','xili-dictionary').' '.get_option("template"); 
   243 		<fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"><legend><?php echo __("Theme's informations:",'xili-dictionary').' ('.get_option("template").')'; ?></legend>
  2435 		} else {
   244 	 		<p>
  2436 			$theme_name = get_option("template"); 
   245 				<?php $langfolder = (defined('THEME_LANGS_FOLDER')) ? THEME_LANGS_FOLDER : $this->xili_settings['langs_folder'];
  2437 		}
       
  2438 		return $theme_name;
       
  2439 	}
       
  2440 	
       
  2441 	function  on_sidebox_info_content() { 
       
  2442 		$template_directory = $this->get_template_directory;
       
  2443 		
       
  2444 		$theme_name = $this->get_theme_name ();
       
  2445 		if ( $this->xililanguage_ms ) {
       
  2446 	   		echo '<p><em>'.__('xili-language-ms is active !','xili-dictionary').'</em></p>';
       
  2447 	   	
       
  2448 	    } else {
       
  2449 	   		switch ( $this->xililanguage ) {
       
  2450 	   			case 'neveractive';
       
  2451 	   				echo '<p>'.__('xili-language plugin is not present !','xili-dictionary').'</p>';
       
  2452 	   				break;
       
  2453 	   			case 'wasactive';
       
  2454 	   				echo '<p>'.__('xili-language plugin is not activated !','xili-dictionary').'</p><br />';
       
  2455 	   				break;
       
  2456 	   			} 
       
  2457 	   	}
       
  2458 		?>
       
  2459 <p><?php _e('xili-dictionary is a plugin (compatible with xili-language) to build a multilingual dictionary saved in the taxonomy tables of WordPress. With this dictionary, it is possible to create and update .mo file in the current theme folder. And more...','xili-dictionary') ?>
       
  2460 </p>
       
  2461 <fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;">
       
  2462 	<legend><?php echo __("Theme's informations:",'xili-dictionary').' ('. $theme_name .')'; ?></legend>
       
  2463 	<p>
       
  2464 				<?php $langfolder = $this->xili_settings['langs_folder'];
   246 				echo __("Languages sub-folder:",'xili-dictionary').' '. $langfolder; ?><br />
  2465 				echo __("Languages sub-folder:",'xili-dictionary').' '. $langfolder; ?><br />
   247 	 			<?php _e('Available MO files:','xili-dictionary'); echo '<br />';
  2466 	 			<?php 
   248 	 			$this->find_files(get_template_directory(), '/.mo$/', array(&$this,'available_mo_files')) ;?>
  2467 	 			if ( $langfolder == 'unknown' ) { ?><span style='color:red'><?php
   249 	 		</p>
  2468 	 			_e("No languages files are present in theme's folder or theme's sub-folder: <strong>add at least a .po or a .mo inside.</strong><br /> Errors will occur if you try to import or export!",'xili-dictionary'); echo '<br />';	?></span> <?php
   250 	 	</fieldset>
  2469 	 			} else {
       
  2470 	 			_e('Available MO files:','xili-dictionary'); echo '<br />';
       
  2471 	 			if ( file_exists( $this->get_template_directory ) ) // when theme was unavailable
       
  2472 	 				$this->find_files($this->get_template_directory, '/.mo$/', array(&$this,'available_mo_files')) ;
       
  2473 	 			}
       
  2474 	 			
       
  2475 	 			?>
       
  2476 	</p>
       
  2477 </fieldset>
       
  2478 
   251 		
  2479 		
   252 		<?php
  2480 		<?php
   253 	}
  2481 	}
   254 	
  2482 	
   255 	function on_normal_1_content($data) { 
  2483 	function  on_sidebox_style_content() { 
       
  2484 		?>
       
  2485 	<p> <?php _e( 'External file xd-style.css for dashboard (flags, customization)','xili-dictionary' ); ?></p>
       
  2486 		<?php
       
  2487 		if ( ! $this->exists_style_ext ) {
       
  2488 			
       
  2489 			echo '<p>'. __( 'There is no style for dashboard','xili-dictionary' ) .' ('.$this->style_message . ' )</p>';
       
  2490 			
       
  2491 		} else {
       
  2492 			
       
  2493 			echo '<p>'. $this->style_message . '</p>';
       
  2494 		}
       
  2495 		
       
  2496 		if ( $this->xili_settings['external_xd_style'] == "on" ) {
       
  2497 		
       
  2498 			$style_action = __( 'No style for dashboard','xili-dictionary' );
       
  2499 			$what = 'off';
       
  2500 			
       
  2501 		} else {
       
  2502 			
       
  2503 			$style_action = __( 'Activate style for dashboard','xili-dictionary' );
       
  2504 			$what = 'on';
       
  2505 		}
       
  2506 		?>
       
  2507 	
       
  2508 		<fieldset style="margin:2px; padding:6px 6px; "><strong><?php _e('Dictionary Styles','xili-dictionary') ;?></strong><br /><br />
       
  2509 		<?php
       
  2510 			$url = "?post_type=xdmsg&action=setstyle&what=".$what."&amp;page=dictionary_page";
       
  2511 			$nonce_url = wp_nonce_url( $url, 'xdsetstyle' );
       
  2512 		?>
       
  2513    		<a class="action-button grey-button" href="<?php echo $nonce_url ?>" title="<?php _e( 'Change style mode', 'xili-dictionary') ?>"><?php _e( $style_action ) ?></a>
       
  2514 	
       
  2515 	</fieldset> <?php
       
  2516 	}
       
  2517 	
       
  2518 	/**
       
  2519 	 * @since 2.0 with datatables js (ex widefat)
       
  2520 	 *
       
  2521 	 */
       
  2522 	function on_normal_cpt_content_list( $data ) { 
   256 		extract($data); 
  2523 		extract($data); 
   257 		$sortparent = (($this->subselect == '') ? '' : '&amp;tagsgroup_parent_select='.$this->subselect );
  2524 		$sortparent = (($this->subselect == '') ? '' : '&amp;tagsgroup_parent_select='.$this->subselect );
   258 		?>
  2525 		?>
   259 			<table class="widefat">
  2526 <div id="topbanner">
   260 				<thead>
  2527 </div>
   261 				<tr>
  2528 <div id="tableupdating">
   262 					<th scope="col"><a href="?page=dictionary_page"><?php _e('ID') ?></a></th>
  2529 </div>
   263 			        <th scope="col"><a href="?page=dictionary_page&amp;orderby=name<?php echo $sortparent; ?>"><?php _e('Text') ?></a></th>
  2530 <table class="display" id="linestable">
   264 			        
  2531 	<thead>
   265 			        <th scope="col"><a href="?page=dictionary_page&amp;orderby=slug<?php echo $sortparent; ?>"><?php _e('Slug','xili-dictionary') ?></a></th>
  2532 		<tr>
   266 			        <th scope="col" ><?php _e('Group','xili-dictionary') ?></th>
  2533 			<th scope="col" class="center colid"><a href="<?php echo $this->xd_settings_page; ?>" ><?php _e('ID') ?></a></th>
   267 			        
  2534 			<th scope="col" class="coltexte"><a href="<?php echo $this->xd_settings_page.'&amp;orderby=name'.$sortparent; ?>"><?php _e('Text') ?></a>
   268 			        <th colspan="2"><?php _e('Action') ?></th>
  2535 			</th>
   269 				</tr>
  2536 			<th scope="col" class="colslug"><?php _e('Metas','xili-dictionary') ?></th>
   270 				</thead>
  2537 			<th scope="col" class="colgroup center"><?php _e('Save status','xili-dictionary') ?></th>
   271 				<tbody id="the-list">
  2538 			<th colspan="2"><?php _e('Action') ?></th>
   272 			<?php $this->xili_dict_row($orderby,$tagsnamelike,$tagsnamesearch); /* the lines */
  2539 		</tr>
       
  2540 	</thead>
       
  2541 	<tbody id="the-list">
       
  2542 			<?php $this->xili_dict_cpt_row( $orderby, $tagsnamelike, $tagsnamesearch ); /* the lines */
   273 			?>
  2543 			?>
   274 				</tbody>
  2544 	</tbody>
   275 			</table>
  2545 </table>
   276 			<?php if ($action=='edit' || $action=='delete') :?>
  2546 <div id="bottombanner">
   277 				<p>(<a href="?action=add&page=dictionary_page"><?php _e('Add a term','xili-dictionary') ?></a>)</p>
  2547 </div>
   278 	   		<?php endif;	
  2548 			<?php	
   279 	}	
  2549 	}
   280 	
  2550 	
   281 	function on_normal_2_content($data) { 
  2551 	/**
   282 		extract($data); 
  2552 	 * metabox shared by dialogs before actions with XD list
   283 		
  2553 	 *
   284 	 	/* the create - edit - delete form */ ?>
  2554 	 */
   285 	 	<div style="background:#f5f5fe;">
  2555 	 function on_normal_2_files_dialog ( $data ) {
   286 	 	<p id="add_edit"><?php _e($formhow,'xili-dictionary') ?></p>
  2556 		extract( $data ); 
       
  2557 		?>
       
  2558 <div style="background:#f5f5fe;">
       
  2559 	<div class="dialogcontainer" >
       
  2560 		
       
  2561 		<p id="add_edit"><?php _e( $formhow, 'xili-dictionary') ?></p>
   287 		<?php 
  2562 		<?php 
   288 		if ($action=='export' || $action=='importmo' || $action=='import' || $action=='exportpo' ) { ?>
  2563 		if ( $action=='export' || $action=='importmo' || $action=='import' || $action=='exportpo' ) { 
   289 			
  2564 			
   290 			<label for="language_file">
  2565 		 	$theme_name = $this->get_theme_name(); 
   291 			<select name="language_file" ><?php
  2566 			
       
  2567 			// left column ?>
       
  2568 			<div class="dialoglang">
       
  2569 				<label for="language_file">
       
  2570 					<select name="language_file" ><?php
   292 	   			$extend = WPLANG;
  2571 	   			$extend = WPLANG;
   293 	   			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
  2572 	   			$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' );//get_terms(TAXONAME, array('hide_empty' => false));
   294 				if (is_wp_error($listlanguages) || empty($listlanguages)) { 
  2573 				if ( $listlanguages ) {
   295 					$langs_array = $this->xili_settings[XDDICTLANGS];
       
   296 						echo '<option value="" >...</option>';	            	
       
   297 	         		foreach ($langs_array as $lkey => $reflanguage) {
       
   298 	         			echo '<option value="'.$reflanguage[0].'"'; 
       
   299 	     				if ($extend == $reflanguage[0]) { 
       
   300 	     					echo ' selected="selected"';
       
   301 	     				} 
       
   302 	     				echo ">".__($reflanguage[1],'xili-dictionary').'</option>';
       
   303 	         		}
       
   304 	     	 } else { 
       
   305 	     	
       
   306 	     			foreach ($listlanguages as $reflanguage) {
  2574 	     			foreach ($listlanguages as $reflanguage) {
   307 	     				echo '<option value="'.$reflanguage->name.'"'; 
  2575 	     				echo '<option value="'.$reflanguage->name.'"'; 
   308 	     				if ($extend == $reflanguage->name) { 
  2576 	     				if ($extend == $reflanguage->name) { 
   309 	     					echo ' selected="selected"';
  2577 	     					echo ' selected="selected"';
   310 	     				} 
  2578 	     				} 
   311 	     				echo ">".__($reflanguage->description,'xili-dictionary').'</option>';	
  2579 	     				echo ">".__($reflanguage->description,'xili-dictionary').'</option>';	
   312 	     			
  2580 	     			
   313 	     			}
  2581 	     			}
   314 	     		} ?>
  2582 				}
   315 	     	</select></label>
  2583 	     		if ( $action=='import' ) { // to import .pot of current domain 1.0.5
   316 	     	<br />&nbsp;<br />
  2584 	     			if ( function_exists('the_theme_domain') ) {// in new xili-language
   317 			<input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" />&nbsp;&nbsp;&nbsp;&nbsp;<input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /><br /></div>
  2585 	     				echo '<option value="'.the_theme_domain().'" >'.the_theme_domain().'.pot</option>';
       
  2586 	    			} else {
       
  2587 						
       
  2588 						echo '<option value="'.$theme_name.'" >'.$theme_name.'.pot</option>';
       
  2589 					}	
       
  2590 	     		}
       
  2591 	     		?>
       
  2592 						</select>
       
  2593 					</label>
       
  2594 				</div>
       
  2595 		<div class="dialogfile">&nbsp;
       
  2596 	<?php // middle column
       
  2597 	
       
  2598 				if ( $action == 'import' ) {	// import po comment option 2.0-rc2
       
  2599 				
       
  2600 				?>
       
  2601 				
       
  2602 				<label for="importing_po_comments">&nbsp;<?php _e( 'What about comments', 'xili-dictionary' ); ?>:&nbsp;
       
  2603 				<select name="importing_po_comments" id="importing_po_comments">
       
  2604 					<option value="" ><?php _e('No change','xili-dictionary'); ?></option>
       
  2605 					<option value="replace" ><?php _e('Imported comments replace those in list','xili-dictionary'); ?></option>
       
  2606 					<option value="append" ><?php _e('Imported comments be appended...','xili-dictionary'); ?></option>
       
  2607 				</select>	
       
  2608 				</label>
       
  2609 				<?php
       
  2610 				} 
       
  2611 	     	
       
  2612 	     		if ( ($action=='export' || $action=='exportpo' ) && is_multisite() && is_super_admin() && $this->xililanguage_ms ) { ?>
       
  2613 	<p><?php printf (__('Verify before that you are authorized to write in languages folder in theme named: %s','xili-dictionary'), $theme_name ) ?>
       
  2614 	</p>
       
  2615 	     		<?php }
       
  2616 		     	if (  ( $action=='export' || $action=='exportpo' ) && is_multisite() && is_super_admin() && !$this->xililanguage_ms ) { ?>
       
  2617 	<label for="only-theme">
       
  2618 		     	<?php 
       
  2619 		     		if ( $action == 'export' ) {
       
  2620 		             	printf ( __('SuperAdmin: %sonly as theme .mo','xili-dictionary'), '<br />') ;
       
  2621 		            } else {
       
  2622 		             	printf ( __('SuperAdmin: %sonly as theme .po','xili-dictionary'), '<br />') ;
       
  2623 		            }
       
  2624 		             ?>
       
  2625 		<input id="only-theme" name="only-theme" type="checkbox" value="only" />
       
  2626 	</label>
       
  2627 	     	
       
  2628 	     	<?php } 
       
  2629 	     	
       
  2630 	     	if ( $action=='export' || $action=='exportpo' ) { ?>
       
  2631 				<br /><br /><label for="only-local">
       
  2632 		     	<?php 
       
  2633 		     	if ( $action == 'export' ) {
       
  2634 		     		_e('Save only local-xx_XX.mo sub-selection','xili-dictionary'); 
       
  2635 		     	
       
  2636 		     	} else {
       
  2637 		     		_e('Save only local-xx_XX.po sub-selection','xili-dictionary');
       
  2638 		     	}
       
  2639 		     	
       
  2640 		     	?>
       
  2641 				<input id="only-local" name="only-local" type="checkbox" value="local" />
       
  2642 				</label>
       
  2643 	     	
       
  2644 	     	<?php }
       
  2645 	     	
       
  2646 	     	?>
       
  2647 		</div>
       
  2648 		<?php 
       
  2649 		if ( $action=='import' || $action=='importmo' ) { 
       
  2650 			echo '<div class="dialogorigin">';
       
  2651 			echo '<label><input type="checkbox" id="local-import" name="local-import" value="local-import" />&nbsp;' . sprintf(__('import terms from local-xx_YY.%s', 'xili-dictionary'), ( ($action=='import') ? 'po' : 'mo' ) ) . '</label>';
       
  2652 			echo '</div>';
       
  2653 		}
       
  2654 	// check origin theme
       
  2655 		if ( $action=='export' || $action=='exportpo' ) {
       
  2656 			if ( function_exists('is_child_theme') && is_child_theme() ) { 
       
  2657 				$cur_theme_name = get_option("stylesheet"); 
       
  2658 			} else {
       
  2659 				$cur_theme_name = get_option("template"); 
       
  2660 			}
       
  2661 			$listterms = get_terms( 'origin', array('hide_empty' => false) );	
       
  2662 			echo '<div class="dialogorigin">'; 
       
  2663 				if ( $listterms ) {
       
  2664 	 				$checkline = __ ( 'Check Origin(s) to be exported', 'xili-dictionary' ).':<br />';
       
  2665 	 				$i = 0;
       
  2666 	 				echo '<table class="checktheme" ><tr>';
       
  2667 	 			foreach ( $listterms as $onetheme) {
       
  2668 	 				$checked = ( $onetheme->name == $cur_theme_name ) ? 'checked="checked"'  : '' ;
       
  2669 	 				$checkline .= '<td><input type="checkbox" '. $checked .' id="theme-'.$onetheme->term_id.'" name="theme-'.$onetheme->term_id.'" value="'.$onetheme->slug.'" />&nbsp;' . $onetheme->name .'</td>';
       
  2670 	 				$i++;
       
  2671 	 				if ( ($i % 2) == 0 ) $checkline .= '</tr><tr>';
       
  2672 	 			}
       
  2673 	 			echo $checkline.'</tr></table>';
       
  2674 			}
       
  2675 	 	echo '</div>';
       
  2676 	} 
       
  2677 	// end container ?>
       
  2678 	</div>    	
       
  2679 	<div class="dialogbbt">
       
  2680 		<input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
       
  2681 		<input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" />
       
  2682 	</div>
       
  2683 </div>
   318 		<?php
  2684 		<?php
   319 		} elseif ($action=='importcats' || $action=='erasedictionary' || $action=='importcurthemeterms') {
  2685 		} elseif ($action=='importbloginfos' || $action=='importtaxonomy' || $action=='erasedictionary' || $action=='importcurthemeterms') {
       
  2686 			
       
  2687 			if ( $action == 'importtaxonomy' ) { ?>
       
  2688 		<label for="taxonomy_name"><?php _e('Slug:','xili-dictionary') ?></label>
       
  2689 		<input name="taxonomy_name" id="taxonomy_name" type="text" value="<?php echo ( $selecttaxonomy != '') ? $selecttaxonomy : 'category'; ?>" /><br />
       
  2690 			<?php }
   320 			?>
  2691 			?>
   321 			
  2692 		<br />&nbsp;<br />
   322 			<br />&nbsp;<br />
  2693 		<input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
   323 			<input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
  2694 		<input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /><br />
   324 			<input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /><br /></div>
  2695 	</div>
       
  2696 </div>
   325 		<?php
  2697 		<?php
   326 	
  2698 	// nothing inside	
   327 			
       
   328 		} else {
  2699 		} else {
   329 			//print_r($dictioline);
  2700 			echo '<p>'.__( 'This box is used for input dialog, leave it opened and visible…', 'xili-dictionary' ).'</p></div></div>';
   330 			
  2701 		}	
   331 			/* rules for edit dictioline */
  2702 		?>
   332 			$noedit = "" ; $noedited = "" ;
  2703 <?php
   333 			if ($action=='edit' && $dictioline->parent == 0)   {
  2704 	}
   334 				$noedited = 'disabled="disabled"';
  2705 	
   335 				$extend = "";
  2706 	/** 
   336 			} elseif ($action=='edit') {
  2707 	 * @since 2.1
   337 			/* search default */
  2708 	 * built checked themes array
   338 				$extend = substr($dictioline->slug,-5);
  2709 	 * 
   339 			} elseif ($action=='delete' && $dictioline->parent == 0) {	
  2710 	 */
   340 				$noedit = 'disabled="disabled"';
  2711 	function checked_themes_array( ) {
   341 				$extend = "";
  2712 		$checked_themes = array();
   342 			} elseif ($action=='delete') {
  2713 		$listterms = get_terms( 'origin', array('hide_empty' => false) );
   343 				$noedit = 'disabled="disabled"';
  2714 		if ( $listterms ) {
   344 				$extend = substr($dictioline->slug,-5);
  2715 			foreach ( $listterms as $onetheme) {
   345 			}		
  2716 				$idcheck = 'theme-'.$onetheme->term_id;
   346 			?>
  2717 				if ( isset ( $_POST[$idcheck] ) ) $checked_themes[] = $onetheme->name;
   347 		<table class="editform" width="100%" cellspacing="2" cellpadding="5">
  2718 			}
   348 			<tr>
  2719 		}
   349 			<?php if ($action=='edit' || $action=='delete') { 
  2720 		return $checked_themes;
   350 					$areacontent = $dictioline->description;
  2721 	}
   351 					$textareas = explode(XPLURAL,$dictioline->description);
  2722 	
   352 					$firstcontent = $textareas[0]; /* also always before js splitting*/
  2723 	/** 
   353 				} else {
  2724 	 * @updated 1.0.2 
   354 					$areacontent = "";
  2725 	 * manage files 
   355 					$firstcontent = "";
  2726 	 */
   356 				}
  2727 	function on_normal_3_content( $data ) { 
   357 					?>
  2728 		extract( $data );
   358 				<th scope="row" valign="top" align="right" width="25%"><label for="dictioline_description1">
  2729 		?>
   359 					<?php 
  2730 <h4 id="manage_file"><?php _e('The files','xili-dictionary') ;?></h4>
   360 					if ($action=='edit' && $dictioline->parent == 0) {
  2731 <a class="action-button blue-button" href="<?php echo $this->xd_settings_page.'&amp;action=export'; ?>" title="<?php _e('Create or Update mo file in current theme folder','xili-dictionary') ?>"><?php _e('Export mo file','xili-dictionary') ?></a>
   361 						_e('Full msgid (original)','xili-dictionary'); 
  2732 &nbsp;<br /><?php _e('Import po/mo file','xili-dictionary') ?>:<a class="small-action-button" href="<?php echo $this->xd_settings_page.'&amp;action=import'; ?>" title="<?php _e('Import an existing .po file from current theme folder','xili-dictionary') ?>">PO</a>
   362 					} elseif ($action=='edit') {
  2733 <a class="small-action-button" href="<?php echo $this->xd_settings_page.'&amp;action=importmo'; ?>" title="<?php _e('Import an existing .mo file from current theme folder','xili-dictionary') ?>">MO</a><br />
   363 						_e('Full msgstr (translation)','xili-dictionary');
  2734 &nbsp;<br /><a class="action-button grey-button" href="<?php echo $this->xd_settings_page.'&amp;action=exportpo'; ?>" title="<?php _e('Create or Update po file in current theme folder','xili-dictionary') ?>"><?php _e('Export po file','xili-dictionary') ?></a>
   364 					} else {
  2735 
   365 						_e('Full msg (id or str)','xili-dictionary');
  2736 <h4 id="manage_categories"><?php _e('The taxonomies','xili-dictionary') ;?></h4>
   366 					} ?> :&nbsp;</label>
  2737 <a class="action-button blue-button" href="<?php echo $this->xd_settings_page.'&amp;action=importtaxonomy'; ?>" title="<?php _e('Import name and description of taxonomy','xili-dictionary') ?>"><?php _e('Import terms of taxonomy','xili-dictionary') ?></a>
   367 					<textarea style="visibility:hidden" name="dictioline_description" id="dictioline_description" cols="12" rows="3"  disabled="disabled" ><?php echo $areacontent; ?></textarea>
  2738 
   368 				</th>
  2739 <h4 id="manage_website_infos"><?php _e('The website infos (title, sub-title and more…)','xili-dictionary') ;?></h4>
   369 				<td align="left">
  2740 	   	<?php if ( class_exists ('xili_language') && XILILANGUAGE_VER > '2.3.9'	) {
   370 				
  2741 	   		_e ( '…and comment, locale, date terms.', 'xili-dictionary' ); echo '<br /><br />';
   371 				<input type="hidden" id="termnblines" name="termnblines" value="1" />
  2742 	   	} ?>
   372 				
  2743 <a class="action-button blue-button" href="<?php echo $this->xd_settings_page.'&amp;action=importbloginfos'; ?>" title="<?php _e('Import infos of web site and more','xili-dictionary') ?>"><?php _e("Import terms of website's infos",'xili-dictionary') ?></a>
   373 				<div id="input1" style="margin-bottom:4px;" class="clonedInput">
  2744 
   374 				  <p id="areatitle1"><?php _e('Singular text','xili-dictionary'); ?></p>
  2745 	<h4 id="manage_dictionary"><?php _e('Dictionary','xili-dictionary') ;?></h4>
   375 				  <textarea style="visibility:visible" class="plural" name="dictioline_description1" id="dictioline_description1" cols="50" rows="3"  <?php echo $noedit; ?> ><?php echo $firstcontent; ?></textarea>
  2746    		<a class="action-button grey-button" href="?post_type=xdmsg&action=erasedictionary&amp;page=dictionary_page" title="<?php _e('Erase all terms of dictionary ! (but not .mo or .po files)','xili-dictionary') ?>"><?php _e('Erase all terms','xili-dictionary') ?></a>
   376 						
  2747 	
   377 				</div>
  2748 	<?php // erase and import theme 
   378 				<?php if ($action != 'delete') { ?>
  2749 	}
   379 					<div>
  2750 	
   380 						<span style="display:block; float:right; width:60%"><small>&nbsp;<?php _e('Use only plural terms if theme contains _n() functions','xili-dictionary') ?></small></span>
  2751 	/** 
   381 						<input type="button" id="btnAdd" value="<?php _e('Add a plural','xili-dictionary') ?>" />
  2752 	 * @since 090423 - 
   382 						<input type="button" id="btnDel" value="<?php _e('Delete a plural','xili-dictionary') ?>" />
  2753 	 * Sub selection box
   383 						
  2754 	 */
   384 					</div>
       
   385 				<?php } ?>
       
   386 				</td>
       
   387 			
       
   388 			</tr>
       
   389 			<tr class="form-field">
       
   390 				<th scope="row" valign="top" align="right"><label for="dictioline_lang"><?php _e('Language','xili-dictionary') ?></label> :&nbsp;</th>
       
   391 				<td>
       
   392 	  				<select name="dictioline_lang" id="dictioline_lang"  <?php echo $noedit.$noedited;?> >
       
   393 	  					<option value="" <?php if ($extend == '') { ?> selected="selected"<?php } ?>>
       
   394 	  						<?php _e('default','xili-dictionary'); ?></option>
       
   395 	  			<?php $listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $curlang));
       
   396 					if (is_wp_error($listlanguages) || empty($listlanguages)) { 
       
   397 						$langs_array = $this->xili_settings[XDDICTLANGS];
       
   398 							foreach ($langs_array as $lkey => $reflanguage) {
       
   399 	         				echo '<option value="'.$reflanguage[0].'"'; 
       
   400 	     					if ($extend == strtolower($reflanguage[0])) { 
       
   401 	     						echo ' selected="selected"';
       
   402 	     					} 
       
   403 	     					echo ">".__($reflanguage[1],'xili-dictionary').'</option>';
       
   404 	         			}
       
   405 	         		
       
   406 	         		 } else {
       
   407      		foreach ($listlanguages as $reflanguage) {
       
   408      			echo '<option value="'.$reflanguage->slug.'"'; 
       
   409      			if ($extend == $reflanguage->slug) { 
       
   410      				echo ' selected="selected"';
       
   411      			} 
       
   412      			echo ">".__($reflanguage->description,'xili-dictionary').'</option>';	
       
   413      			
       
   414      		}
       
   415      	}
       
   416    	 ?>    
       
   417                 	</select>
       
   418 	  			</td>
       
   419 			</tr>
       
   420 			<tr>
       
   421 				<th scope="row" valign="top" align="right"><label for="dictioline_slug"><?php _e('Term slug','xili-dictionary') ?></label> :&nbsp;</th>
       
   422 				<td><input name="dictioline_slug" id="dictioline_slug" type="text" readonly="readonly" value="<?php echo attribute_escape($dictioline->slug); ?>" size="40" <?php echo $noedit; ?> /></td>
       
   423 			</tr>
       
   424 			<tr class="form-field">
       
   425 				<th scope="row" valign="top" align="right"><label for="dictioline_parent"><?php _e('Relationship (msgid)','xili-dictionary') ?></label> :&nbsp;</th>
       
   426 				<td>
       
   427 					<fieldset style="margin:2px; padding:10px 5px; border:1px solid #ccc;"><legend><?php
       
   428 					 if ($action=='edit' || $action=='delete') {
       
   429 					 	if ($dictioline->parent == 0) {
       
   430 					 		_e('Original','xili-dictionary');
       
   431 					 	} else {
       
   432 					 		_e('Translation','xili-dictionary');
       
   433 					 	}
       
   434 					 } else {
       
   435 					 	_e('Original or translation','xili-dictionary'); 
       
   436 					 } 
       
   437 					 ?></legend>
       
   438 			  			<?php $this->xili_select_row($term_id,$dictioline); /* choice of parent line */?>
       
   439 			  		</fielset>
       
   440              	</td>
       
   441 			</tr>
       
   442 			<tr>
       
   443 				<th scope="row" valign="top" align="right"><label for="alias_of"><?php _e('Alias of','xili-dictionary') ?></label> :&nbsp;</th>
       
   444 				<td><input name="alias_of" id="alias_of" type="text" value="" size="40" <?php echo $noedit; ?> /></td>
       
   445 			</tr>
       
   446 		<?php if ($action=='edit') { ?>
       
   447 			<tr>
       
   448 				<th scope="row" valign="top" align="right" style="color:#eee;"><label for="dictioline_name"><?php _e('Text') ?> :&nbsp;</label></th>
       
   449 				<td style="color:#eee;"><?php echo attribute_escape($dictioline->name); ?></td>
       
   450 			</tr>
       
   451 		<?php } ?>
       
   452 			<tr>
       
   453 				<th><input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /></th>
       
   454 				<td> 
       
   455 					<p class="submit"><input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" /></p>
       
   456 				</td>
       
   457 			</tr>
       
   458 		</table></div>
       
   459 		<?php 
       
   460 			if ($action=='edit' || $action=='delete') { ?>
       
   461 				<input type="hidden" name="dictioline_term_id" value="<?php echo $dictioline->term_id ?>" />
       
   462 			<?php } 
       
   463 			if ($action=='edit') { ?>
       
   464 				<input type="hidden" name="dictioline_name" id="dictioline_name"  value="<?php echo attribute_escape($dictioline->name); ?>" />
       
   465 			<?php }
       
   466 		}
       
   467 	} 
       
   468 	/** * @updated 1.0.2 * manage files */
       
   469 	function on_normal_3_content($data) { ?>
       
   470 		<h4 id="manage_file"><?php _e('The files','xili-dictionary') ;?></h4>
       
   471 	   	<?php 
       
   472 	   	switch ($this->xililanguage) {
       
   473 	   			case 'neveractive';
       
   474 	   				echo '<p>'._e('xili-language plugin is not present !','xili-dictionary').'</p>';
       
   475 	   				break;
       
   476 	   			case 'wasactive';
       
   477 	   				echo '<p>'._e('xili-language plugin is not activated !','xili-dictionary').'</p><br />';
       
   478 	   				break;
       
   479 	   			} 
       
   480 	   	$linkstyle = "text-decoration:none; text-align:center; display:block; width:70%; margin:0px 1px 1px 30px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;" ;
       
   481 	   	$linkstyle3 = "text-decoration:none; text-align:center; display:inline-block; width:16%; margin:0px 1px 1px 10px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;  border:1px #ccc solid;" ;
       
   482 	   	$linkstyle1 = $linkstyle." border:1px #33f solid;";
       
   483 	   	$linkstyle2 = $linkstyle." border:1px #ccc solid;";
       
   484 	   	?>
       
   485 	   		<a style="<?php echo $linkstyle1 ; ?>" href="?action=export&amp;page=dictionary_page" title="<?php _e('Create or Update mo file in current theme folder','xili-dictionary') ?>"><?php _e('Export mo file','xili-dictionary') ?></a>
       
   486 	   	  	&nbsp;<br /><?php _e('Import po/mo file','xili-dictionary') ?>:<a style="<?php echo $linkstyle3 ; ?>" href="?action=import&amp;page=dictionary_page" title="<?php _e('Import an existing .po file from current theme folder','xili-dictionary') ?>">PO</a>
       
   487 	   	  	<a style="<?php echo $linkstyle3 ; ?>" href="?action=importmo&amp;page=dictionary_page" title="<?php _e('Import an existing .mo file from current theme folder','xili-dictionary') ?>">MO</a><br />
       
   488 	   	  	&nbsp;<br /><a style="<?php echo $linkstyle2 ; ?>" href="?action=exportpo&amp;page=dictionary_page" title="<?php _e('Create or Update po file in current theme folder','xili-dictionary') ?>"><?php _e('Export po file','xili-dictionary') ?></a>
       
   489 	   	<h4 id="manage_categories"><?php _e('The categories','xili-dictionary') ;?></h4>
       
   490 	   		<a style="<?php echo $linkstyle2 ; ?>" href="?action=importcats&amp;page=dictionary_page" title="<?php _e('Import name and description of categories','xili-dictionary') ?>"><?php _e('Import terms of categories','xili-dictionary') ?></a>
       
   491 	   	<h4 id="manage_dictionary"><?php _e('Dictionary','xili-dictionary') ;?></h4>
       
   492    		<a style="<?php echo $linkstyle2 ; ?>" href="?action=erasedictionary&amp;page=dictionary_page" title="<?php _e('Erase all terms of dictionary ! (but not .mo or .po files)','xili-dictionary') ?>"><?php _e('Erase all terms','xili-dictionary') ?></a>
       
   493    		&nbsp;<br /><a style="<?php echo $linkstyle2 ; ?>" href="?action=importcurthemeterms&amp;page=dictionary_page" title="<?php _e('Import all terms from current theme files - alpha test -','xili-dictionary') ?>"><?php _e('Import all terms from current theme','xili-dictionary') ?></a>	
       
   494 	
       
   495 	<?php
       
   496 	}
       
   497 	/** * @since 090423 - */
       
   498 	function on_normal_4_content($data=array()) {
  2755 	function on_normal_4_content($data=array()) {
   499 		extract($data);
  2756 		extract($data);
   500 		?>
  2757 		?>
   501 			<fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Sub list of terms','xili-dictionary'); ?></legend>
  2758 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;">
   502 			<label for="tagsnamelike"><?php _e('Starting with:','xili-dictionary') ?></label> 
  2759 	<legend><?php _e('Sub list of terms','xili-dictionary'); ?></legend>
   503 			<input name="tagsnamelike" id="tagsnamelike" type="text" value="<?php echo $tagsnamelike; ?>" /><br />
  2760 	<label for="tagsnamelike"><?php _e('Starting with:','xili-dictionary') ?></label>
   504 			<label for="tagsnamesearch"><?php _e('Containing:','xili-dictionary') ?></label> 
  2761 	<input name="tagsnamelike" id="tagsnamelike" type="text" value="<?php echo $tagsnamelike; ?>" /><br />
   505 			<input name="tagsnamesearch" id="tagsnamesearch" type="text" value="<?php echo $tagsnamesearch; ?>" />
  2762 	<label for="tagsnamesearch"><?php _e('Containing:','xili-dictionary') ?></label>
   506 			<p class="submit"><input type="submit" id="tagssublist" name="tagssublist" value="<?php _e('Sub select…','xili-dictionary'); ?>" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" id="notagssublist" name="notagssublist" value="<?php _e('No select…','xili-dictionary'); ?>" /></p>
  2763 	<input name="tagsnamesearch" id="tagsnamesearch" type="text" value="<?php echo $tagsnamesearch; ?>" />
   507 			</fieldset>
  2764 	<p class="submit">
   508 			
  2765 		<input type="submit" id="tagssublist" name="tagssublist" value="<?php _e('Sub select…','xili-dictionary'); ?>" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   509 			<fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Selection by language','xili-dictionary'); ?></legend>
  2766 		<input type="submit" id="notagssublist" name="notagssublist" value="<?php _e('No select…','xili-dictionary'); ?>" />
   510 			<select name="tagsgroup_parent_select" id="tagsgroup_parent_select" style="width:100%;">
  2767 	</p>
   511 		  				<option value="no_select" ><?php _e('No sub-selection','xili-dictionary'); ?></option>
  2768 </fieldset>
       
  2769 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;">
       
  2770 	<legend><?php _e('Selection by language','xili-dictionary'); ?></legend>
       
  2771 	<select name="tagsgroup_parent_select" id="tagsgroup_parent_select" style="width:100%;">
       
  2772 		<option value="no_select" ><?php _e('No sub-selection','xili-dictionary'); ?></option>
   512 		  				<?php $checked = ($this->subselect == "msgid") ? 'selected="selected"' :'' ; 
  2773 		  				<?php $checked = ($this->subselect == "msgid") ? 'selected="selected"' :'' ; 
   513 		  				echo '<option value="msgid" '.$checked.' >'.__('Only MsgID (en_US)','xili-dictionary').'</option>'; 		  	
  2774 		  				echo '<option value="msgid" '.$checked.' >'.__('Only MsgID (en_US)','xili-dictionary').'</option>';
   514 		  				echo $this->build_grouplist();		  				
  2775 		  				$checked = ($this->subselect == "msgstr") ? 'selected="selected"' :'' ; 
       
  2776 		  				echo '<option value="msgstr" '.$checked.' >'.__('Only Msgstr','xili-dictionary').'</option>';
       
  2777 		  				$checked = ($this->subselect == "msgstr_0") ? 'selected="selected"' :'' ; 
       
  2778 		  				echo '<option value="msgstr_0" '.$checked.' >'.__('Only Msgstr plural','xili-dictionary').'</option>';  		  	
       
  2779 		  				echo $this->build_grouplist();
       
  2780 		  				echo $this->build_grouplist('nottransin_');	// 2.1.2 - not translated in	  				
   515 		  				?>
  2781 		  				?>
   516 		  	</select>			
  2782 	</select>
   517 		  	<br /> <p class="submit"><input type="submit" id="subselection" name="subselection" value="<?php _e('Sub select…','xili-dictionary'); ?>" /></p>
  2783 	<br />
   518 			</fieldset>
  2784 	<p class="submit">
       
  2785 		<input type="submit" id="subselection" name="subselection" value="<?php _e('Sub select…','xili-dictionary'); ?>" />
       
  2786 	</p>
       
  2787 </fieldset>
   519 		<?php
  2788 		<?php
   520 	}
  2789 	}
   521 	/** * @since 1.0.2 * only if xili-language plugin is absent */ 
  2790 	/** 
       
  2791 	 * @since 1.0.2 
       
  2792 	 * only if xili-language plugin is absent 
       
  2793 	 */ 
   522 	function on_normal_5_content($data=array()) {
  2794 	function on_normal_5_content($data=array()) {
   523 		extract($data);
  2795 		extract($data);
   524 		?>
  2796 		?>
   525 		<fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Language to delete','xili-dictionary'); ?></legend>
  2797 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;">
   526 			<p><?php _e('Only the languages list is here modified (but not the dictionary\'s contents)','xili-dictionary'); ?></p>
  2798 	<legend><?php _e('Language to delete','xili-dictionary'); ?></legend>
   527 			<select name="langs_list" id="langs_list" style="width:100%;">
  2799 	<p><?php _e('Only the languages list is here modified (but not the dictionary\'s contents)','xili-dictionary'); ?>
   528 		  				<option value="no_select" ><?php _e('Select...','xili-dictionary'); ?></option>
  2800 	</p>
       
  2801 	<select name="langs_list" id="langs_list" style="width:100%;">
       
  2802 		<option value="no_select" ><?php _e('Select...','xili-dictionary'); ?></option>
   529 		  				<?php echo $this->build_grouplist('');
  2803 		  				<?php echo $this->build_grouplist('');
   530 		  				?>
  2804 		  				?>
   531 		  	</select>
  2805 	</select>
   532 		  	<br />
  2806 	<br />
   533 		  	<p class="submit"><input type="submit" id="lang_delete" name="lang_delete" value="<?php _e('Delete a language','xili-dictionary'); ?>" /></p></fieldset><br />
  2807 	<p class="submit">
   534 		  	<fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Language to add','xili-dictionary'); ?></legend>
  2808 		<input type="submit" id="lang_delete" name="lang_delete" value="<?php _e('Delete a language','xili-dictionary'); ?>" />
   535 		  	<label for="lang_ISO"><?php _e('ISO (xx_YY)','xili-dictionary') ?></label>:&nbsp; 
  2809 	</p>
   536 			<input name="lang_ISO" id="lang_ISO" type="text" value="" size="5"/><br />
  2810 </fieldset><br />
   537 			<label for="lang_name"><?php _e('Name (eng.)','xili-dictionary') ?></label>:&nbsp; 
  2811 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;">
   538 			<input name="lang_name" id="lang_name" type="text" value="" size="20" />
  2812 	<legend><?php _e('Language to add','xili-dictionary'); ?></legend>
   539 			<br />
  2813 	<label for="lang_ISO"><?php _e('ISO (xx_YY)','xili-dictionary') ?></label>:&nbsp;
   540 			<p class="submit"><input type="submit" id="lang_add" name="lang_add" value="<?php _e('Add a language','xili-dictionary'); ?>" /></p>
  2814 	<input name="lang_ISO" id="lang_ISO" type="text" value="" size="5"/><br />
   541 		</fieldset>
  2815 	<label for="lang_name"><?php _e('Name (eng.)','xili-dictionary') ?></label>:&nbsp;
       
  2816 	<input name="lang_name" id="lang_name" type="text" value="" size="20" />
       
  2817 	<br />
       
  2818 	<p class="submit">
       
  2819 		<input type="submit" id="lang_add" name="lang_add" value="<?php _e('Add a language','xili-dictionary'); ?>" />
       
  2820 	</p>
       
  2821 </fieldset>
   542 	<?php }
  2822 	<?php }
       
  2823 	
   543 	/**
  2824 	/**
   544 	 * build the list of group of languages for dictionary
  2825 	 * build the list of group of languages for dictionary
   545 	 *
  2826 	 *
   546 	 * @updated 1.0.2
  2827 	 * @updated 1.0.2
   547 	 *
  2828 	 *
   548 	 */
  2829 	 */
   549 	 function build_grouplist ($left_line = 'Only:') {
  2830 	 function build_grouplist ($left_line = '') {
   550 	 	if ($this->xililanguage == 'isactive') {
  2831 	 	  
   551 	 		$listdictlanguages = get_terms(XDDICTLANGS, array('hide_empty' => false));
  2832 	 		$listdictlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
       
  2833 	 		$optionlist = "";
       
  2834 	 		$lefttext = "";
       
  2835 	 		if ( $left_line == 'nottransin_' ) $lefttext = __('not translated in','xili-dictionary').' ';
   552 	 		foreach($listdictlanguages as $dictlanguage) {
  2836 	 		foreach($listdictlanguages as $dictlanguage) {
   553 	 			$checked = ($this->subselect == $dictlanguage->slug) ? 'selected="selected"' :'' ; 
  2837 	 			$checked = ($this->subselect == $left_line.$dictlanguage->slug) ? 'selected="selected"' :'' ; 
   554 		  		$optionlist .= '<option value="'.$dictlanguage->slug.'" '.$checked.' >'.__('Only:','xili-dictionary').' '.$dictlanguage->name.'</option>'; 
  2838 		  		$optionlist .= '<option value="'.$left_line.$dictlanguage->slug.'" '.$checked.' >'.$lefttext.$dictlanguage->name .' ('.$dictlanguage->description.')</option>'; 
   555 	 		}
  2839 	 		}
   556 	 	} else {
  2840 	 	
   557 	 		$langs_array = $this->xili_settings[XDDICTLANGS];
       
   558 			foreach ($langs_array as $lkey => $dictlanguage) {
       
   559 	         	$checked = ($this->subselect == $lkey) ? 'selected="selected"' :'' ; 
       
   560 		  		$optionlist .= '<option value="'.$lkey.'" '.$checked.' >'.__($left_line,'xili-dictionary').' '.$dictlanguage[0].'</option>'; 
       
   561 			}
       
   562 	 	}	
       
   563 	 	return $optionlist;
  2841 	 	return $optionlist;
   564 	 }
  2842 	 }
       
  2843 	 
   565 	 /**
  2844 	 /**
   566 	  * @since 0.9.9
  2845 	  * @since 1.3.3
   567 	  * 
  2846 	  * 
   568 	  *
  2847 	  *
   569 	  */
  2848 	  */
   570 	 function test_and_create_slug($description, $slug, $lang='') {
  2849 	 function xd_wp_set_object_terms( $term_id, $lang_slug, $taxo_dictgroup , $bool = false) {
   571 	 	$slug = sanitize_title(str_replace(' ','_',$slug));
  2850 	 	
   572 	 	//echo $slug;
  2851 	 	// check if lang_slug exists in this dict taxonomy
   573 	 	$found = is_term($slug,DTAXONAME);
  2852 	 	if ( ! $term_info = term_exists($lang_slug, $taxo_dictgroup) ) { 
   574 	 	if ($found){
  2853 			// Skip if a non-existent term ID is passed.
   575 	 		/* compare description*/
  2854 			if ( is_int( $term_info ) ) 
   576 	 		$found_term = get_term($found['term_id'],DTAXONAME);
  2855 				continue;
   577 	 		if ($found_term->description == $description) {
  2856 			$args = array( 'alias_of' => '', 'description' => 'Dictionary Group in '.$lang_slug );	
   578 	 			return $slug;
  2857 			$term_info = wp_insert_term($lang_slug, $taxo_dictgroup, $args); //print_r ($term_info);
   579 	 		} else {
  2858 		}
   580 	 			if ( '' == $lang) {
  2859 	 	wp_set_object_terms( $term_id, $lang_slug, $taxo_dictgroup, $bool );
   581 	 				//echo 'nul';
  2860 	 
   582 	 				$slug = $slug.'z';
       
   583 	 			   	return $this->test_and_create_slug($description, $slug, $lang);
       
   584 	 			} else {
       
   585 	 				//echo $slug;
       
   586 	 				$theslug = str_replace('_'.$lang,'',$slug);
       
   587 	 				$theslug = $theslug.'z'.'_'.$lang; /* risk the parent term cannot be created after */
       
   588 	 				return $this->test_and_create_slug($description, $theslug, $lang);
       
   589 	 			}
       
   590 	 		}
       
   591 	 	} else {
       
   592 	 		//echo 'pas nul';
       
   593 	 		return $slug;
       
   594 	 	}
       
   595 	 }
  2861 	 }
   596 	/** * @since 1.0.0 */
  2862 	 
   597 	function xili_dic_update_term($term, $taxonomy, $args) {
  2863 		
   598 		remove_filter('pre_term_description', 'wp_filter_kses'); /* 0.9.8.2 to allow more tag in msg str or id */
  2864 	/**
   599 		$rterm_id = wp_update_term( $term, $taxonomy, $args);
  2865 	 * Dashboard - Manage - Dictionary
   600 		add_filter('pre_term_description', 'wp_filter_kses');
  2866 	 *  
   601 		return $rterm_id;
  2867 	 * @since 0.9
   602 	}
  2868 	 * @updated 2.0
   603 	function xili_dic_insert_term($termname, $taxonomy, $args) {
  2869 	 *
   604 		remove_filter('pre_term_description', 'wp_filter_kses'); /* 0.9.8.2 to allow more tag in msg str or id */
  2870 	 */
   605 		$rterm_id = wp_insert_term( $termname, $taxonomy, $args);
       
   606 		add_filter('pre_term_description', 'wp_filter_kses');
       
   607 		return $rterm_id;
       
   608 	}
       
   609 		
       
   610 	/* Dashboard - Manage - Dictionary */
       
   611 	function xili_dictionary_settings() { 
  2871 	function xili_dictionary_settings() { 
   612 		$formtitle = __('Add a term','xili-dictionary');
  2872 		$action = "";
       
  2873 		
       
  2874 		$term_id = 0;
       
  2875 		$formtitle = __('Dialog box','xili-dictionary');
   613 		$formhow = " ";
  2876 		$formhow = " ";
   614 		$submit_text = __('Add &raquo;','xili-dictionary');
  2877 		$submit_text = __('Do &raquo;','xili-dictionary');
   615 		$cancel_text = __('Cancel');
  2878 		$cancel_text = __('Cancel');
   616 		$this->langfolder = (defined('THEME_LANGS_FOLDER') && THEME_LANGS_FOLDER !='/')  ? '/'.str_replace("/","",THEME_LANGS_FOLDER).'/' : "/";
  2879 		$langfolderset = $this->xili_settings['langs_folder'];
   617 		$tagsnamelike = $_POST['tagsnamelike'];
  2880 		$this->langfolder = ( $langfolderset !='' )  ? $langfolderset.'/' : '/';
       
  2881 		// doublon 
       
  2882 		$this->langfolder = str_replace ("//","/", $this->langfolder ); // upgrading... 2.0 and sub folder sub
       
  2883 		$selecttaxonomy = "";
       
  2884 		
       
  2885 		$tagsnamelike = ( isset ( $_POST['tagsnamelike'] ) ) ? $_POST['tagsnamelike'] : '';
   618 		if (isset($_GET['tagsnamelike']))
  2886 		if (isset($_GET['tagsnamelike']))
   619 		    $tagsnamelike = $_GET['tagsnamelike']; /* if link from table */
  2887 		    $tagsnamelike = $_GET['tagsnamelike']; /* if link from table */
   620 		$tagsnamesearch = $_POST['tagsnamesearch'];
  2888 		$tagsnamesearch = ( isset ( $_POST['tagsnamesearch'] ) ) ? $_POST['tagsnamesearch'] : '';
   621 		if (isset($_GET['tagsnamesearch']))
  2889 		if (isset($_GET['tagsnamesearch']))
   622 			$tagsnamesearch = $_GET['tagsnamesearch'];
  2890 			$tagsnamesearch = $_GET['tagsnamesearch'];
   623 		
  2891 		
   624 		if (isset($_POST['reset'])) {
  2892 		if (isset($_POST['reset'])) {
   625 			$action=$_POST['reset'];
  2893 			$action=$_POST['reset'];
   628 			$action=$_POST['action'];
  2896 			$action=$_POST['action'];
   629 		}
  2897 		}
   630 		
  2898 		
   631 		if (isset($_GET['action'])) {
  2899 		if (isset($_GET['action'])) {
   632 			$action=$_GET['action'];
  2900 			$action=$_GET['action'];
   633 			$term_id = $_GET['term_id'];
  2901 			
   634 		}
  2902 		}
   635 		/* language delete or add */
  2903 		/* language delete or add */
   636 		if (isset($_POST['lang_delete'])) {
  2904 		if (isset($_POST['lang_delete'])) {
   637 			$action='lang_delete';
  2905 			$action='lang_delete';
   638 		}
  2906 		}
   650 		if (isset($_GET['orderby'])) :
  2918 		if (isset($_GET['orderby'])) :
   651 			$orderby = $_GET['orderby'] ;
  2919 			$orderby = $_GET['orderby'] ;
   652 		else :
  2920 		else :
   653 			$orderby = 't.term_id'; /* 0.9.8 */
  2921 			$orderby = 't.term_id'; /* 0.9.8 */
   654 		endif;
  2922 		endif;
   655 		if(isset($_POST['tagsgroup_parent_select']) && $_POST['tagsgroup_parent_select'] != 'no_select') {
  2923 		if ( isset($_POST['tagsgroup_parent_select']) && $_POST['tagsgroup_parent_select'] != 'no_select') {
   656 				$this->subselect = $_POST['tagsgroup_parent_select'];
  2924 				$this->subselect = $_POST['tagsgroup_parent_select'];
   657 			} else {
  2925 			} else {
   658 				$this->subselect = '';
  2926 				$this->subselect = '';
   659 			}
  2927 			}
   660 		if (isset($_GET['tagsgroup_parent_select']))
  2928 		if ( isset($_GET['tagsgroup_parent_select']))
   661 			$this->subselect = $_GET['tagsgroup_parent_select'];
  2929 			$this->subselect = $_GET['tagsgroup_parent_select'];
   662 				
  2930 				
   663 		if (isset($_POST['subselection'])) {
  2931 		if (isset($_POST['subselection'])) {
   664 			$action='subselection';
  2932 			$action='subselection';
   665 		}
  2933 		}
   666 		
  2934 		
   667 		$message = $action." = " ;
  2935 		if ( function_exists('is_child_theme') && is_child_theme() ) { 
   668 	switch($action) {
  2936 			$cur_theme_name = get_option("stylesheet"); 
   669 		
  2937 		} else {
       
  2938 			$cur_theme_name = get_option("template"); 
       
  2939 		}
       
  2940 		
       
  2941 		$message = ''; //$action." = " ; 
       
  2942 		$msg = 0;
       
  2943 		switch($action) {
       
  2944 		
       
  2945 		case 'setstyle'; // external xd-style.css
       
  2946 			check_admin_referer( 'xdsetstyle' );
       
  2947 			if ( isset ( $_GET['what'] ) ) {
       
  2948 				$what = 'off';
       
  2949 				if ( $_GET['what'] == 'on' ) {
       
  2950 					$what = 'on';
       
  2951 				} else if ( $_GET['what'] == 'off' ) {
       
  2952 					$what = 'off';
       
  2953 				}
       
  2954 			   	$this->xili_settings['external_xd_style'] = $what ;	
       
  2955 			   	update_option('xili_dictionary_settings', $this->xili_settings);
       
  2956 			}
       
  2957 			$actiontype = "add";
       
  2958 			break;
       
  2959 			
   670 		case 'lang_delete';
  2960 		case 'lang_delete';
   671 				$reflang = $_POST['langs_list'];
  2961 			$reflang = $_POST['langs_list'];
   672 				$wp_lang = (defined('WPLANG')) ? strtolower(WPLANG) : 'en_us'; 
  2962 			$wp_lang = (defined('WPLANG')) ? strtolower(WPLANG) : 'en_us'; 
   673 				if ($reflang != 'no_select' &&  $reflang != 'en_us' &&  $reflang != $wp_lang) {
  2963 			if ($reflang != 'no_select' &&  $reflang != 'en_us' &&  $reflang != $wp_lang) {
   674 					unset($this->xili_settings[XDDICTLANGS][$reflang]);
  2964 				$ids = term_exists($reflang, TAXONAME);
   675 					update_option('xili_dictionary_settings', $this->xili_settings);
  2965 				if ( $ids ) {
   676 					$message .= ' '.$reflang.' deleted';
  2966 					if ( is_wp_error( $ids )  ) {
   677 				} else { 
  2967 						$message .= ' '.$reflang.' error';
   678 					$message .= ' nothing to delete';
  2968 					} else {
   679 				}				
  2969 						$t_id = $ids['term_id'];
   680 				
  2970 						wp_delete_term( $t_id, TAXONAME );
   681 				$actiontype = "add";
  2971 						$message .= ' '.$reflang.' deleted';
   682 				break;
  2972 					}
       
  2973 				} else {
       
  2974 					$message .= ' '.$reflang.' not exist';
       
  2975 				}
       
  2976 				
       
  2977 			} else { 
       
  2978 				$message .= ' nothing to delete';
       
  2979 			}				
       
  2980 			
       
  2981 			$actiontype = "add";
       
  2982 			break;
   683 								
  2983 								
   684 		case 'lang_add';
  2984 		case 'lang_add';
   685 				$reflang = ('' != $_POST['lang_ISO'] ) ? $_POST['lang_ISO'] : "???";
  2985 				$reflang = ('' != $_POST['lang_ISO'] ) ? $_POST['lang_ISO'] : "???";
   686 				$reflangname = ('' !=$_POST['lang_name']) ? $_POST['lang_name'] : $reflang; 
  2986 				$reflangname = ('' !=$_POST['lang_name']) ? $_POST['lang_name'] : $reflang; 
   687 				if ($reflang != '???' && strlen($reflang) == 5 && substr($reflang,2,1) == '_') {
  2987 				if ($reflang != '???' && ( ( strlen($reflang) == 5 && substr($reflang,2,1) == '_') ) || ( strlen($reflang) == 2 ) ) {
   688 					$lkey = strtolower($reflang);
  2988 					
   689 					$reflang = strtolower(substr($reflang,0,3)).strtoupper(substr($reflang,-2));
  2989 					$args = array( 'alias_of' => '', 'description' => $reflangname, 'parent' => 0, 'slug' =>strtolower( $reflang ));
   690 					$msg = (array_key_exists($lkey, $this->xili_settings[XDDICTLANGS])) ? ' updated' : ' added';
  2990 					$theids = $this->safe_lang_term_creation ( $reflang, $args );
   691 					$this->xili_settings[XDDICTLANGS][$lkey] = array($reflang,$reflangname);
  2991 					wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP);
   692 					update_option('xili_dictionary_settings', $this->xili_settings);
       
   693 					$message .= ' '.$reflang.$msg;
  2992 					$message .= ' '.$reflang.$msg;
   694 				} else {
  2993 				} else {
   695 					$message .= ' error ('.$reflang.') ! no add';
  2994 					$message .= ' error ('.$reflang.') ! no add';
   696 				}
  2995 				}
   697 				
  2996 				
   714 			
  3013 			
   715 		case 'tagssublist';
  3014 		case 'tagssublist';
   716 				$message .= ' sub list of terms starting with '.$_POST['tagsnamelike'];
  3015 				$message .= ' sub list of terms starting with '.$_POST['tagsnamelike'];
   717 				$actiontype = "add";
  3016 				$actiontype = "add";
   718 				break;
  3017 				break;
   719 		
  3018 				    
   720 		case 'add':
       
   721 			
       
   722 			$originalortrans = $_POST['dictioline_description1'];
       
   723 			$nblines = $_POST['termnblines']; /**/
       
   724 			if ( $nblines > 1 )  {
       
   725 				for ($i = 2; $i <= $nblines; $i++) {
       
   726 					$originalortrans .= XPLURAL.$_POST['dictioline_description'.$i];
       
   727 				}
       
   728 			}
       
   729 			
       
   730 			/*create the slug with term and add prefix*/
       
   731 			$possible = true;
       
   732 			if (''!=$_POST['dictioline_lang']) {
       
   733 			  if ('no_parent' != $_POST['dictioline_parent'] ) {
       
   734 				$parent_id = $_POST['dictioline_parent'];
       
   735 				$parent_term = get_term($parent_id,DTAXONAME,OBJECT,'edit');
       
   736 				$sslug = $parent_term->slug.'_'.$_POST['dictioline_lang'] ;
       
   737 				
       
   738 				$lang = $_POST['dictioline_lang'];
       
   739 			  } else {
       
   740 			  	$message .= __('No parent term defined','xili-dictionary');
       
   741 			  	$possible = false;
       
   742 			  }
       
   743 			} else {
       
   744 				$lang = '';
       
   745 				/* is content plural */
       
   746 				if (false === strpos($originalortrans,XPLURAL)) {			
       
   747 					$sslug = htmlentities($originalortrans);
       
   748 						
       
   749 				} else {
       
   750 					$plurals = explode (XPLURAL,$originalortrans);
       
   751 					$sslug = htmlentities($plurals[0]);	/* in term slug only first*/
       
   752 				}	
       
   753 			}
       
   754 			$sslug = $this->test_and_create_slug($originalortrans, $sslug, $lang);	
       
   755 			
       
   756 			if ($possible) {
       
   757 				$aliasof = $_POST['alias_of'];			
       
   758 				$args = array('alias_of' => $aliasof, 'description' => $originalortrans, 'parent' => $_POST['dictioline_parent'], 'slug' => $sslug);
       
   759 				
       
   760 			    $rterm_id = $this->xili_dic_insert_term( $originalortrans, DTAXONAME, $args);
       
   761 			    
       
   762 			    if (''!=$_POST['dictioline_lang']) {
       
   763 				    if (is_wp_error($rterm_id)) {$message .= ' ---- error ---- '; $possible = false ;} else {
       
   764 				    	wp_set_object_terms((int) $rterm_id['term_id'], $_POST['dictioline_lang'], XDDICTLANGS,false);	
       
   765 				    }
       
   766 			    } else {
       
   767 			    	if (is_wp_error($rterm_id)) { $message .= ' ---- error ---- '; $possible = false ; } else { $message .= " (". $rterm_id['term_id'] .") "; }
       
   768 			    }
       
   769 			}
       
   770 		    $actiontype = "add";
       
   771 		    if ($possible) $message .= " - ".__('A new term was added.','xili-dictionary');
       
   772 		     break;
       
   773 		    
       
   774 		case 'edit';
       
   775 		    $actiontype = "edited";
       
   776 		    
       
   777 		    $dictioline = get_term($term_id,DTAXONAME,OBJECT,'edit');
       
   778 		    $submit_text = __('Update &raquo;','xili-dictionary');
       
   779 		    $formtitle = 'Edit term';
       
   780 		    $message .= " - ".__('Term to update.','xili-dictionary');
       
   781 		    break;
       
   782 		    
       
   783 		case 'edited';
       
   784 		    $actiontype = "add";
       
   785 		    $term = $_POST['dictioline_term_id'];
       
   786 		    $termname = $_POST['dictioline_name']; 
       
   787 		    $sslug = $_POST['dictioline_slug'];
       
   788 		    $originalortrans = $_POST['dictioline_description1'];
       
   789 			$nblines = $_POST['termnblines']; /**/
       
   790 			if ( $nblines > 1 )  {
       
   791 				for ($i = 2; $i <= $nblines; $i++) {
       
   792 					$originalortrans .= XPLURAL.$_POST['dictioline_description'.$i];
       
   793 				}
       
   794 			}
       
   795 		    
       
   796 			if (''!=$_POST['dictioline_lang']) {
       
   797 				$parent_id = $_POST['dictioline_parent'];
       
   798 				$parent_term = get_term($parent_id,DTAXONAME,OBJECT,'edit');
       
   799 				$sslug = $parent_term->slug.'_'.$_POST['dictioline_lang'] ;
       
   800 			}
       
   801 			
       
   802 			$args = array('name'=>$termname, 'alias_of' => $_POST['alias_of'], 'description' => $originalortrans , 'parent' => $_POST['dictioline_parent'], 'slug' => $sslug);
       
   803 		    
       
   804 		    $this->xili_dic_update_term($term, DTAXONAME, $args);
       
   805 		    
       
   806 			if (''!=$_POST['dictioline_lang']) {
       
   807 			    if (is_wp_error($rterm_id)) {$message .= ' ---- error ---- ';} else {
       
   808 			    	wp_set_object_terms((int) $rterm_id['term_id'], $_POST['dictioline_lang'], XDDICTLANGS,false);	
       
   809 			    }
       
   810 		    }
       
   811 			$message .= " - ".__('A term was updated.','xili-dictionary').' '.$_POST['dictioline_term_id'];
       
   812 		    break;
       
   813 		    
       
   814 		case 'delete';
       
   815 		    $actiontype = "deleting";
       
   816 		    $submit_text = __('Delete &raquo;','xili-dictionary');
       
   817 		    $formtitle = 'Delete term ?';
       
   818 		    $dictioline = get_term($term_id,DTAXONAME,OBJECT,'edit');
       
   819 		    
       
   820 		    $message .= " - ".__('A term to delete. CLICK MENU DICTIONARY TO CANCEL !','xili-dictionary');
       
   821 		    
       
   822 		    break;
       
   823 		    
       
   824 		case 'deleting';
       
   825 		    $actiontype = "add";
       
   826 		    $term_id = $_POST['dictioline_term_id'];
       
   827 		    wp_delete_object_term_relationships( $term_id, XDDICTLANGS ); 
       
   828 		    wp_delete_term( $term_id, DTAXONAME, $args);
       
   829 		    $message .= " - ".__('A term was deleted.','xili-dictionary');
       
   830 		    $term_id = 0; /* 0.9.7.2 */
       
   831 		    break;
       
   832 		    
       
   833 		case 'export';
  3019 		case 'export';
   834 			 $actiontype = "exporting";
  3020 			 $actiontype = "exporting";
   835 			 $formtitle = __('Export mo file','xili-dictionary');
  3021 			 $formtitle = __('Export mo file','xili-dictionary');
   836 			 $formhow = __('To create a .mo file, choose language and click below.','xili-dictionary');
  3022 			 $formhow = __('To create a .mo file, choose language and click below.','xili-dictionary');
   837 			 $submit_text = __('Export &raquo;','xili-dictionary');
  3023 			 $submit_text = __('Export &raquo;','xili-dictionary');
   838 		     break;
  3024 		     break;
   839 		case 'exporting';
  3025 		     
       
  3026 		case 'exporting'; // MO
       
  3027 			check_admin_referer( 'xilidicoptions' );
   840 			$actiontype = "add";
  3028 			$actiontype = "add";
   841 			$selectlang = $_POST['language_file'];
  3029 			$selectlang = $_POST['language_file'];
   842 		     if ("" != $selectlang){
  3030 		     if ("" != $selectlang){
   843 		     	//$this->xili_create_mo_file(strtolower($selectlang));
  3031 		     	//$this->xili_create_mo_file(strtolower($selectlang));
   844 		     	$mo = $this->from_twin_to_POMO ($selectlang);
  3032 		     	$file = "";
   845 		     	if (false === $this->Save_MO_to_file ($selectlang , $mo )) {
  3033 		     	$extract_array = array();
   846 		     		$message .= ' '.sprintf(__('error during exporting in  %1s.mo file.','xili-dictionary'),$selectlang);
  3034 		     	$checked_themes = $this->checked_themes_array(); 
       
  3035 		     	if ( is_multisite() ) { /* complete theme's language with db structure languages (cats, desc,…) in uploads */
       
  3036 					//global $wpdb;
       
  3037     				//$thesite_ID = $wpdb->blogid;
       
  3038    					$superadmin = ( isset ( $_POST['only-theme'] ) && $_POST['only-theme'] == 'only') ? true : false ;
       
  3039    					$message .= ( isset ( $_POST['only-theme'] ) && $_POST['only-theme'] == 'only') ? "- exported only in theme - " : "- exported in uploads - " ;
       
  3040    					
       
  3041    					
       
  3042    					if (($uploads = xili_upload_dir()) && false === $uploads['error'] ) {
       
  3043    						
       
  3044    						if ( $superadmin === true )  {
       
  3045    							if ( isset ( $_POST['only-local'] ) && $_POST['only-local'] == 'local' ) {
       
  3046    								$local = 'local';
       
  3047 		     					$extract_array [ $this->msg_extracted_comments ] = $this->local_tag;
       
  3048 			     				$extract_array [ 'like-'.$this->msg_extracted_comments ] = true;
       
  3049 		     					$file = $this->get_template_directory.$this->langfolder.'local-'.$selectlang.'.mo' ;
       
  3050 		     				} else {
       
  3051 		     					$extract_array [ 'origin' ] = $checked_themes;
       
  3052 		     					$local = '';
       
  3053 		     					$file = '';
       
  3054 		     				}
       
  3055    						} else {
       
  3056    							if ( isset ( $_POST['only-local'] ) && $_POST['only-local'] == 'local' ) {
       
  3057    								$local = 'local';
       
  3058 		     					$extract_array [ $this->msg_extracted_comments ] = $this->local_tag;
       
  3059 			     				$extract_array [ 'like-'.$this->msg_extracted_comments ] = true;
       
  3060 		     					$file = $uploads['path']."/local-".$selectlang.".mo" ; 
       
  3061 		     				} else {
       
  3062 		     					$extract_array [ 'origin' ] = $checked_themes;
       
  3063 		     					$local = '';
       
  3064 		     					$file = $uploads['path']."/".$selectlang.".mo" ;
       
  3065 		     				}
       
  3066    						}
       
  3067    						
       
  3068    						$mo = $this->from_cpt_to_POMO_wpmu ( $selectlang, 'mo', $superadmin, $extract_array );  // do diff if not superadmin
       
  3069    					} 
       
  3070     			} else {
       
  3071 		     		
       
  3072 		     		if ( isset ( $_POST['only-local'] ) && $_POST['only-local'] == 'local' ) {
       
  3073 		     			$local = 'local';
       
  3074 		     			$extract_array [ $this->msg_extracted_comments ] = $this->local_tag;
       
  3075 			     		$extract_array [ 'like-'.$this->msg_extracted_comments ] = true;
       
  3076 		     			$file = $this->get_template_directory.$this->langfolder.'local-'.$selectlang.'.mo' ;
       
  3077 		     		} else {
       
  3078 		     			$extract_array [ 'origin' ] = $checked_themes;
       
  3079 		     			$local = '';
       
  3080 		     			$file = '';
       
  3081 		     		}
       
  3082 		     		
       
  3083 		     		$mo = $this->from_cpt_to_POMO ( $selectlang, 'mo', $extract_array );
       
  3084 		     	}
       
  3085 		     	if ( count ($mo->entries) > 0 ){ // 2.2
       
  3086 		     		if ( false === $this->Save_MO_to_file ($selectlang , $mo, $file ) ) { 
       
  3087 		     			$message .= $file.' '.sprintf(__('error during exporting in %2s %1s.mo file.','xili-dictionary'), $selectlang, $local);
       
  3088 		     		} else {
       
  3089 		     			$message .= ' '.sprintf(__('exported in %2s %1s.mo file with %3s msgids.','xili-dictionary'),$selectlang, $local, count ($mo->entries));
       
  3090 		     		}
   847 		     	} else {
  3091 		     	} else {
   848 		     		$message .= ' '.sprintf(__('exported in %1s.mo file.','xili-dictionary'),$selectlang);
  3092 	     			$message .= sprintf('<span class="alert">'.__('Nothing in %s, not updated', 'xili-dictionary').'</span>', $local.$selectlang.'.mo');
   849 		     	}
  3093 	     		}
   850 		     }	else {
  3094 		     }	else {
   851 		     	$message .= ' : error "'.$selectlang.'"';
  3095 		     	$message .= ' : error "'.$selectlang.'"';
   852 		     }	
  3096 		     }
       
  3097 		     $msg = 6 ;	
   853 		     break;
  3098 		     break;
   854 		     
  3099 		     
   855 		case 'exportpo';
  3100 		case 'exportpo';
   856 			 $actiontype = "exportingpo";
  3101 			 $actiontype = "exportingpo";
   857 			 $formtitle = __('Export po file','xili-dictionary');
  3102 			 $formtitle = __('Export po file','xili-dictionary');
   858 			 $formhow = __('To export terms in a .po file, choose language and click below.','xili-dictionary');
  3103 			 $formhow = __('To export terms in a .po file, choose language and click below.','xili-dictionary');
   859 			 $submit_text = __('Export &raquo;','xili-dictionary');
  3104 			 $submit_text = __('Export &raquo;','xili-dictionary');
   860 		     break;
  3105 		     break;
   861 		case 'exportingpo';
  3106 		     
       
  3107 		case 'exportingpo'; // PO
       
  3108 			check_admin_referer( 'xilidicoptions' );
   862 			$actiontype = "add";
  3109 			$actiontype = "add";
   863 			$selectlang = $_POST['language_file'];
  3110 			$selectlang = $_POST['language_file'];
   864 		     if ("" != $selectlang){
  3111 		     if ("" != $selectlang){
   865 		     	$po = $this->from_twin_to_POMO ($selectlang,'po');
  3112 		     	
   866 		     	//if ($this->xili_exportterms_inpo(strtolower($selectlang))) {
  3113 		     	$extract_array = array();
   867 		     	if (false === $this->Save_PO_to_file ($selectlang , $po )) {	
  3114 		     	$checked_themes = $this->checked_themes_array();
   868 		     		$message .= ' '.sprintf(__('error during exporting in  %1s.po file.','xili-dictionary'),$selectlang);
  3115 		     	if ( is_multisite() ) { /* complete theme's language with db structure languages (cats, desc,…) in uploads */
       
  3116 					
       
  3117    					$superadmin = ( isset ( $_POST['only-theme'] ) && $_POST['only-theme'] == 'only') ? true : false ;
       
  3118    					$message .= ( isset ( $_POST['only-theme'] ) && $_POST['only-theme'] == 'only') ? "- exported only in theme - " : "- exported in uploads - " ;
       
  3119    					
       
  3120    					if (($uploads = xili_upload_dir()) && false === $uploads['error'] ) {
       
  3121    						
       
  3122    						if ( $superadmin === true )  {
       
  3123    							if ( isset ( $_POST['only-local'] ) && $_POST['only-local'] == 'local' ) {
       
  3124 		     					$local = 'local';
       
  3125 			     				$extract_array [ $this->msg_extracted_comments ] = $this->local_tag;
       
  3126 			     				$extract_array [ 'like-'.$this->msg_extracted_comments ] = true;
       
  3127 		     					$file = $this->get_template_directory.$this->langfolder.'local-'.$selectlang.'.po' ; // theme folder
       
  3128 		     				} else {
       
  3129 		     					$local = '';
       
  3130 		     					$file = '';
       
  3131 		     				}
       
  3132    						} else {
       
  3133    							if ( isset ( $_POST['only-local'] ) && $_POST['only-local'] == 'local' ) {
       
  3134 		     					$local = 'local';
       
  3135 			     				$extract_array [ $this->msg_extracted_comments ] = $this->local_tag;
       
  3136 			     				$extract_array [ 'like-'.$this->msg_extracted_comments ] = true;
       
  3137 		     					$file = $uploads['path']."/local-".$selectlang.".po" ; // blogs.dir folder
       
  3138 		     				} else {
       
  3139 		     					$extract_array [ 'origin' ] = $checked_themes;
       
  3140 			     				
       
  3141 		     					$local = '';
       
  3142 		     					$file = $uploads['path']."/".$selectlang.".po" ;
       
  3143 		     				}
       
  3144    						}
       
  3145    						  
       
  3146    					} 
       
  3147     			} else { // standalone
       
  3148 		     	
       
  3149 			     	if ( isset ( $_POST['only-local'] ) && $_POST['only-local'] == 'local' ) {
       
  3150 			     		$local = 'local';
       
  3151 			     		$extract_array [ $this->msg_extracted_comments ] = $this->local_tag;
       
  3152 			     		$extract_array [ 'like-'.$this->msg_extracted_comments ] = true;
       
  3153 			     		
       
  3154 			     		$file = $this->get_template_directory.$this->langfolder.'local-'.$selectlang.'.po' ;
       
  3155 			     	} else {
       
  3156 			     		$extract_array [ 'origin' ] = $checked_themes;
       
  3157 			     		$local = '';
       
  3158 			     		$file = '';
       
  3159 			     	}
       
  3160     			}
       
  3161 		     	
       
  3162 		     	
       
  3163 		     	
       
  3164 		     	$po = $this->from_cpt_to_POMO ( $selectlang, 'po', $extract_array );
       
  3165 		     	if ( count ($po->entries) > 0 ){ // 2.2
       
  3166 		     		if ( false === $this->Save_PO_to_file ( $selectlang , $po, $file ) ) {	
       
  3167 		     			$message .= ' '.sprintf(__('error during exporting in %2s  %1s.po file.','xili-dictionary'), $selectlang, $local );
       
  3168 		     		} else {
       
  3169 		     			$message .= ' '.sprintf(__('exported in %2s %1s.po file with %3s msgids.','xili-dictionary'), $selectlang, $local, count ($po->entries));
       
  3170 		     		}
   869 		     	} else {
  3171 		     	} else {
   870 		     		$message .= ' '.sprintf(__('exported in %1s.po file.','xili-dictionary'),$selectlang);
  3172 	     			$message .= sprintf('<span class="alert">'.__('Nothing saved in %s, not updated', 'xili-dictionary').'</span>', $local.$selectlang.'.po');
   871 		     	}	
  3173 	     		}	
   872 		     } else {
  3174 		     } else {
   873 		     	$message .= ' : error "'.$selectlang.'"';
  3175 		     	$message .= ' : error "'.$selectlang.'"';
   874 		     }	
  3176 		     }	
   875 		     break; 
  3177 		     break; 
   876 		         
  3178 		         
   878 			$actiontype = "importing";
  3180 			$actiontype = "importing";
   879 		    $formtitle = __('Import po file','xili-dictionary');
  3181 		    $formtitle = __('Import po file','xili-dictionary');
   880 		    $formhow = __('To import terms of the current .po, choose language and click below.','xili-dictionary');
  3182 		    $formhow = __('To import terms of the current .po, choose language and click below.','xili-dictionary');
   881 			$submit_text = __('Import &raquo;','xili-dictionary'); 
  3183 			$submit_text = __('Import &raquo;','xili-dictionary'); 
   882 		    break;
  3184 		    break;
       
  3185 		    
   883 		case 'importmo';
  3186 		case 'importmo';
   884 			$actiontype = "importingmo";
  3187 			$actiontype = "importingmo";
   885 		    $formtitle = __('Import mo file','xili-dictionary');
  3188 		    $formtitle = __('Import mo file','xili-dictionary');
   886 		    $formhow = __('To import terms of the current .mo, choose language and click below.','xili-dictionary');
  3189 		    $formhow = __('To import terms of the current .mo, choose language and click below.','xili-dictionary');
   887 			$submit_text = __('Import &raquo;','xili-dictionary'); 
  3190 			$submit_text = __('Import &raquo;','xili-dictionary'); 
   888 		    break;
  3191 		    break;
   889 		    
  3192 		    
   890 		case 'importing';
  3193 		case 'importing';  // PO
   891 			$actiontype = "add";
  3194 			$actiontype = "add";
   892 		    $message .= ' '.__('line imported from po file: ','xili-dictionary');
  3195 		    $message .= ' '.__('line imported from po file: ','xili-dictionary');
   893 		    $selectlang = $_POST['language_file'];
  3196 		    $selectlang = $_POST['language_file'];
       
  3197 		    $this->importing_po_comments = $_POST['importing_po_comments']; // 2.0-rc2 
   894 		    
  3198 		    
   895 		    $po = $this->pomo_import_PO ($selectlang); //print_r($po);
  3199 		    if ( isset ( $_POST['local-import'] ) && $_POST['local-import'] == 'local-import' ) {
   896 		    if (false !== $po ) $twintexts = $this->from_PO_to_twin ($po);
  3200 		    	$local = 'local-';
   897 			
  3201 		    	if ( is_multisite() ) {
   898 			if (is_array($twintexts)) {
  3202 		    		
   899 				$nblines = $this->xili_import_in_tables($twintexts,$selectlang); 
  3203 		    		$po = $this->pomo_import_PO ( $selectlang, true ); // temp - only in theme if model
   900 				$message .= __('id lines = ','xili-dictionary').$nblines[0].' & ' .__('str lines = ','xili-dictionary').$nblines[1].' & ' .__('str lines up = ','xili-dictionary').$nblines[2];
  3204 		    	
       
  3205 		    	} else {
       
  3206 		    		
       
  3207 		    		$po = $this->pomo_import_PO ( $selectlang, true );
       
  3208 		    	}
       
  3209 		    
       
  3210 		    } else {
       
  3211 		    	$local = '';
       
  3212 		    	$po = $this->pomo_import_PO ( $selectlang ); 
       
  3213 		    }
       
  3214 		    
       
  3215 		    if (false !== $po ) {
       
  3216 		    	$this->origin_theme = $cur_theme_name ;
       
  3217 				$nblines = $this->from_pomo_to_cpts ( $po, $selectlang ) ; //echo "new method"; 
       
  3218 		    
       
  3219 				$message .= ' - '. __('id lines = ','xili-dictionary').$nblines[0].' & ' .__('str lines = ','xili-dictionary').$nblines[1] ;
   901 			} else {
  3220 			} else {
   902 				
  3221 				
   903 		    	$readfile = get_template_directory().$this->langfolder.$selectlang.'.po';
  3222 		    	$readfile = $this->get_template_directory.$this->langfolder.$local.$selectlang.'.po';
   904 				$message .= ' '.$readfile.__('po file is not present.','xili-dictionary');
  3223 				$message .= ' '.$readfile.' > '.__('po file is not present.','xili-dictionary');
   905 			}	
  3224 			}	
   906 		    break;
  3225 		    break;
   907 		
  3226 		
   908 		case 'importingmo';
  3227 		case 'importingmo';  // MO
   909 			$actiontype = "add";
  3228 			$actiontype = "add";
   910 		    $message .= ' '.__('line imported from mo file: ','xili-dictionary');
  3229 		    $message .= ' '.__('line imported from mo file: ','xili-dictionary');
   911 		    $selectlang = $_POST['language_file'];
  3230 		    $selectlang = $_POST['language_file'];
   912 		    $mo = $this->pomo_import_MO ($selectlang);
  3231 		    
   913 		    if (false !== $mo ) $twintexts = $this->from_MO_to_twin ($mo);
  3232 		    if ( isset ( $_POST['local-import'] ) && $_POST['local-import'] == 'local-import' ) { 
   914 		    if (is_array($twintexts)) {
  3233 		    	$local = 'local-';
   915 		    	$nblines = $this->xili_import_in_tables($twintexts,$selectlang); 
  3234 		    	if ( is_multisite() ) {
   916 				$message .= __('id lines = ','xili-dictionary').$nblines[0].' & ' .__('str lines = ','xili-dictionary').$nblines[1].' & ' .__('str lines up = ','xili-dictionary').$nblines[2];
  3235 		    		if ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) {
       
  3236 						$folder = $uploads['basedir']."/languages";
       
  3237 	 				}
       
  3238 	 				$folder_file = $folder . '/local-' . $selectlang . '.mo';
       
  3239 		    		$mo = $this->pomo_import_MO ( $selectlang, $folder_file, false ); // - only in local site if saved - false because folder_file
       
  3240 		    	
       
  3241 		    	} else {
       
  3242 		    		
       
  3243 		    		$mo = $this->pomo_import_MO ( $selectlang, '', true ); // file set in function
       
  3244 		    	}
       
  3245 		    } else {
       
  3246 		    	$local = '';
       
  3247 		    	$mo = $this->pomo_import_MO ( $selectlang ); 
       
  3248 		    }
       
  3249 		   
       
  3250 		    if (false !== $mo ) {
       
  3251 		    	$this->origin_theme = $cur_theme_name ;
       
  3252 		    	$nblines = $this->from_pomo_to_cpts ( $mo, $selectlang ) ; 
       
  3253 		    
       
  3254 				$message .= ' - '.__('id lines = ','xili-dictionary').$nblines[0].' & ' .__('str lines = ','xili-dictionary').$nblines[1];
   917 		    } else {				
  3255 		    } else {				
   918 		    	$readfile = get_template_directory().$this->langfolder.$selectlang.'.mo';
  3256 		    	$readfile = $this->get_template_directory.$this->langfolder.$local.$selectlang.'.mo';
   919 				$message .= ' '.$readfile.__('mo file is not present.','xili-dictionary');
  3257 				$message .= ' '.$readfile.' > '.__('mo file is not present.','xili-dictionary');
   920 			}	
  3258 			}	
   921 		    break;
  3259 		    break;
   922 		    	
  3260 		
   923 		case 'importcats';
  3261 		case 'importbloginfos'; // bloginfos and others since 1.1.0 
   924 			$actiontype = "importingcats";
  3262 			$actiontype = "importingbloginfos";
   925 		    $formtitle = __('Import terms of categories','xili-dictionary');
  3263 		    $formtitle = __('Import terms of blog info and others…','xili-dictionary');
   926 		    $formhow = __('To import terms of the current categories, click below.','xili-dictionary');
  3264 		    $formhow = __('To import terms of blog info and others…, click below.','xili-dictionary');
   927 			$submit_text = __('Import category’s terms &raquo;','xili-dictionary'); 
  3265 			$submit_text = __('Import blog info terms &raquo;','xili-dictionary');
   928 		    break;
  3266 			break;
   929 		
  3267 		
   930 		case 'importingcats';
  3268 		case 'importingbloginfos'; // bloginfos and others since 1.1.0
       
  3269 		  	check_admin_referer( 'xilidicoptions' );
   931 			$actiontype = "add";
  3270 			$actiontype = "add";
   932 		    $message .= ' '.__('terms imported from WP: ','xili-dictionary');
       
   933 		    
  3271 		    
   934 		    $catterms = $this->xili_read_catsterms();
  3272 		    $infosterms = $this->xili_import_infosterms_cpt (); 
   935 			
  3273 			 
   936 			if (is_array($catterms)) {
  3274 			$msg = 4;
   937 				$nbterms = $this->xili_importcatsterms_in_tables($catterms); 
  3275 			if ($infosterms[1] > 0) {
   938 				$message .= __('names = ','xili-dictionary').$nbterms[0].' & ' .__('descs = ','xili-dictionary').$nbterms[1];
  3276 				$message .= ' ('.$infosterms[1].'/'.$infosterms[0].') '.__('imported with success','xili-dictionary');
   939 			} else {
  3277 			} else {
   940 				$message .= ' '.$readfile.__('category’terms pbs!','xili-dictionary');
  3278 				$message .= ' '.__('already imported','xili-dictionary') . ' (' .$infosterms[0].') ';
   941 			}	
  3279 			}	
   942 		    break;
  3280 		    break;
       
  3281 		  	
       
  3282 		case 'importtaxonomy';
       
  3283 			$actiontype = "importingtax";
       
  3284 		    $formtitle = __('Import terms of taxonomy','xili-dictionary');
       
  3285 		    $formhow = __('To import terms of the current taxonomy named, click below.', 'xili-dictionary');
       
  3286 			$submit_text = __('Import taxonomy’s terms &raquo;', 'xili-dictionary'); 
       
  3287 		    break;
       
  3288 		
       
  3289 		case 'importingtax';
       
  3290 			check_admin_referer( 'xilidicoptions' );
       
  3291 			$actiontype = "add";
       
  3292 		    $selecttaxonomy = $_POST['taxonomy_name']; // 
       
  3293 		    if ( taxonomy_exists( $selecttaxonomy ) ) {
       
  3294 		    	$nbterms = $this->xili_read_catsterms_cpt( $selecttaxonomy, $this->local_tag ); //$this->xili_read_catsterms();
       
  3295 		    	$msg = 4;
       
  3296 				if ( is_array($nbterms) ) {
       
  3297 				//$nbterms = $this->xili_importcatsterms_in_tables($catterms); 
       
  3298 					$message .= __('names = ','xili-dictionary').$nbterms[0].' & ' .__('descs = ','xili-dictionary').$nbterms[1];
       
  3299 				} else {
       
  3300 					$message .= ' '.sprintf(__('taxonomy -%s- terms pbs!', 'xili-dictionary'), $selecttaxonomy );
       
  3301 				}
       
  3302 		    } else {
       
  3303 		    	$msg = 8;
       
  3304 		    	$message .= ' '.sprintf(__('taxonomy -%s- do not exists', 'xili-dictionary'), $selecttaxonomy );
       
  3305 		    }
       
  3306 				
       
  3307 		    break;
       
  3308 		    
   943 		 case 'erasedictionary';
  3309 		 case 'erasedictionary';
   944 			$actiontype = "erasingdictionary";
  3310 			$actiontype = "erasingdictionary";
   945 		    $formtitle = __('Erase all terms','xili-dictionary');
  3311 		    $formtitle = __('Erase all terms','xili-dictionary');
   946 		    $formhow = __('To erase terms of the dictionary, click below. (before, create a .po if necessary!)');
  3312 		    $formhow = __('To erase terms of the dictionary, click below. (before, create a .po if necessary!)');
   947 			$submit_text = __('Erase all terms &raquo;','xili-dictionary'); 
  3313 			$submit_text = __('Erase all terms &raquo;','xili-dictionary'); 
   948 		    break;
  3314 		    break;
       
  3315 		    
   949 		 case 'erasingdictionary';
  3316 		 case 'erasingdictionary';
       
  3317 		 	check_admin_referer( 'xilidicoptions' );
       
  3318 		 	
       
  3319 		 	$selection = ""; // $selecttaxonomy = $_POST['erasing_selection'];
       
  3320 		 	$this->erase_dictionary( $selection );
       
  3321 		 	
       
  3322 		 	
   950 			$actiontype = "add";
  3323 			$actiontype = "add";
   951 		    $message .= ' '.__('All terms erased !','xili-dictionary'); 
  3324 		    $message .= ' '.__('All terms erased !','xili-dictionary'); $msg = 7;
   952 		    $listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false));
  3325 		    // for next update
   953 		    if (!empty($listdictiolines)) {
       
   954 		    	foreach ($listdictiolines as $dictioline) {
       
   955 		    		wp_delete_object_term_relationships( $dictioline->term_id, XDDICTLANGS );
       
   956 		    		wp_delete_term($dictioline->term_id, DTAXONAME, $args);
       
   957 		    	}
       
   958 		    	$dictioline = null;
       
   959 		    }
       
   960 		    break; 
  3326 		    break; 
       
  3327 		    
   961 		 case 'importcurthemeterms';
  3328 		 case 'importcurthemeterms';
   962 		 	$actiontype = "importingcurthemeterms";
  3329 		 	$actiontype = "importingcurthemeterms";
   963 		    $formtitle = __('Import all terms from current theme','xili-dictionary');
  3330 		    $formtitle = __('Import all terms from current theme','xili-dictionary');
   964 		    $formhow = __('To import terms of the current theme, click below.','xili-dictionary');
  3331 		    $formhow = __('To import terms of the current theme, click below.','xili-dictionary');
   965 			$submit_text = __('Import all terms &raquo;','xili-dictionary'); 
  3332 			$submit_text = __('Import all terms &raquo;','xili-dictionary'); 
   968 			$themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),2);
  3335 			$themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),2);
   969 			$formhow = $this->tempoutput.'<br /><br /><strong>'.$formhow .'</strong>';
  3336 			$formhow = $this->tempoutput.'<br /><br /><strong>'.$formhow .'</strong>';
   970 			
  3337 			
   971 		    break;
  3338 		    break;
   972 		 
  3339 		 
   973 		 case 'importingcurthemeterms';   
  3340 		 case 'importingcurthemeterms';   // temporary inactive 2.1
   974 		    $actiontype = "add";
  3341 		    $actiontype = "add";
   975 		    $message .= ' '.__('All terms imported !','xili-dictionary');
  3342 		    $message .= ' '.__('All terms imported !','xili-dictionary'); $msg = 5 ;
   976 		    	$themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),0);
  3343 		    	$themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),0);
   977 		    if (is_array($themeterms)) {
  3344 		    if (is_array($themeterms)) {
   978 				$nbterms = $this->xili_importthemeterms_in_tables($themeterms); 
  3345 				//$nbterms = $this->xili_importthemeterms_in_tables($themeterms); 
   979 				$message .= __('terms = ','xili-dictionary').$nbterms;
  3346 				$message .= __('terms = ','xili-dictionary').$nbterms;
   980 			} else {
  3347 			} else {
   981 				$message .= ' '.$readfile.__('theme’s terms pbs!','xili-dictionary');
  3348 				$message .= ' '.$readfile.__('theme’s terms pbs!','xili-dictionary');
   982 			}
  3349 			}
   983 		    break;  
  3350 		    break;  
   984 	     case 'reset';    
  3351 	     case 'reset';    
   985 			    $actiontype = "add";
  3352 			    $actiontype = "add";
   986 			    break;    
  3353 			    break;    
   987 		default:
  3354 		default:
   988 		    $actiontype = "add";
  3355 		    $actiontype = "add";
   989 		    $message .= ' '.__('Find above the list of terms.','xili-dictionary');
  3356 		    $message .= ' '.__('Find below the list of terms.','xili-dictionary');
   990 		        
  3357 		        
   991 		}
  3358 		}
   992 		/* register the main boxes always available */
  3359 		/* register the main boxes always available */
   993 		
  3360 		
   994 		add_meta_box('xili-dictionary-sidebox-3', __('Import & export','xili-dictionary'), array(&$this,'on_normal_3_content'), $this->thehook , 'side', 'core'); /* files */
  3361 		add_meta_box('xili-dictionary-sidebox-3', __('Import & export','xili-dictionary'), array(&$this,'on_normal_3_content'), $this->thehook , 'side', 'core'); /* files */
   995 		add_meta_box('xili-dictionary-sidebox-4', __('Terms list management','xili-dictionary'), array(&$this,'on_normal_4_content'), $this->thehook , 'side', 'core'); /* files */
  3362 		add_meta_box('xili-dictionary-sidebox-4', __('Terms list management','xili-dictionary'), array(&$this,'on_normal_4_content'), $this->thehook , 'side', 'core'); /* files */
   996 		if ($this->xililanguage != 'isactive')
  3363 		if ($this->xililanguage != 'isactive')
   997 				add_meta_box('xili-dictionary-sidebox-5', __('Languages list management','xili-dictionary'), array(&$this,'on_normal_5_content'), $this->thehook , 'side', 'core'); /* Languages list when xili-language is absent */
  3364 				add_meta_box('xili-dictionary-sidebox-5', __('Languages list management','xili-dictionary'), array(&$this,'on_normal_5_content'), $this->thehook , 'side', 'core'); /* Languages list when xili-language is absent */
   998 		
  3365 		
   999 		add_meta_box('xili-dictionary-normal-2', __('Multilingual Terms','xili-dictionary'), array(&$this,'on_normal_1_content'), $this->thehook , 'normal', 'core'); /* list of terms*/
  3366 		add_meta_box('xili-dictionary-normal-1', __( $formtitle, 'xili-dictionary'), array(&$this,'on_normal_2_files_dialog'), $this->thehook , 'normal', 'core'); /* input form */
  1000 		add_meta_box('xili-dictionary-normal-1', __($formtitle,'xili-dictionary'), array(&$this,'on_normal_2_content'), $this->thehook , 'normal', 'core'); /* input form */
  3367 		add_meta_box('xili-dictionary-normal-cpt', __('Multilingual Terms','xili-dictionary'), array(&$this,'on_normal_cpt_content_list'), $this->thehook , 'normal', 'core'); /* list of terms*/
  1001 		
  3368 		
       
  3369 		
       
  3370 		// since 1.2.2 - need to be upgraded...
       
  3371 		if ($msg == 0 && $message != '' ) $msg = 6 ; //by temporary default
       
  3372 		$themessages[1] = __('A new term was added.','xili-dictionary');
       
  3373 		$themessages[2] = __('A term was updated.','xili-dictionary');
       
  3374 		$themessages[3] = __('A term was deleted.','xili-dictionary');
       
  3375 		$themessages[4] = __('terms imported from WP: ','xili-dictionary') . $message;
       
  3376 		$themessages[5] = __('All terms imported !','xili-dictionary');
       
  3377 		$themessages[6] = 'beta testing log: '.$message ;
       
  3378 		$themessages[7] = __('All terms erased !','xili-dictionary');
       
  3379 		$themessages[8] = __('Error when adding !','xili-dictionary');
       
  3380 		$themessages[9] = __('Error when updating !','xili-dictionary');
  1002 		
  3381 		
  1003 		/* form datas in array for do_meta_boxes() */
  3382 		/* form datas in array for do_meta_boxes() */
  1004 		$data = array('message'=>$message,'messagepost'=>$messagepost,'action'=>$action, 'formtitle'=>$formtitle, 'dictioline'=>$dictioline,'submit_text'=>$submit_text,'cancel_text'=>$cancel_text, 'formhow'=>$formhow, 'orderby'=>$orderby,'term_id'=>$term_id, 'tagsnamesearch'=>$tagsnamesearch, 'tagsnamelike'=>$tagsnamelike);
  3383 		$data = array('message'=>$message, 'action'=>$action, 'formtitle'=>$formtitle, 'submit_text'=>$submit_text,'cancel_text'=>$cancel_text, 'formhow'=>$formhow, 'orderby'=>$orderby,'term_id'=>$term_id, 'tagsnamesearch'=>$tagsnamesearch, 'tagsnamelike'=>$tagsnamelike, 'selecttaxonomy' =>$selecttaxonomy);
       
  3384 		if ( isset ( $dictioline ) )  $data['dictioline'] = $dictioline ;
       
  3385 		
  1005 		?>
  3386 		?>
  1006 		<div id="xili-dictionary-settings" class="wrap" style="min-width:850px">
  3387 <div id="xili-dictionary-settings" class="wrap columns-2" style="min-width:850px">
  1007 			<?php screen_icon('tools'); ?>
  3388 			<?php screen_icon('tools'); ?>
  1008 			<h2><?php _e('Dictionary','xili-dictionary') ?></h2>
  3389 	<h2><?php _e('Dictionary','xili-dictionary') ?></h2>
  1009 			<form name="add" id="add" method="post" action="tools.php?page=dictionary_page">
  3390 			<?php if (0!= $msg ) { // 1.2.2 ?>
  1010 				<input type="hidden" name="action" value="<?php echo $actiontype ?>" />
  3391 	<div id="message" class="updated fade"><p><?php echo $themessages[$msg]; ?></p></div>
       
  3392 			<?php }
       
  3393 			 
       
  3394 			global $wp_version;
       
  3395 		if ( version_compare($wp_version, '3.3.9', '<') ) {
       
  3396 			$poststuff_class = 'class="metabox-holder has-right-sidebar"';
       
  3397 			$postbody_class = "";
       
  3398 			$postleft_id = "";
       
  3399 			$postright_id = "side-info-column";
       
  3400 			$postleft_class = "";
       
  3401 			$postright_class = "inner-sidebar";
       
  3402 		} else { // 3.4
       
  3403 			$poststuff_class = "";
       
  3404 			$postbody_class = 'class="metabox-holder columns-2"';
       
  3405 			$postleft_id = 'id="postbox-container-2"';
       
  3406 			$postright_id = "postbox-container-1";
       
  3407 			$postleft_class = 'class="postbox-container"';
       
  3408 			$postright_class = "postbox-container";
       
  3409 		}
       
  3410 			?>
       
  3411 	<form name="add" id="add" method="post" action="<?php echo $this->xd_settings_page; ?>">
       
  3412 		<input type="hidden" name="action" value="<?php echo $actiontype ?>" />
  1011 				<?php wp_nonce_field('xili-dictionary-settings'); ?>
  3413 				<?php wp_nonce_field('xili-dictionary-settings'); ?>
       
  3414 				<?php wp_nonce_field('xilidicoptions'); ?>
  1012 				<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
  3415 				<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
  1013 				<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); 
  3416 				<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); 
  1014 				/* 0.9.6 add has-right-sidebar for next wp 2.8*/ ?>
  3417 				/* 0.9.6 add has-right-sidebar for next wp 2.8*/ ?>
  1015 				<div id="poststuff" class="metabox-holder has-right-sidebar">
  3418 		<div id="poststuff"  <?php echo $poststuff_class; ?> >
  1016 					<div id="side-info-column" class="inner-sidebar">
  3419 			
       
  3420 			<div id="post-body" <?php echo $postbody_class; ?> >
       
  3421 				<div id="<?php echo $postright_id; ?>" class="<?php echo $postright_class; ?>">
  1017 						<?php do_meta_boxes($this->thehook, 'side', $data); ?>
  3422 						<?php do_meta_boxes($this->thehook, 'side', $data); ?>
       
  3423 				</div>
       
  3424 				<div id="post-body-content" >
       
  3425 					<div <?php echo $postleft_id; ?> <?php echo $postleft_class; ?> style="min-width:360px">
       
  3426 	   					<?php do_meta_boxes($this->thehook, 'normal', $data); ?>
  1018 					</div>
  3427 					</div>
  1019 					<div id="post-body" class="has-sidebar has-right-sidebar">
  3428 					<h4><a href="http://dev.xiligroup.com/xili-dictionary" title="Plugin page and docs" target="_blank" style="text-decoration:none" ><img style="vertical-align:middle" src="<?php echo plugins_url( 'images/xilidico-logo-32.jpg', __FILE__ ) ; ?>" alt="xili-dictionary logo"/></a> - © <a href="http://dev.xiligroup.com" target="_blank" title="<?php _e('Author'); ?>" >xiligroup.com</a>™ - msc 2007-12 - v. <?php echo XILIDICTIONARY_VER; ?></h4>
  1020 						<div id="post-body-content" class="has-sidebar-content" style="min-width:360px">
       
  1021 					
       
  1022 	   					<?php do_meta_boxes($this->thehook, 'normal', $data); ?>
       
  1023 						</div>
       
  1024 						 	
       
  1025 					<h4><a href="http://dev.xiligroup.com/xili-dictionary" title="Plugin page and docs" target="_blank" style="text-decoration:none" ><img style="vertical-align:middle" src="<?php echo WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)).'/xilidico-logo-32.gif'; ?>" alt="xili-dictionary logo"/>  xili-dictionary</a> - © <a href="http://dev.xiligroup.com" target="_blank" title="<?php _e('Author'); ?>" >xiligroup.com</a>™ - msc 2007-9 - v. <?php echo XILIDICTIONARY_VER; ?></h4>
       
  1026 							
       
  1027 					</div>
       
  1028 				</div>
  3429 				</div>
  1029 		</form>
  3430 			</div>
       
  3431 			<br class="clear" />
  1030 		</div>
  3432 		</div>
  1031 		<script type="text/javascript">
  3433 	</form>
  1032 			//<![CDATA[
  3434 </div>
  1033 			jQuery(document).ready( function($) {
  3435 		
  1034 				// close postboxes that should be closed
       
  1035 				$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
       
  1036 				// postboxes setup
       
  1037 				postboxes.add_postbox_toggles('<?php echo $this->thehook; ?>');
       
  1038 			});
       
  1039 			//]]>
       
  1040 		</script> 
       
  1041 		<?php	//end settings div 
  3436 		<?php	//end settings div 
  1042 		}
  3437 		$this->insert_js_for_datatable( array('swidth2'=>'60%') );
  1043 	
  3438 		}
  1044 	/** * private function for admin page : select of parents */
  3439 
  1045 		function xili_select_row($term_id=0,$editterm,$listby='name') {
  3440 
  1046 		// select all terms if current term is new
  3441 	/**
  1047 			if ($term_id == 0) {
  3442 	 * delete lines of dictionary
  1048 				$listterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => '0'));
  3443 	 *
  1049 				echo '<small>'.__('Choose the original term (msgid) to translate','xili-dictionary').'<br /></small>'; ?>
  3444 	 * 
  1050 				<select name="dictioline_parent" id="dictioline_parent" style="width:100%;">
  3445 	 */
  1051 		  				<option value="no_parent" ><?php _e('no parent (= msgid)','xili-dictionary'); ?></option>
  3446 	 function erase_dictionary ( $selection = "" ) {
  1052 				<?php
  3447 	 	
  1053 				foreach ($listterms as $curterm) {
  3448 	 	if ( $selection == "" ) {
  1054 					echo '<option value="'.$curterm->term_id.'" >'.substr($curterm->slug,0,50).' ('.$curterm->term_id.') </option>';
  3449 	 		// select all ids
  1055 				} 
  3450 	 		$listdictiolines = get_posts( array(
  1056 				?>
  3451 				'numberposts' => -1, 'offset' => 0,
  1057 				</select>
  3452 				'category' => 0, 'orderby' => 'ID',
  1058 				<br />
  3453 				'order' => 'ASC', 'include' => array(),
  1059 	    		<?php 
  3454 				'exclude' => array(), 'post_type' => XDMSG,
  1060 	     	} else {
  3455 				'suppress_filters' => true
  1061 	     	
  3456 			) );
  1062 	     		if ($editterm->parent == 0) {
  3457 	 		
  1063 	     			$listterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => $term_id));
  3458 	 		
  1064 					// display childs
  3459 	 	} else { // to improve soon
  1065 					if (!empty($listterms)) {
  3460 	 		
  1066 						echo '<small>'.__('translated as','xili-dictionary').": </small>";
  3461 	 	}
  1067 						echo '<ul>';
  3462 	 	
  1068 						foreach ($listterms as $curterm) { 
  3463 	 	if ( $listdictiolines ) { 
  1069 							$edit = "<a href='?action=edit&amp;page=dictionary_page&amp;term_id=".$curterm->term_id."' >".__( 'Edit' )."</a>";
  3464 	 		// loop
  1070 							echo '<li value="'.$curterm->term_id.'" >'.$this->display_singular_or_plural ($curterm->description, true).' <small>'.$edit.'</small></li>';
  3465 	 		foreach ( $listdictiolines as $oneline ) {
  1071 						}
  3466 	 			wp_delete_post( $oneline->ID, false ) ;
  1072 						echo '</ul>';
  3467 	 		}
  1073 					} else {
  3468 	 	}
  1074 						echo __('not yet translated','xili-dictionary')."<br /><br />";	
  3469 	 }
  1075 					}	
  3470 
  1076 	     		} else {
  3471 		
  1077 	     			echo '<small>'.__('translation of','xili-dictionary').": </small>";
  3472 	/** 
  1078 	     			$edit = "<a href='?action=edit&amp;page=dictionary_page&amp;term_id=".$editterm->parent."' >".__( 'Edit' )."</a>";
  3473 	 * create an array of mo content of theme (maintained by super-admin)	
  1079 	     			$parent_term = get_term($editterm->parent,DTAXONAME,OBJECT,'edit');
  3474 	 *
  1080 	     			echo $this->display_singular_or_plural ($parent_term->description, true).' <small>'.$edit.'</small>'; ?>
  3475 	 * @since 1.1.0
  1081 	     			<input type="hidden" name="dictioline_parent" value="<?php echo $parent_term->term_id ?>" />	
  3476 	 */
  1082 	     	<?php }	
  3477 	 function get_pomo_from_theme( $local = false ) {
  1083 			}	
  3478 	 	$theme_mos = array();
  1084 		}
  3479 	 	if ( defined ('TAXONAME') ) {
  1085 	/** * private function for admin page : one line of taxonomy */
  3480 	 		$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
  1086 		
  3481 	 		foreach ($listlanguages as $reflanguage) {
  1087 	function xili_dict_row($listby='name',$tagsnamelike='',$tagsnamesearch='') { 
  3482 	     		$res = $this->pomo_import_MO ( $reflanguage->name, '', $local);
  1088 		global $default_lang;	
  3483 	     		if (false !== $res) $theme_mos[$reflanguage->slug] = $res->entries;
  1089 		/*list of dictiolines*/
  3484 	 		}
  1090 	
  3485 	 	}
  1091 		if ($this->subselect == 'msgid' || $this->subselect == '') {
  3486 	 	return $theme_mos;	
  1092 			$parentselect = '';
  3487 	 }	
  1093 			if ($this->subselect == 'msgid') $parentselect = '0';
  3488 	 
  1094 			$listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false,'orderby' => 	$listby,'get'=>'all','name__like'=>$tagsnamelike,'search'=>$tagsnamesearch, 'parent'=>$parentselect));
  3489 	 /** 
       
  3490 	 * create an array of mo content of theme (maintained by admin of current site)
       
  3491 	 * currently contains the msgid which are not in theme mo
       
  3492 	 *
       
  3493 	 * @since 1.2.0
       
  3494 	 */
       
  3495 	 function get_pomo_from_site( $local = false ) {
       
  3496 	 	$theme_mos = array();
       
  3497 	 	if ( defined ('TAXONAME') ) {
       
  3498 	 		$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
       
  3499 	 		foreach ($listlanguages as $reflanguage) {
       
  3500 	     		$res = $this->import_mo_file_wpmu ( $reflanguage->name, false, $local ); // of current site
       
  3501 	     		if (false !== $res) $theme_mos[$reflanguage->slug] = $res->entries;
       
  3502 	 		}
       
  3503 	 	}
       
  3504 	 	return $theme_mos;	
       
  3505 	 }
       
  3506 	 
       
  3507 	/** 
       
  3508 	 * private function for admin page : one line of taxonomy
       
  3509 	 *
       
  3510 	 *
       
  3511 	 */
       
  3512 	function xili_dict_cpt_row( $listby='name', $tagsnamelike='', $tagsnamesearch='' ) { /* the lines */
       
  3513  		
       
  3514  		// select msg
       
  3515  		$special_query = false;
       
  3516  		switch ( $this->subselect ) {
       
  3517  			
       
  3518  			case 'msgid' :
       
  3519  				$meta_key_val = $this->msgtype_meta;
       
  3520  				$meta_value_val = 'msgid';
       
  3521  				break;
       
  3522  			case 'msgstr' :
       
  3523  				$meta_key_val = $this->msgtype_meta;
       
  3524  				$meta_value_val = 'msgstr';
       
  3525  				break;
       
  3526  			case 'msgstr_0' :
       
  3527  				$meta_key_val = $this->msgtype_meta;
       
  3528  				$meta_value_val = 'msgstr_0';
       
  3529  				break;	
       
  3530  			case '' :
       
  3531  				$meta_key_val = '';
       
  3532  				$meta_value_val = '';
       
  3533  				break;
       
  3534  			default;
       
  3535  				if ( false !== strpos ( $this->subselect, 'only=' ) ) { 
       
  3536  					$exps = explode ('=', $this->subselect);
       
  3537  					$special_query = 'strlang' ;
       
  3538  					$curlang = $exps[1];
       
  3539  					
       
  3540  				} else {
       
  3541  					if ( false !== strpos ( $this->subselect, 'nottransin_' ) ) {
       
  3542  						$exps = explode ('_', $this->subselect);
       
  3543  						$special_query = 'idlang' ;
       
  3544  						$curlang = $exps[1];
       
  3545  						$this->searchtranslated = 'not'; // 2.1.2
       
  3546  					} else {
       
  3547  						// msgid + language
       
  3548  						$curlang = $this->subselect;
       
  3549  						$special_query = 'idlang' ;
       
  3550  					}
       
  3551  				}		
       
  3552  		}	
       
  3553  		if ( $special_query ==  'idlang' ) {
       
  3554  			if ( $this->searchtranslated != 'not' ) {
       
  3555  				$listdictiolines = $this->get_cpt_msgids( $curlang ) ;
       
  3556  			} else {
       
  3557  				$listdictiolines = $this->get_cpt_msgids( $curlang, 'mo', array(), true ) ; // search not translated in target language
       
  3558  			}
       
  3559  		} elseif ( $special_query ==  'strlang' ) {
       
  3560  			$listdictiolines = get_posts( array(
       
  3561 				'numberposts' => -1, 'offset' => 0,
       
  3562 				'category' => 0, 'orderby' => 'ID',
       
  3563 				'order' => 'ASC', 'include' => array(),
       
  3564 				'exclude' => array(), 
       
  3565 				'post_type' => XDMSG,
       
  3566 				'suppress_filters' => true, 's' => $tagsnamesearch,
       
  3567 				'tax_query' => array(
       
  3568 						array(
       
  3569 							'taxonomy' => TAXONAME,
       
  3570 							'field' => 'name',
       
  3571 							'terms' => $curlang
       
  3572 					)
       
  3573 				),
       
  3574 				'meta_query' => array(
       
  3575 						array(
       
  3576 							'key' => $this->msgtype_meta,
       
  3577 							'value' => array( 'msgstr', 'msgstr_0', 'msgstr_1' ),
       
  3578 							'compare' => 'IN'
       
  3579 						)
       
  3580 				)
       
  3581 			) );	
       
  3582  			
       
  3583  		} else {	
       
  3584  			$listdictiolines = get_posts( array(
       
  3585 				'numberposts' => -1, 'offset' => 0,
       
  3586 				'category' => 0, 'orderby' => 'ID',
       
  3587 				'order' => 'ASC', 'include' => array(),
       
  3588 				'exclude' => array(), 'meta_key' => $meta_key_val,
       
  3589 				'meta_value' =>$meta_value_val, 'post_type' => XDMSG,
       
  3590 				'suppress_filters' => true, 's' => $tagsnamesearch
       
  3591 			) );
       
  3592  		}
       
  3593  		$class = "";
       
  3594  		$this->mo_files_array (); 
       
  3595  		//print_r( $this->file_site_mos );
       
  3596  		foreach ( $listdictiolines as $dictioline ) {
       
  3597 			
       
  3598 			$class = (( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
       
  3599  			
       
  3600  			$type  = get_post_meta ( $dictioline->ID, $this->msgtype_meta, true);
       
  3601  			$context  = get_post_meta ( $dictioline->ID, $this->ctxt_meta, true);
       
  3602  			
       
  3603  			$res = $this->is_saved_cpt_in_theme( $dictioline->post_content, $type, $context );
       
  3604  			$save_state = $res[0] . ' (local: '.$res[2].')'; // improve for str and multisite
       
  3605  			
       
  3606  			if ( is_multisite() ) $save_state .= '<br />'.__('this site', 'xili-dictionary').': '.$res[1] . ' (local: '.$res[3].')';
       
  3607  			
       
  3608  			$edit = "<a href='post.php?post=$dictioline->ID&action=edit' >".__( 'Edit' )."</a></td>";
       
  3609  			
       
  3610 			$line = "<tr id='cat-$dictioline->ID'$class>
       
  3611 				<td scope='row' style='text-align: center'>$dictioline->ID</td>
       
  3612 				
       
  3613 				<td>". htmlspecialchars( $dictioline->post_content ) ."</td>
       
  3614 				
       
  3615 				<td>";
       
  3616 			echo $line;	
       
  3617 			$this->msg_link_display ( $dictioline->ID, false, $dictioline ) ;	
       
  3618 			$line = "</td>
       
  3619 				<td class='center'>$save_state</td>
       
  3620 				  
       
  3621 				<td class='center'>$edit</td>\n\t</tr>\n"; /*to complete*/
       
  3622 			echo $line;
       
  3623 		
       
  3624  		}
       
  3625 	}
       
  3626 	
       
  3627 	/**
       
  3628 	 * return count of msgid (local or theme domain)
       
  3629 	 * @since
       
  3630 	 */
       
  3631 	function count_msgids ( $curlang, $local = true, $theme_domain = '' ) {
       
  3632 		
       
  3633 		if ( $local ) {
       
  3634 			// msg id with lang
       
  3635 			$the_query = array(
       
  3636 			'post_type' => XDMSG,
       
  3637 			'meta_query' => array(
       
  3638 			'relation' => 'AND',
       
  3639 				array(
       
  3640 					'key' => $this->msgtype_meta,
       
  3641 					'value' => 'msgid',
       
  3642 					'compare' => '='
       
  3643 					),
       
  3644 				array(
       
  3645 					'key' => $this->msglang_meta,
       
  3646 					'value' => $curlang,
       
  3647 					'compare' => 'LIKE' // 2.1.2
       
  3648 					),
       
  3649 				array(
       
  3650 					'key' => $this->msg_extracted_comments,
       
  3651 					'value' => $this->local_tag,
       
  3652 					'compare' => 'LIKE'
       
  3653 					)
       
  3654 			)
       
  3655 		);
       
  3656 		
       
  3657 		} else if (  $theme_domain == '') {
       
  3658 			$the_query = array(
       
  3659 			'post_type' => XDMSG,
       
  3660 			'tax_query' => array(
       
  3661 				array(
       
  3662 					'taxonomy' => TAXONAME,
       
  3663 					'field' => 'name',
       
  3664 					'terms' => $curlang
       
  3665 					)
       
  3666 				)
       
  3667 			);
       
  3668 			
  1095 		} else {
  3669 		} else {
  1096 			/*  */
  3670 			
  1097 			$group = is_term($this->subselect,XDDICTLANGS);
  3671 			$the_query = array(
  1098 			$listdictiolines = get_terms_of_groups(array($group['term_id']),XDDICTLANGS,DTAXONAME, array('hide_empty' => false,'orderby' => 	$listby,'get'=>'all','name__like'=>$tagsnamelike,'search'=>$tagsnamesearch));
  3672 			'post_type' => XDMSG,
  1099 		}
  3673 			'meta_query' => array(
  1100 		if (empty($listdictiolines) && $tagsnamelike=='' && $tagsnamesearch=='') : /*create a default line with the default language (as in config)*/
  3674 				'relation' => 'AND',
  1101 			$term = 'term';
  3675 				array(
  1102 			$args = array( 'alias_of' => '', 'description' => "term", 'parent' => 0, 'slug' =>'');
  3676 					'key' => $this->msgtype_meta,
  1103 			wp_insert_term( $term, DTAXONAME, $args);
  3677 					'value' => 'msgid',
  1104 			$listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false));
  3678 					'compare' => '='
  1105 		endif;
  3679 					),
  1106 		if (empty($listdictiolines)) {
  3680 				array(
  1107 			echo '<p>'.__('try another sub-selection !','xili-dictionary').'</p>';
  3681 					'key' => $this->msglang_meta,
  1108 		} else {
  3682 					'value' => $curlang,
  1109 			$subselect = (($tagsnamelike=='') ? '' : '&amp;tagsnamelike='.$tagsnamelike);
  3683 					'compare' => 'LIKE' // 2.1.2
  1110 			$subselect .= (($tagsnamesearch=='') ? '' : '&amp;tagsnamesearch='.$tagsnamesearch);
  3684 					)
  1111 					
  3685 				),
  1112 			foreach ($listdictiolines as $dictioline) {
  3686 			'tax_query' => array(
  1113 				
  3687 				
  1114 				$class = (( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
  3688 				array(
  1115 		
  3689 					'taxonomy' => 'origin',
  1116 				$dictioline->count = number_format_i18n( $dictioline->count );
  3690 					'field' => 'slug',
  1117 				$posts_count = ( $dictioline->count > 0 ) ? "<a href='edit.php?lang=$dictioline->term_id'>$dictioline->count</a>" : $dictioline->count;	
  3691 					'terms' => array($theme_domain),
  1118 			
  3692 					'operator' => 'IN'
  1119 				$edit = "<a href='?action=edit&amp;page=dictionary_page".$subselect."&amp;term_id=".$dictioline->term_id."' >".__( 'Edit' )."</a></td>";	
  3693 					)
  1120 				/* delete link */
  3694 				)
  1121 				$edit .= "<td><a href='?action=delete&amp;page=dictionary_page".$subselect."&amp;term_id=".$dictioline->term_id."' class='delete'>".__( 'Delete' )."</a>";	
  3695 			);
  1122 				/* modify to allow all html tags in msg str or id -  0.9.8.2*/
  3696 			
  1123 				$line="<tr id='cat-$dictioline->term_id'$class>
  3697 		}
  1124 				<th scope='row' style='text-align: center'>$dictioline->term_id</th>
  3698 		
  1125 				
  3699 		
  1126 				<td>".$this->display_singular_or_plural($dictioline->description)."</td>
  3700 		$query_4_test = new WP_Query( $the_query ); 
  1127 				
  3701 		return $query_4_test->found_posts;
  1128 				<td>".$dictioline->slug."</td>
  3702 	
  1129 				<td align='center'>$dictioline->term_group</td>
  3703 	}		
  1130 				  
  3704 	/**
  1131 				<td>$edit</td>\n\t</tr>\n"; /*to complete*/
  3705 	 * test if line is in entries
  1132 				echo $line;
  3706 	 * @since
  1133 			}	
  3707 	 */
  1134 		}
  3708 	function is_intheme_mos ( $msg, $type, $entries, $context ) {
  1135 	}
  3709 		foreach ($entries as $entry) {
  1136 	function display_singular_or_plural ($msg, $onlyfirst = false) {
  3710 			$diff = 1;
  1137 		if (false === strpos($msg,XPLURAL)) {
  3711 			switch ( $type ) {
  1138 			return wp_filter_kses($msg);
  3712 		 		case 'msgid' :
  1139 		} else {
  3713 		 			$diff = strcmp( $msg , $entry->singular );
  1140 			$list = explode (XPLURAL,$msg);
  3714 		 			if ( $context != "" ) {
  1141 			if ($onlyfirst === false) {
  3715 		 				if ( $entry->context != null ) {
  1142 				$list = array_map('wp_filter_kses',$list);
  3716 		 					$diff += strcmp( $context , $entry->context ); 
  1143 				return implode('<br />',$list);
  3717 		 				}
  1144 			} else {
  3718 		 			}
  1145 				return wp_filter_kses($list[0]);
  3719 					break;
  1146 			}
  3720 				case 'msgid_plural' :
  1147 		}
  3721 					$diff = strcmp( $msg , $entry->plural );
  1148 	}
  3722 					break;	
       
  3723 				case 'msgstr' :
       
  3724 				 if ( isset ( $entry->translations[0] ) )
       
  3725 					$diff = strcmp( $msg , $entry->translations[0] );
       
  3726 					break;
       
  3727 				default:
       
  3728 					if ( false !== strpos ( $type, 'msgstr_'  ) ) {
       
  3729 						$indice = (int) substr ( $type, -1) ;
       
  3730 						if ( isset ( $entry->translations[$indice] ) )
       
  3731 							$diff = strcmp( $msg , $entry->translations[$indice] );
       
  3732 					}
       
  3733 			}
       
  3734 			
       
  3735 			//if ( $diff != 0) { echo $msg.' i= '.strlen($msg); echo $entry->singular.') e= '.strlen($entry->singular); }
       
  3736 			if ( $diff == 0) return true;
       
  3737 		}	
       
  3738 	return false;
       
  3739 	}
       
  3740 	
       
  3741 	/**
       
  3742 	 * Detect if cpt are saved in theme's languages folder
       
  3743 	 * @since 2.0
       
  3744 	 * 
       
  3745 	 */
       
  3746 	function is_saved_cpt_in_theme( $msg, $type, $context = "" ) {
       
  3747 		$thelist = array();
       
  3748 		$thelistsite = array();
       
  3749 		$thelist_local = array();
       
  3750 		$thelistsite_local = array();
       
  3751 		$outputsite = "";
       
  3752 		$localfile_site = "";
       
  3753 		$output = "";
       
  3754 		$localfile="";
       
  3755 		
       
  3756 		if ( defined ('TAXONAME') ) {
       
  3757 			$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
       
  3758 			
       
  3759 		 	foreach ($listlanguages as $reflanguage) {
       
  3760 		 		if ( isset( $this->theme_mos[$reflanguage->slug]) ) { 
       
  3761 		 			if ( $this->is_intheme_mos ( $msg, $type, $this->theme_mos[$reflanguage->slug], $context ) )
       
  3762 		 				$thelist[] = $reflanguage->name.".mo";		 							 			
       
  3763 		 		}
       
  3764 		 		// local data
       
  3765 		 		if ( isset( $this->local_mos[$reflanguage->slug]) ) { 
       
  3766 		 			if ( $this->is_intheme_mos ( $msg, $type, $this->local_mos[$reflanguage->slug], $context ) )
       
  3767 		 				$thelist_local[] = $reflanguage->name.".mo";		 							 			
       
  3768 		 		}
       
  3769 		 		
       
  3770 		 		if ( is_multisite() ) {
       
  3771 		 			if ( isset($this->file_site_mos[$reflanguage->slug]) ) { 
       
  3772 		 				if ( $this->is_intheme_mos ( $msg, $type, $this->file_site_mos[$reflanguage->slug], $context ) )
       
  3773 		 					$thelistsite[] = $reflanguage->name.".mo";		 							 			
       
  3774 		 			} 
       
  3775 		 			// local data
       
  3776 		 			if ( isset($this->file_site_local_mos[$reflanguage->slug]) ) { 
       
  3777 		 				if ( $this->is_intheme_mos ( $msg, $type, $this->file_site_local_mos[$reflanguage->slug], $context ) )
       
  3778 		 					$thelistsite_local[] = $reflanguage->name.".mo";		 							 			
       
  3779 		 			} 
       
  3780 		 		}
       
  3781 		 		
       
  3782 		 	}
       
  3783 		 	
       
  3784 			$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>';
       
  3785 			
       
  3786 			$localfile = ($thelist_local == array()) ? '<small><span style="color:black" title="'.__("No translations saved in local-xx_XX .mo files","xili-dictionary").'">?</span></small>' : '<small><span style="color:green" title="'.__("Original with translations saved in local-xx_XX files: ","xili-dictionary").'" >'. implode(', ', $thelist_local ).'</small></small>';
       
  3787 			
       
  3788 			if ( is_multisite() ) {
       
  3789 				
       
  3790 				$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>';
       
  3791 				
       
  3792 				$localfile_site = ($thelistsite_local == array()) ? '<small><span style="color:black" title="' . __("No translations saved in site's local .mo files","xili-dictionary").'">?</span></small>' : '<small><span style="color:green" title="'.__("Original with translations saved in site's local files: ","xili-dictionary").'" >'. implode(', ',$thelistsite_local).'</small></small>';
       
  3793 				
       
  3794 			}
       
  3795 			
       
  3796 			return array ( $output, $outputsite, $localfile, $localfile_site ) ;
       
  3797 		}
       
  3798 	}
       
  3799 	
       
  3800 	
  1149 	/**
  3801 	/**
  1150 	 * Import PO file in class PO 
  3802 	 * Import PO file in class PO 
  1151 	 *
  3803 	 *
  1152 	 *
  3804 	 *
  1153 	 * @since 1.0 - only WP >= 2.8.4
  3805 	 * @since 1.0 - only WP >= 2.8.4
  1154 	 */
  3806 	 * @updated 1.05 - import .pot if domain name - fixed 1.3.1
  1155 	function pomo_import_PO ($lang = "") {
  3807 	 * @updated 2.1 - local-xx_XX
       
  3808 	 */
       
  3809 	function pomo_import_PO ( $lang = "", $local = false ) {
  1156 		$po = new PO();
  3810 		$po = new PO();
  1157 		$pofile = get_template_directory().$this->langfolder.$lang.'.po'; 
  3811 		$t = "";
  1158 		if ( !$po->import_from_file( $pofile ) ) {
  3812 		if ( function_exists('the_theme_domain') ) {
       
  3813 				$t = ($lang == the_theme_domain()) ? 't': ''; /* from UI to select .pot */
       
  3814 		} else {
       
  3815 				if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0
       
  3816 					$theme_name = get_option("stylesheet"); 
       
  3817 				} else {
       
  3818 					$theme_name = get_option("template"); 
       
  3819 				}
       
  3820 				$t = ( $lang == $theme_name ) ? 't': ''; /* from UI to select .pot */
       
  3821 		}
       
  3822 		
       
  3823 		if ( $local == false ) {
       
  3824 			$pofile = $this->get_template_directory.$this->langfolder.$lang.'.po'.$t;
       
  3825 		} else {
       
  3826 			$pofile = $this->get_template_directory.$this->langfolder.'local-'.$lang.'.po'; // fixed 2.1.1
       
  3827 		}
       
  3828 		
       
  3829 		if ( file_exists( $pofile ) ) { 
       
  3830 			if ( !$po->import_from_file( $pofile ) ) {
       
  3831 				return false;
       
  3832 			} else { 
       
  3833 				return $po;
       
  3834 			}
       
  3835 		} else {
  1159 			return false;
  3836 			return false;
  1160 		} else { 
  3837 		}
  1161 			return $po;
  3838 	}
  1162 		}
  3839 	
  1163 	}
       
  1164 	/**
       
  1165 	 * the PO object to twinlines (msgid - msgstr) for list
       
  1166 	 *
       
  1167 	 *
       
  1168 	 * @since 1.0 - only WP >= 2.8.4
       
  1169 	 */	
       
  1170 	function from_PO_to_twin ($po)	{
       
  1171 		$twinlines = array();
       
  1172 		foreach ($po->entries as $pomsgid => $pomsgstr) {
       
  1173 			if ($pomsgstr->is_plural == null) {
       
  1174 				$twinlines[$pomsgid] = $pomsgstr->translations[0];
       
  1175 			} else {
       
  1176 				$keytwin = $pomsgstr->singular.XPLURAL.$pomsgstr->plural;
       
  1177 				$twinlines[$keytwin] = implode (XPLURAL, $pomsgstr->translations);
       
  1178 			}
       
  1179 			
       
  1180 		}
       
  1181 		//print_r($twinlines);
       
  1182 		return $twinlines;
       
  1183 	}
       
  1184 	/**
  3840 	/**
  1185 	 * Import MO file in class PO 
  3841 	 * Import MO file in class PO 
  1186 	 *
  3842 	 *
  1187 	 *
  3843 	 *
  1188 	 * @since 1.0.2 - only WP >= 2.8.4
  3844 	 * @since 1.0.2 - only WP >= 2.8.4
  1189 	 */
  3845 	 * @updated 1.0.5 - for wp-net
  1190 	function pomo_import_MO ($lang = "") {
  3846 	 * @param lang
       
  3847 	 * @param $mofile since 1.0.5
       
  3848 	 * @updated 2.1 - local-xx_XX
       
  3849 	 */
       
  3850 	function pomo_import_MO ($lang = "", $mofile = "", $local = false ) {
  1191 		$mo = new MO();
  3851 		$mo = new MO();
  1192 		$mofile = get_template_directory().$this->langfolder.$lang.'.mo'; 
  3852 		
  1193 		if ( !$mo->import_from_file( $mofile ) ) {
  3853 		if ( $mofile == "" &&  $local == true ) {
       
  3854 			$mofile = $this->get_template_directory.$this->langfolder.'local-'.$lang.'.mo';
       
  3855 		} else if ( '' == $mofile ) {
       
  3856 			$mofile = $this->get_template_directory.$this->langfolder.$lang.'.mo';
       
  3857 		}
       
  3858 		
       
  3859 		if ( file_exists( $mofile ) ) {
       
  3860 			if ( !$mo->import_from_file( $mofile ) ) {
       
  3861 				return false;
       
  3862 			} else { 
       
  3863 				return $mo;
       
  3864 			}
       
  3865 		} else {
  1194 			return false;
  3866 			return false;
  1195 		} else { 
       
  1196 			return $mo;
       
  1197 		}
  3867 		}
  1198 	}
  3868 	}
  1199 	/**
  3869 	/**
  1200 	 * the MO object to twinlines (msgid - msgstr) for list
  3870 	 * import mo for temporary diff mo files or check if saved
  1201 	 *
  3871 	 *
  1202 	 *
  3872 	 * @since 1.0.6
  1203 	 * @since 1.0.2 - only WP >= 2.8.4
  3873 	 * 
       
  3874 	 */
       
  3875 	function import_mo_file_wpmu ($lang = "", $istheme = true, $local = false ){
       
  3876 	  if ($istheme == true) {
       
  3877 	  	return $this->pomo_import_MO ( $lang, "", $local );
       
  3878 	  } else {
       
  3879 	  		global $wpdb;
       
  3880     			$thesite_ID = $wpdb->blogid; 
       
  3881     			if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {
       
  3882 					//if ($thesite_ID > 1) {
       
  3883 						if ( $local == true ) {
       
  3884 							$mofile = $uploads['basedir']."/languages/local-".$lang.'.mo';
       
  3885 						} else {
       
  3886 							$mofile = $uploads['basedir']."/languages/".$lang.'.mo'; //normally inside theme's folder if root wp-net
       
  3887 						}
       
  3888 						
       
  3889 						return $this->pomo_import_MO ( $lang, $mofile, $local );
       
  3890 					//} else {
       
  3891 						//return false; // normally inside theme's folder if root wp-net
       
  3892 					//}
       
  3893     			} else {
       
  3894     				return false;
       
  3895     			}
       
  3896 	  }
       
  3897 	}
       
  3898 	
       
  3899 	
       
  3900 	/**
       
  3901 	 * convert twinlines (msgid - msgstr) to MOs in wp-net
       
  3902 	 * @since 1.0.4
       
  3903 	 * @updated 2.0
       
  3904 	 * @params as from_twin_to_POMO and $superadmin 
  1204 	 */	
  3905 	 */	
  1205 	function from_MO_to_twin ($mo)	{
  3906 	function from_cpt_to_POMO_wpmu ($curlang, $obj='mo', $superadmin = false, $extract = array() )	{
  1206 		$twinlines = array();
  3907 		global $user_identity,$user_url,$user_email;
  1207 		foreach ($mo->entries as $pomsgid => $pomsgstr) {
  3908 	    // the table array
  1208 			if ($pomsgstr->is_plural == null) {
  3909 	    $table_mo = $this->from_cpt_to_POMO( $curlang, $obj, $extract ); 
  1209 				$twinlines[$pomsgid] = $pomsgstr->translations[0];
  3910 	    $site_mo = new MO () ; 
       
  3911 	    $translation ='
       
  3912 	Project-Id-Version: theme: '.get_option("template").'\n
       
  3913 	Report-Msgid-Bugs-To: contact@xiligroup.com\n
       
  3914 	POT-Creation-Date: '.date("c").'\n
       
  3915 	PO-Revision-Date: '.date("c").'\n
       
  3916 	Last-Translator: '.$user_identity.' <'.$user_email.'>\n
       
  3917 	Language-Team: xili-dictionary WP plugin and '.$user_url.' <'.$user_email.'>\n
       
  3918 	MIME-Version: 1.0\n
       
  3919 	Content-Type: text/plain; charset=utf-8\n
       
  3920 	Content-Transfer-Encoding: 8bit\n
       
  3921 	Plural-Forms: '.$this->plural_forms_rule($curlang).'\n
       
  3922 	X-Poedit-Language: '.$curlang.'\n
       
  3923 	X-Poedit-Country: '.$curlang.'\n
       
  3924 	X-Poedit-SourceCharset: utf-8\n';
       
  3925 		
       
  3926 		$site_mo->set_headers($site_mo->make_headers($translation));
       
  3927 	   	// array diff
       
  3928 	   	if (false  === $superadmin) {
       
  3929 	   		// special for superadmin who don't need diff.
       
  3930 			// the pomo array available in theme's folder 
       
  3931 	   		$theme_mo = $this->import_mo_file_wpmu ( $curlang, true );
       
  3932 	   	  	if ( false !== $theme_mo ) {
       
  3933 	   	  		// without keys available in theme' mo
       
  3934 	   			$site_mo->entries =  array_diff_key ( $table_mo->entries, $theme_mo->entries  ); // those differents ex. categories
       
  3935 	   			// those with same keys but translations[0] diff
       
  3936 	   			$diff_mo_trans = array_uintersect_assoc ( $table_mo->entries, $theme_mo->entries, array(&$this,'test_translations')  ) ;
       
  3937 	   			
       
  3938 	   			$site_mo->entries += $diff_mo_trans ;
       
  3939 	   			//print_r ( array_keys ( $diff_mo_trans ));
       
  3940 	   			
       
  3941 	   		}
       
  3942 	   		return $site_mo;
       
  3943 	   	} elseif ( $extract != '' ) { 
       
  3944 	   		
       
  3945 	   		return $table_mo;
       
  3946 	   	}
       
  3947 	}
       
  3948 	
       
  3949 	function test_translations ( $table, $theme ) {
       
  3950 		if ( $table->translations[0] != $theme->translations[0] ) {
       
  3951 			if ( $table->singular == $theme->singular ) {
       
  3952 				//echo '--tQuote--not'.$table->translations[0];
       
  3953 				return 0;
       
  3954 				
  1210 			} else {
  3955 			} else {
  1211 				$keytwin = $pomsgstr->singular.XPLURAL.$pomsgstr->plural;
  3956 				return 1;
  1212 				$twinlines[$keytwin] = implode (XPLURAL, $pomsgstr->translations);
  3957 			}	
  1213 			}
  3958 		}
  1214 			
  3959 		if ( $table->singular > $theme->singular ) return 1;
  1215 		}
  3960 		return -1;
  1216 		//print_r($twinlines);
       
  1217 		return $twinlines;
       
  1218 	}
  3961 	}
  1219 	
  3962 	
  1220 	/**
  3963 	/**
  1221 	 * convert twinlines (msgid - msgstr) to MO
  3964 	 * return array of msgid objects 
  1222 	 *
  3965 	 * @since 2.0
  1223 	 *
  3966 	 *
  1224 	 * @since 1.0 - only WP >= 2.8.4
  3967 	 * @updated 2.1.2
       
  3968 	 */
       
  3969 	function get_cpt_msgids( $curlang, $pomo = "mo", $extract_array = array(), $not = false ) {
       
  3970 		global $wpdb;
       
  3971 		$like = ($not === true ) ? 'NOT LIKE' : 'LIKE' ;
       
  3972 		if ( $pomo == "mo" ) {
       
  3973 			
       
  3974 			if ( $extract_array == array() ) { 
       
  3975 				//$posts_query = $wpdb->prepare("SELECT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) INNER JOIN $wpdb->postmeta as mt1 ON ($wpdb->posts.ID = mt1.post_id) INNER JOIN $wpdb->postmeta as mt2 ON ($wpdb->posts.ID = mt2.post_id) INNER JOIN $wpdb->postmeta as mt3 ON ($wpdb->posts.ID = mt3.post_id)  WHERE post_status = %s AND post_type = %s AND $wpdb->postmeta.meta_key='{$this->msgtype_meta}' AND mt1.meta_key='{$this->msgtype_meta}' AND mt1.meta_value = %s AND mt2.meta_key='{$this->msglang_meta}' AND mt3.meta_key='{$this->msglang_meta}' AND mt3.meta_value LIKE %s ", 'publish', XDMSG ,'msgid', '%'.$curlang.'%' );
       
  3976 				//return $wpdb->get_results($posts_query);
       
  3977 				return get_posts( array( 
       
  3978 				'numberposts' => -1, 'offset' => 0,
       
  3979 				'category' => 0, 'orderby' => 'ID',
       
  3980 				'order' => 'ASC', 'include' => array(),
       
  3981 				'exclude' => array(), 
       
  3982 				'post_type' => XDMSG,
       
  3983 				'suppress_filters' => true,
       
  3984 				'meta_query' => array(
       
  3985 						'relation' => 'AND',
       
  3986 						array(
       
  3987 							'key' => $this->msgtype_meta,
       
  3988 							'value' => 'msgid',
       
  3989 							'compare' => '='
       
  3990 						),
       
  3991 						array(
       
  3992 							'key' => $this->msglang_meta,
       
  3993 							'value' => $curlang,
       
  3994 							'compare' => $like // 2.1.2
       
  3995 						)
       
  3996 					)	
       
  3997 				 ) );
       
  3998 				
       
  3999 			
       
  4000 			} else if ( isset ( $extract_array [ $this->msg_extracted_comments ] ) ) {
       
  4001 				$extract = 	$extract_array [ $this->msg_extracted_comments ];
       
  4002 			
       
  4003 				//$posts_query = $wpdb->prepare("SELECT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) INNER JOIN $wpdb->postmeta as mt1 ON ($wpdb->posts.ID = mt1.post_id) INNER JOIN $wpdb->postmeta as mt2 ON ($wpdb->posts.ID = mt2.post_id) INNER JOIN $wpdb->postmeta as mt3 ON ($wpdb->posts.ID = mt3.post_id)  INNER JOIN $wpdb->postmeta as mt4 ON ($wpdb->posts.ID = mt4.post_id) INNER JOIN $wpdb->postmeta as mt5 ON ($wpdb->posts.ID = mt5.post_id)  WHERE post_status = %s AND post_type = %s AND $wpdb->postmeta.meta_key='{$this->msgtype_meta}' AND mt1.meta_key='{$this->msgtype_meta}' AND mt1.meta_value = %s AND mt2.meta_key='{$this->msglang_meta}' AND mt3.meta_key='{$this->msglang_meta}' AND mt3.meta_value LIKE %s AND mt4.meta_key='{$this->msg_extracted_comments}' AND mt5.meta_key='{$this->msg_extracted_comments}' AND mt5.meta_value LIKE %s ", 'publish', XDMSG ,'msgid', '%'.$curlang.'%', '%'.$extract.'%' );
       
  4004 				//return $wpdb->get_results($posts_query);
       
  4005 				
       
  4006 				return get_posts( array( 
       
  4007 				'numberposts' => -1, 'offset' => 0,
       
  4008 				'category' => 0, 'orderby' => 'ID',
       
  4009 				'order' => 'ASC', 'include' => array(),
       
  4010 				'exclude' => array(), 
       
  4011 				'post_type' => XDMSG,
       
  4012 				'suppress_filters' => true,
       
  4013 				'meta_query' => array(
       
  4014 						'relation' => 'AND',
       
  4015 						array(
       
  4016 							'key' => $this->msgtype_meta,
       
  4017 							'value' => 'msgid',
       
  4018 							'compare' => '='
       
  4019 						),
       
  4020 						array(
       
  4021 							'key' => $this->msglang_meta,
       
  4022 							'value' => $curlang,
       
  4023 							'compare' => 'LIKE'
       
  4024 						),
       
  4025 						array(
       
  4026 							'key' => $this->msg_extracted_comments,
       
  4027 							'value' => $extract,
       
  4028 							'compare' => 'LIKE'
       
  4029 						)
       
  4030 					)	
       
  4031 				 ) );
       
  4032 				
       
  4033 				
       
  4034 				
       
  4035 			} else if ( isset ( $extract_array [ 'origin' ] ) ) {
       
  4036 			//error_log ( '------------' . serialize ( $extract_array [ 'origin' ] ));
       
  4037 				if ( !is_array( $extract_array [ 'origin' ] ) ) {
       
  4038 					
       
  4039 				 $array_tax = array(
       
  4040 							'taxonomy' => 'origin',
       
  4041 							'field' => 'slug',
       
  4042 							'terms' => $extract_array [ 'origin' ]
       
  4043 						);
       
  4044 				 
       
  4045 				} else {
       
  4046 					
       
  4047 					$array_tax = array(
       
  4048 							'taxonomy' => 'origin',
       
  4049 							'field' => 'slug',
       
  4050 							'terms' => $extract_array [ 'origin' ],
       
  4051 							'operator' => 'IN'
       
  4052 						);
       
  4053 				}
       
  4054 				
       
  4055 				if ( $extract_array [ 'origin' ] == '' || $extract_array [ 'origin' ] == array() ) {
       
  4056 					
       
  4057 					return get_posts( array( 
       
  4058 				'numberposts' => -1, 'offset' => 0,
       
  4059 				'category' => 0, 'orderby' => 'ID',
       
  4060 				'order' => 'ASC', 'include' => array(),
       
  4061 				'exclude' => array(), 
       
  4062 				'post_type' => XDMSG,
       
  4063 				'suppress_filters' => true,
       
  4064 				'meta_query' => array(
       
  4065 						'relation' => 'AND',
       
  4066 						array(
       
  4067 							'key' => $this->msgtype_meta,
       
  4068 							'value' => 'msgid',
       
  4069 							'compare' => '='
       
  4070 						),
       
  4071 						array(
       
  4072 							'key' => $this->msglang_meta,
       
  4073 							'value' => $curlang,
       
  4074 							'compare' => 'LIKE'
       
  4075 						)
       
  4076 					)	
       
  4077 				 ) );
       
  4078 					
       
  4079 				} else {
       
  4080 			
       
  4081 				return get_posts( array( 
       
  4082 				'numberposts' => -1, 'offset' => 0,
       
  4083 				'category' => 0, 'orderby' => 'ID',
       
  4084 				'order' => 'ASC', 'include' => array(),
       
  4085 				'exclude' => array(), 
       
  4086 				'post_type' => XDMSG,
       
  4087 				'suppress_filters' => true,
       
  4088 				'meta_query' => array(
       
  4089 						'relation' => 'AND',
       
  4090 						array(
       
  4091 							'key' => $this->msgtype_meta,
       
  4092 							'value' => 'msgid',
       
  4093 							'compare' => '='
       
  4094 						),
       
  4095 						array(
       
  4096 							'key' => $this->msglang_meta,
       
  4097 							'value' => $curlang,
       
  4098 							'compare' => 'LIKE'
       
  4099 						)
       
  4100 					),
       
  4101 				'tax_query' => array(
       
  4102 						$array_tax
       
  4103 					)	
       
  4104 				 ) );
       
  4105 				}
       
  4106 				
       
  4107 			}
       
  4108 		
       
  4109 			
       
  4110 		
       
  4111 		} else { // po 
       
  4112 		
       
  4113 			if ( $extract_array == array() ) {
       
  4114 				// to have also empty translation
       
  4115 				$meta_key_val = $this->msgtype_meta; 
       
  4116 				$meta_value_val = 'msgid';
       
  4117 				return get_posts( array(
       
  4118 					'numberposts' => -1, 'offset' => 0,
       
  4119 					'category' => 0, 'orderby' => 'ID',
       
  4120 					'order' => 'ASC', 'include' => array(),
       
  4121 					'exclude' => array(), 'post_type' => XDMSG,
       
  4122 					'suppress_filters' => true,
       
  4123 					'meta_query' => array(
       
  4124 						array (
       
  4125 							'meta_key' => $meta_key_val,
       
  4126 							'meta_value' =>$meta_value_val
       
  4127 							)
       
  4128 						), 
       
  4129 					)
       
  4130 				);
       
  4131 				
       
  4132 			} else if ( isset ( $extract_array [ 'origin' ] ) ) {
       
  4133 				
       
  4134 				
       
  4135 				if ( !is_array( $extract_array [ 'origin' ] ) ) {
       
  4136 					
       
  4137 				 $array_tax = array(
       
  4138 							'taxonomy' => 'origin',
       
  4139 							'field' => 'slug',
       
  4140 							'terms' => $extract_array [ 'origin' ]
       
  4141 						);
       
  4142 				 
       
  4143 				} else { 
       
  4144 					
       
  4145 					$array_tax = array(
       
  4146 							'taxonomy' => 'origin',
       
  4147 							'field' => 'slug',
       
  4148 							'terms' => $extract_array [ 'origin' ],
       
  4149 							'operator' => 'IN'
       
  4150 						);
       
  4151 				}
       
  4152 				
       
  4153 				return get_posts( array( 
       
  4154 				'numberposts' => -1, 'offset' => 0,
       
  4155 				'category' => 0, 'orderby' => 'ID',
       
  4156 				'order' => 'ASC', 'include' => array(),
       
  4157 				'exclude' => array(), 
       
  4158 				'post_type' => XDMSG,
       
  4159 				'suppress_filters' => true,
       
  4160 				'meta_query' => array(
       
  4161 						array(
       
  4162 							'key' => $this->msgtype_meta,
       
  4163 							'value' => 'msgid',
       
  4164 							'compare' => '='
       
  4165 						)
       
  4166 					),
       
  4167 				'tax_query' => array(
       
  4168 						$array_tax
       
  4169 					)	
       
  4170 				 ) );	
       
  4171 				
       
  4172 			} else {  
       
  4173 				
       
  4174 				$extract = 	$extract_array [ $this->msg_extracted_comments ];
       
  4175 				
       
  4176 				$like_or_not = ( $extract_array [ 'like-'. $this->msg_extracted_comments ] == true )? 'LIKE' : 'NOT LIKE' ;
       
  4177 				
       
  4178 				return get_posts( array( 
       
  4179 				'numberposts' => -1, 'offset' => 0,
       
  4180 				'category' => 0, 'orderby' => 'ID',
       
  4181 				'order' => 'ASC', 'include' => array(),
       
  4182 				'exclude' => array(), 
       
  4183 				'post_type' => XDMSG,
       
  4184 				'suppress_filters' => true,
       
  4185 				'meta_query' => array(
       
  4186 						'relation' => 'AND',
       
  4187 						array(
       
  4188 							'key' => $this->msgtype_meta,
       
  4189 							'value' => 'msgid',
       
  4190 							'compare' => '='
       
  4191 						),
       
  4192 						array(
       
  4193 							'key' => $this->msg_extracted_comments,
       
  4194 							'value' => $extract ,
       
  4195 							'compare' => $like_or_not
       
  4196 						)
       
  4197 					)
       
  4198 				 ) );
       
  4199 				
       
  4200 			}
       
  4201 		}
       
  4202 	}
       
  4203 	
       
  4204 	/**
       
  4205 	 * return msgstr object (array translation)
       
  4206 	 * @since 2.0
       
  4207 	 */
       
  4208 	function get_cpt_msgstr( $cur_msgid_ID, $curlang, $plural = false ) {
       
  4209 		$res = get_post_meta ( $cur_msgid_ID, $this->msglang_meta, false );
       
  4210 		$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  4211 			if ( $plural ) {
       
  4212 				
       
  4213 				$cur_msgstr_ID = $thelangs['msgstrlangs'][$curlang]['msgstr_0'];
       
  4214 				// get_parent (msgstr_0)
       
  4215 				
       
  4216 				$msgstr_array = array ( get_post( $cur_msgstr_ID ) ) ;
       
  4217  				// get_children
       
  4218  				$args = array(
       
  4219 							'numberposts' => -1, 'post_type' => XDMSG,
       
  4220 							'post_status' => 'publish', 'post_parent' => $cur_msgstr_ID
       
  4221 				);
       
  4222 				$children = get_posts( $args );
       
  4223 				return array_merge($msgstr_array, $children); 
       
  4224 				
       
  4225 			} else {
       
  4226 				if ( isset ( $thelangs['msgstrlangs'][$curlang]['msgstr'] ) ) {
       
  4227 					$cur_msgstr_ID = $thelangs['msgstrlangs'][$curlang]['msgstr'];
       
  4228 				// get_content
       
  4229 				//echo ' - '.$cur_msgstr_ID;
       
  4230  					return get_post( $cur_msgstr_ID  );
       
  4231 				} else {
       
  4232 					return false;
       
  4233 				}
       
  4234 			}
       
  4235 	}
       
  4236 	
       
  4237 	/**
       
  4238 	 * convert cpt (msgid - msgstr) to MO or PO
       
  4239 	 *
       
  4240 	 * @since 2.0
       
  4241 	 * 
  1225 	 */	
  4242 	 */	
  1226 	function from_twin_to_POMO ($curlang, $obj='mo')	{
  4243 	function from_cpt_to_POMO ( $curlang, $obj='mo', $extract = array() ) {
  1227 		global $user_identity,$user_url,$user_email;
  4244 		global $user_identity,$user_url,$user_email;
  1228 		if ($obj == 'mo') {
  4245 		if ($obj == 'mo') {
  1229 			$mo = new MO(); /* par default */
  4246 			$mo = new MO(); /* par default */
  1230 		} else {
  4247 		} else {
  1231 			$mo = new PO();
  4248 			$mo = new PO();
  1246 	X-Poedit-Country: '.$curlang.'\n
  4263 	X-Poedit-Country: '.$curlang.'\n
  1247 	X-Poedit-SourceCharset: utf-8\n';
  4264 	X-Poedit-SourceCharset: utf-8\n';
  1248 		
  4265 		
  1249 		$mo->set_headers($mo->make_headers($translation));
  4266 		$mo->set_headers($mo->make_headers($translation));
  1250 		/* entries */
  4267 		/* entries */
  1251 		$listterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => '')); //print_r($listterms);
  4268 		
  1252 			foreach ($listterms as $curterm) {
  4269 		$list_msgids = $this->get_cpt_msgids( $curlang, $obj, $extract ); // msgtype = msgid && $curlang in 
  1253 				if ($curterm->parent == 0) {		
  4270 		
  1254 					/* select child to create translated term */
  4271 		//error_log ( 'list_msgids ='.count ( $list_msgids ));
  1255 					$listchildterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => $curterm->term_id));
  4272 		//print_r( $list_msgids );
  1256 					$noentry = true; /* to create po with empty translation */
  4273 		
  1257 					foreach ($listchildterms as $curchildterm) {
  4274 		foreach ( $list_msgids as $cur_msgid ) { 
  1258 						if (substr($curchildterm->slug,-5) == strtolower($curlang)) {
  4275 			
  1259 							if ($obj == 'mo') {
  4276 			if ( $cur_msgid->post_content == '++' ) continue; // no empty msgid
  1260 								if (false === strpos($curterm->description,XPLURAL)) {
  4277 				
  1261 									$mo->add_entry($mo->make_entry($curterm->description, $curchildterm->description));
  4278 			$getctxt = get_post_meta( $cur_msgid->ID , $this->ctxt_meta, true ) ;
  1262 								} else {
  4279 			$cur_msgid->ctxt = ( $getctxt == "" ) ? false : $getctxt;
  1263 									$msgidplural = explode(XPLURAL,$curterm->description);
  4280 					
  1264 									$original = implode(chr(0),$msgidplural);
  4281 			$cur_msgid->plural = false ;
  1265 									$msgstrplural = explode(XPLURAL,$curchildterm->description);
  4282 			$res = get_post_meta ( $cur_msgid->ID, $this->msgchild_meta, false );
  1266 									$translation = implode(chr(0),$msgstrplural);
  4283  			$thechilds =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : false;
  1267 									
  4284  			
  1268 									$mo->add_entry($mo->make_entry($original, $translation));
  4285  			if ( $thechilds ) {
  1269 								}	
  4286  				
  1270 							} else { /* po */ 
  4287  				
  1271 								if (false === strpos($curterm->description,XPLURAL)) {
  4288  				if ( isset ( $thechilds['msgid']['plural'] ) ) {
  1272 									$entry = & new Translation_Entry(array('singular'=>$curterm->description,'translations'=> explode(XPLURAL, $curchildterm->description)));
  4289  					$cur_msgid->plural = true ;
  1273 								} else {
  4290  					$plural_ID = $thechilds['msgid']['plural'];
  1274 									$msgidplural = explode(XPLURAL,$curterm->description);
  4291  				
  1275 									$msgstrplural = explode(XPLURAL,$curchildterm->description);
  4292  					$post_child_msgid = get_post( $plural_ID ); 
  1276 									$entry = & new Translation_Entry(array('singular' => $msgidplural[0],'plural' => $msgidplural[1], 'is_plural' =>1, 'translations' => $msgstrplural)); 	
  4293  					$cur_msgid->plural_post_content = $post_child_msgid -> post_content ;
  1277 								}
  4294  				}
  1278 								$mo->add_entry($entry);
  4295  			}
  1279 								$noentry = false;
  4296 					
  1280 							}
  4297 			//$res = get_post_meta ( $cur_msgid->ID, $this->msglang_meta, false );
       
  4298 						
       
  4299 				/* select child in curlang */
       
  4300 			$list_msgstr = $this->get_cpt_msgstr( $cur_msgid->ID, $curlang, $cur_msgid->plural ); // array of objects if plural
       
  4301 					 
       
  4302 			$noentry = true; /* to create po with empty translation */ 
       
  4303 			if ( false !== $list_msgstr ) { 
       
  4304  				if ($obj == 'mo') { 
       
  4305 					if ( $cur_msgid->plural === false ) {
       
  4306 						if ( false === $cur_msgid->ctxt ) {
       
  4307 							$original = $cur_msgid->post_content;
       
  4308 						} else {
       
  4309 							$original = $cur_msgid->ctxt . chr(4) . $cur_msgid->post_content ;
       
  4310 						}
       
  4311 						$mo->add_entry( $mo->make_entry( $original, $list_msgstr->post_content ) );
       
  4312 										
       
  4313 					} else {
       
  4314 						$list_msgstr_plural_post_content = array();
       
  4315 						foreach ( $list_msgstr as $one_msgstr ) {
       
  4316 							$list_msgstr_plural_post_content[] = $one_msgstr->post_content ;
       
  4317 						}
       
  4318 						if ( false === $cur_msgid->ctxt ) {  // PLURAL
       
  4319 							$original = $cur_msgid->post_content . chr(0) . $cur_msgid->plural_post_content ;
       
  4320 							$translation = implode( chr(0), $list_msgstr_plural_post_content );
       
  4321 							$mo->add_entry($mo->make_entry($original, $translation));
       
  4322 						} else { // CONTEXT + PLURAL
       
  4323 							$original = $cur_msgid->ctxt .chr(4). $cur_msgid->post_content . chr(0) . $cur_msgid->plural_post_content ;
       
  4324 							$translation = implode( chr(0), $list_msgstr_plural_post_content );
       
  4325 							$mo->add_entry( $mo->make_entry($original, $translation) );
  1281 						}
  4326 						}
  1282 					}
  4327 					}
  1283 					/* to create po with empty translations */
  4328 										
  1284 					if ($obj == 'po' && $noentry == true) {
  4329 				} else { /* po */ 
  1285 						$entry = & new Translation_Entry(array('singular'=>$curterm->description,'translations'=> ""));
  4330 				
  1286 						$mo->add_entry($entry);
  4331 					// comments prepare
       
  4332 					// * 	- translator_comments (string) -- comments left by translators
       
  4333 	 				// * 	- extracted_comments (string) -- comments left by developers
       
  4334 	 				// * 	- references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form
       
  4335 					// * 	- flags (array) -- flags like php-format
       
  4336 					
       
  4337 					$comment_array = array(); // $list_msgstr because in msgstr (20120318)
       
  4338 					
       
  4339 					if ( $cur_msgid->plural === false ) { 
       
  4340 					 	$translator_comments = get_post_meta ( $list_msgstr->ID, $this->msg_translator_comments, true );
       
  4341 						if ( $translator_comments != '' )  $comment_array['translator_comments'] = $translator_comments;
       
  4342 					} else {
       
  4343 						$translator_comments = get_post_meta ( $list_msgstr[0]->ID, $this->msg_translator_comments, true );
       
  4344 						if ( $translator_comments != '' )  $comment_array['translator_comments'] = $translator_comments;
  1287 					}
  4345 					}
  1288 				}		
  4346 					
  1289 			}
  4347 					$extracted_comments = get_post_meta ( $cur_msgid->ID, $this->msg_extracted_comments, true );
  1290 		//print_r ($mo);
  4348 					if ( $extracted_comments != '' )  $comment_array['extracted_comments'] = $extracted_comments;
       
  4349 					if ( $cur_msgid->post_excerpt != '' ) {
       
  4350 						$references = explode ('#: ', $cur_msgid->post_excerpt );
       
  4351 						$comment_array['references'] = $references;
       
  4352 					}
       
  4353 					$flags = get_post_meta ( $cur_msgid->ID, 'flags', true );
       
  4354 					if ( $flags != '' )  {
       
  4355 						$comment_array['flags'] = explode (', ', $flags );
       
  4356 					}
       
  4357 					
       
  4358 					if ( $cur_msgid->plural === false ) {
       
  4359 						if ( false === $cur_msgid->ctxt ) {
       
  4360 							$entry_array = array('singular'=>$cur_msgid->post_content,'translations'=> array( $list_msgstr ->post_content ) ) ; 
       
  4361 						} else {
       
  4362 							$entry_array = array('context'=>$cur_msgid->ctxt, 'singular'=>$cur_msgid->post_content, 'translations'=> array($list_msgstr ->post_content) );
       
  4363 						}
       
  4364 					} else { // PLURAL
       
  4365 						$list_msgstr_plural_post_content = array();
       
  4366 						foreach ( $list_msgstr as $one_msgstr ) {
       
  4367 							$list_msgstr_plural_post_content[] = $one_msgstr->post_content ;
       
  4368 						}
       
  4369 					
       
  4370 						if ( false === $cur_msgid->ctxt ) { 
       
  4371 							$entry_array = array('singular' => $cur_msgid->post_content,'plural' => $cur_msgid->plural_post_content, 'is_plural' =>1, 'translations' => $list_msgstr_plural_post_content );
       
  4372 						} else { // CONTEXT + PLURAL 
       
  4373 							$entry_array = array('context'=>$cur_msgid->ctxt, 'singular' => $cur_msgid->post_content, 'plural' => $cur_msgid->plural_post_content, 'is_plural' =>1, 'translations' => $list_msgstr_plural_post_content );
       
  4374 						}	
       
  4375 					}
       
  4376 					$entry = & new Translation_Entry( array_merge ( $entry_array, $comment_array ) );
       
  4377 					
       
  4378 					$mo->add_entry($entry); 
       
  4379 					$noentry = false;
       
  4380 				}
       
  4381 			}
       
  4382 			/* to create po with empty translations */
       
  4383 			if ($obj == 'po' && $noentry == true) {
       
  4384 				$comment_array = array(); // $list_msgstr because in msgstr (20120318)
       
  4385 					
       
  4386 				
       
  4387 				$extracted_comments = get_post_meta ( $cur_msgid->ID, $this->msg_extracted_comments, true );
       
  4388 				if ( $extracted_comments != '' )  $comment_array['extracted_comments'] = $extracted_comments;
       
  4389 				if ( $cur_msgid->post_excerpt != '' ) {
       
  4390 					$references = explode ('#: ', $cur_msgid->post_excerpt );
       
  4391 					$comment_array['references'] = $references;
       
  4392 				}
       
  4393 				$flags = get_post_meta ( $cur_msgid->ID, 'flags', true );
       
  4394 				if ( $flags != '' )  {
       
  4395 					$comment_array['flags'] = explode (', ', $flags );
       
  4396 				}
       
  4397 			
       
  4398 				
       
  4399 				$entry = & new Translation_Entry( array_merge ( array('singular'=>$cur_msgid->post_content,'translations'=> ""), $comment_array ) );
       
  4400 				$mo->add_entry($entry);
       
  4401 			}
       
  4402 		}	
       
  4403 		
       
  4404 		
       
  4405 			
  1291 		return $mo;
  4406 		return $mo;
  1292 	}
  4407 	}
  1293 	
  4408 	
  1294 	/**
  4409 	/**
  1295 	 * Save MO object to file
  4410 	 * Save MO object to file
  1296 	 *
  4411 	 *
  1297 	 *
  4412 	 *
  1298 	 * @since 1.0 - only WP >= 2.8.4
  4413 	 * @since 1.0 - only WP >= 2.8.4
       
  4414 	 * @updated 1.0.5 - wp-net 
       
  4415 	 *
       
  4416 	 * @updated 2.1
  1299 	 */	
  4417 	 */	
  1300 	function Save_MO_to_file ($curlang , $mo )	{
  4418 	function Save_MO_to_file ($curlang , $mo, $createfile = "" )	{
  1301 		$filename = substr($curlang,0,3).strtoupper(substr($curlang,-2));
  4419 		$filename = ( strlen ($curlang) == 5 ) ? substr($curlang,0,3).strtoupper(substr($curlang,-2)) : $curlang;
  1302 		$filename .= '.mo';
  4420 		$filename .= '.mo';
  1303 		$createfile = get_template_directory().$this->langfolder.$filename;
  4421 		if ("" == $createfile)
       
  4422 			$createfile = $this->get_template_directory.$this->langfolder.$filename;
       
  4423 		//echo $createfile;	
  1304 		if (false === $mo->export_to_file($createfile)) return false;
  4424 		if (false === $mo->export_to_file($createfile)) return false;
  1305 	}
  4425 	}
  1306 	
  4426 	
  1307 	/**
  4427 	/**
  1308 	 * Save PO object to file
  4428 	 * Save PO object to file
  1309 	 *
  4429 	 *
  1310 	 *
  4430 	 *
  1311 	 * @since 1.0 - only WP >= 2.8.4
  4431 	 * @since 1.0 - only WP >= 2.8.4
       
  4432 	 *
       
  4433 	 * @updated 2.1
  1312 	 */	
  4434 	 */	
  1313 	function Save_PO_to_file ($curlang , $po )	{
  4435 	function Save_PO_to_file ($curlang , $po, $createfile = ""  )	{
  1314 		$filename = substr($curlang,0,3).strtoupper(substr($curlang,-2));
  4436 		$filename = ( strlen ($curlang) == 5 ) ? substr($curlang,0,3).strtoupper(substr($curlang,-2)) : $curlang;
  1315 		$filename .= '.po';
  4437 		$filename .= '.po';
  1316 		$createfile = get_template_directory().$this->langfolder.$filename;
  4438 		if ( "" == $createfile)
  1317 		//print_r($po);
  4439 			$createfile = $this->get_template_directory.$this->langfolder.$filename;
  1318 		if (false === $po->export_to_file($createfile)) return false;
  4440 			if ( defined ('WP_DEBUG') &&  WP_DEBUG != true ) error_log ( '---- po file ------- '.$createfile );
  1319 	}
  4441 		if ( false === $po->export_to_file( $createfile ) ) { 
       
  4442 			return false;
       
  4443 		} else {
       
  4444 			return true;
       
  4445 		}
       
  4446 	}
       
  4447 	
  1320 	/** 
  4448 	/** 
  1321 	 * thanks to http://urbangiraffe.com/articles/translating-wordpress-themes-and-plugins/2/#plural_forms
  4449 	 * thanks to http://urbangiraffe.com/articles/translating-wordpress-themes-and-plugins/2/#plural_forms
  1322 	 * @since 1.0 - only WP >= 2.8
  4450 	 * @since 1.0 - only WP >= 2.8
       
  4451 	 *
       
  4452 	 * called when creating po
  1323 	 */	
  4453 	 */	
  1324 	function plural_forms_rule($curlang) {	
  4454 	function plural_forms_rule( $curlang ) {	
  1325 		$curlang = substr($curlang,0,3).strtoupper(substr($curlang,-2));
  4455 		$curlang = ( strlen ($curlang) == 5 ) ? substr($curlang,0,3).strtoupper(substr($curlang,-2)) : $curlang;
  1326 		$rulesarrays = array(
  4456 		$rulesarrays = array(
  1327 		'nplurals=1; plural=0' => array('tr_TR','ja_JA'),
  4457 		'nplurals=1; plural=0' => array('tr_TR','ja_JA','ja'),
  1328 		'nplurals=2; plural=1' => array('zh_ZH'),
  4458 		'nplurals=2; plural=1' => array('zh_ZH'),
  1329 		'nplurals=2; plural=n != 1' => array('en_US','en_UK','es_ES','da_DA'), 
  4459 		'nplurals=2; plural=n != 1' => array('en_US','en_UK','es_ES','da_DA'), 
  1330 		'nplurals=2; plural=n>1' => array('fr_FR','fr_CA','fr_BE','pt_BR'),
  4460 		'nplurals=2; plural=n>1' => array('fr_FR','fr_CA','fr_BE','pt_BR'),
  1331 		'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2' => array('lv_LV'),
  4461 		'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2' => array('lv_LV'),
  1332 		'nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2' => array('gd_GD'),
  4462 		'nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2' => array('gd_GD'),
  1339 		foreach ($rulesarrays as $rule => $langs) {
  4469 		foreach ($rulesarrays as $rule => $langs) {
  1340 			if (in_array($curlang, $langs)) return $rule;
  4470 			if (in_array($curlang, $langs)) return $rule;
  1341 		}
  4471 		}
  1342 		return 'nplurals=2; plural=n != 1'; /* english and most... */
  4472 		return 'nplurals=2; plural=n != 1'; /* english and most... */
  1343 	}
  4473 	}
  1344 		
  4474 	
  1345 	/*
  4475 	/** 
  1346 	 * import array of twintexts in terms tables
  4476 	 * bloginfo term and others in cpt 
  1347 	 *
  4477 	 * @since 2.0
  1348 	 * @since 0.9.0
  4478 	 * 
  1349 	 * @updated 0.9.7 to set in langs group
  4479 	 */
  1350 	 * @updated 1.0.0 to manage plural
  4480 	function xili_import_infosterms_cpt () {
  1351 	 *	
  4481 		$this->importing_mode = true ;
  1352 	 * @param array of msgid/msgstr, language (xx_XX)
  4482 		$nbname = array ( 0, 0 ); // to import, imported
  1353 	 *
  4483 		$terms_to_import = array();
  1354 	 */
  4484 		$temp = array ();
  1355 	function xili_import_in_tables($twintexts=Array(),$translang) {
  4485 		$temp['msgid'] = get_bloginfo( 'blogname', 'display' );
  1356 		$nbline = 0;
  4486 		$temp['extracted_comments'] = $this->local_tag.' bloginfo - blogname';
  1357 		$nbtline = 0;
  4487 		$terms_to_import[] = $temp ;
  1358 	 	foreach ($twintexts as $key => $line) {
  4488 		$temp['msgid'] = get_bloginfo( 'description', 'display' );	
  1359 	 		
  4489 		$temp['extracted_comments'] = $this->local_tag.' bloginfo - description';
  1360 	 		/* is content plural */
  4490 		$terms_to_import[] = $temp ;
  1361 				if (false === strpos($key,XPLURAL)) {			
  4491 		$temp['msgid'] = addslashes ( get_option('time_format') );
  1362 					$thekey = htmlentities($key);			
  4492 		$temp['extracted_comments'] = $this->local_tag.' bloginfo - time_format';
       
  4493 		$terms_to_import[] = $temp ;
       
  4494 		$temp['msgid'] = addslashes ( get_option('date_format') );
       
  4495 		$temp['extracted_comments'] = $this->local_tag.' bloginfo - date_format';
       
  4496 		$terms_to_import[] = $temp ;
       
  4497 		$nbname[0] += 4;
       
  4498 		if ( class_exists ('xili_language') ) {
       
  4499 			global $xili_language;
       
  4500 			foreach ( $xili_language->comment_form_labels as $key => $label) {
       
  4501 				$temp['msgid'] =  $label ;
       
  4502 				$temp['extracted_comments'] = $this->local_tag.' comment_form_labels '.$key;
       
  4503 				$terms_to_import[] = $temp ;
       
  4504 			}
       
  4505 			$nbname[0] += count( $xili_language->comment_form_labels );
       
  4506 		
       
  4507 			$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
       
  4508 	 		foreach ($listlanguages as $reflanguage) { // 2.1
       
  4509 	 			$temp['msgid'] =  $reflanguage->description ;
       
  4510 				$temp['extracted_comments'] = $this->local_tag.' language with ISO '.$reflanguage->name;
       
  4511 				$terms_to_import[] = $temp ;	
       
  4512 	 		}
       
  4513 	 		$nbname[0] += count( $listlanguages );
       
  4514 		
       
  4515 			if ( XILILANGUAGE_VER > '2.3.9' ) { // msgid and msgstr
       
  4516 				global $wp_locale;
       
  4517 				 $wp_locale_array_trans = array (
       
  4518 					'Sunday' => $wp_locale->weekday[0], 'Monday' => $wp_locale->weekday[1], 'Tuesday' => $wp_locale->weekday[2], 
       
  4519 					'Wednesday' => $wp_locale->weekday[3], 'Thursday' => $wp_locale->weekday[4], 'Friday' => $wp_locale->weekday[5], 
       
  4520 					'Saturday' => $wp_locale->weekday[6],
       
  4521 					'S_Sunday_initial' => $wp_locale->weekday_initial[$wp_locale->weekday[0]], 
       
  4522 					'M_Monday_initial' => $wp_locale->weekday_initial[$wp_locale->weekday[1]], 
       
  4523 					'T_Tuesday_initial' => $wp_locale->weekday_initial[$wp_locale->weekday[2]], 
       
  4524 					'W_Wednesday_initial' => $wp_locale->weekday_initial[$wp_locale->weekday[3]], 
       
  4525 					'T_Thursday_initial' => $wp_locale->weekday_initial[$wp_locale->weekday[4]], 
       
  4526 					'F_Friday_initial' => $wp_locale->weekday_initial[$wp_locale->weekday[5]], 
       
  4527 					'S_Saturday_initial' => $wp_locale->weekday_initial[$wp_locale->weekday[6]],
       
  4528 					'Sun' => $wp_locale->weekday_abbrev[$wp_locale->weekday[0]], 
       
  4529 					'Mon' => $wp_locale->weekday_abbrev[$wp_locale->weekday[1]], 
       
  4530 					'Tue' => $wp_locale->weekday_abbrev[$wp_locale->weekday[2]], 
       
  4531 					'Wed' => $wp_locale->weekday_abbrev[$wp_locale->weekday[3]], 
       
  4532 					'Thu' => $wp_locale->weekday_abbrev[$wp_locale->weekday[4]], 
       
  4533 					'Fri' => $wp_locale->weekday_abbrev[$wp_locale->weekday[5]], 
       
  4534 					'Sat' => $wp_locale->weekday_abbrev[$wp_locale->weekday[6]],
       
  4535 					'January' => $wp_locale->month['01'], 'February' => $wp_locale->month['02'], 
       
  4536 					'March' => $wp_locale->month['03'], 'April' => $wp_locale->month['04'], 'May' => $wp_locale->month['05'], 
       
  4537 					'June' => $wp_locale->month['06'], 'July' => $wp_locale->month['07'], 'August' => $wp_locale->month['08'], 
       
  4538 					'September' => $wp_locale->month['09'], 'October' => $wp_locale->month['10'], 'November' => $wp_locale->month['11'], 
       
  4539 					'December' => $wp_locale->month['12'],
       
  4540 					'Jan_January_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['01']], 
       
  4541 					'Feb_February_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['02']], 
       
  4542 					'Mar_March_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['03']], 
       
  4543 					'Apr_April_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['04']], 
       
  4544 					'May_May_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['05']], 
       
  4545 					'Jun_June_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['06']], 
       
  4546 					'Jul_July_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['07']], 
       
  4547 					'Aug_August_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['08']], 
       
  4548 					'Sep_September_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['09']], 
       
  4549 					'Oct_October_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['10']], 
       
  4550 					'Nov_November_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['11']], 
       
  4551 					'Dec_December_abbreviation' => $wp_locale->month_abbrev[$wp_locale->month['12']],
       
  4552 					'am' => $wp_locale->meridiem['am'], 'pm' => $wp_locale->meridiem['pm'], 
       
  4553 					'AM' => $wp_locale->meridiem['AM'], 'PM' => $wp_locale->meridiem['PM'],
       
  4554 					'number_format_thousands_sep' => $wp_locale->number_format['thousands_sep'], 'number_format_decimal_point' => $wp_locale->number_format['decimal_point']
       
  4555 					);
       
  4556 				if ( isset ( $wp_locale->text_direction) ) {
       
  4557 					$wp_locale_array_trans['text_direction'] = $wp_locale->text_direction; //_x( 'ltr', 'text direction', $theme_domain ) ))  ) 	
       
  4558 				}	
       
  4559 				if ( 'en_US' == get_locale() ) {
       
  4560 					foreach ( $wp_locale_array_trans as $key => $value ) {
       
  4561 						$temp['msgid'] =  $key ;
       
  4562 						$temp['extracted_comments'] = $this->local_tag.' wp_locale '.$key;
       
  4563 						$terms_to_import[] = $temp ;
       
  4564 					}
       
  4565 				}
       
  4566 			}
       
  4567 		}
       
  4568 		
       
  4569 		foreach ( $terms_to_import as $term )  {
       
  4570 			
       
  4571 			if ( $term['msgid'] == 'text_direction' )  {
       
  4572 				$the_context = 'text direction';
       
  4573 			} else {
       
  4574 				$the_context = null;
       
  4575 			}
       
  4576 			
       
  4577 			$result = $this->msgid_exists ( $term['msgid'], $the_context ) ;
       
  4578 			
       
  4579 			$t_entry = array();
       
  4580 			$t_entry['extracted_comments'] = $term['extracted_comments'] ;
       
  4581 			$entry = (object) $t_entry ;
       
  4582 			
       
  4583 			if ( $result === false ) {
       
  4584 				// create the msgid
       
  4585 				
       
  4586 				$msgid_post_ID = $this->insert_one_cpt_and_meta( $term['msgid'], $the_context, 'msgid', 0, $entry ) ;
       
  4587 				$nbname[1]++;
       
  4588 			} else {
       
  4589 				$msgid_post_ID = $result[0];
       
  4590 				// add comment in existing ?
       
  4591 			}
       
  4592 			$nbname[0]++;
       
  4593 		}
       
  4594 		
       
  4595 		$curlang = get_locale() ; // admin language of config - import id and str
       
  4596 		if ( class_exists ('xili_language') && XILILANGUAGE_VER > '2.3.9' && 'en_US' != $curlang ) {
       
  4597 			
       
  4598 			foreach ( $wp_locale_array_trans as $key => $value ) {
       
  4599 				
       
  4600 				$t_entry = array();
       
  4601 				$t_entry['extracted_comments'] = $this->local_tag.' wp_locale '.$key ;
       
  4602 				// add context for this wp_locale
       
  4603 				if ( $key == 'text_direction' )  {
       
  4604 					$the_context = 'text direction';
  1363 				} else {
  4605 				} else {
  1364 					$plurals = explode (XPLURAL,$key);
  4606 					$the_context = null;
  1365 					$thekey = htmlentities($plurals[0]);	/* in term slug only first*/
  4607 				}
  1366 				}	
  4608 				
  1367 	 		
  4609 				$entry = (object) $t_entry ;
  1368 	    	// verify if origin msgid term exist
  4610 				
  1369 			$cur_id = is_term($thekey, DTAXONAME);
  4611 				$result = $this->msgid_exists ( $key, $the_context ) ;
  1370 			if ($cur_id == 0) {
  4612 				
  1371 				// create term 
  4613 				if ( $result === false ) {
  1372 				$args = array('description' => $key, 'slug'=>sanitize_title($thekey));
  4614 					// create the msgid
  1373 				$cur_id = is_term(sanitize_title($thekey),DTAXONAME);
  4615 					
  1374 				if ($cur_id == 0) {
  4616 					$msgid_post_ID = $this->insert_one_cpt_and_meta( $key, $the_context, 'msgid', 0, $entry ) ;
  1375 					$result = $this->xili_dic_insert_term(htmlentities($thekey), DTAXONAME, $args);
  4617 					$nbname[1]++;
  1376 					$insertid = $result['term_id'];
       
  1377 					$nbline++;
       
  1378 				} else {
  4618 				} else {
  1379 					$insertid = $cur_id['term_id'];	
  4619 					$msgid_post_ID = $result[0];
  1380 				}	
  4620 					// add comment
  1381 				$parent_term = get_term($insertid,DTAXONAME,OBJECT,'edit');
  4621 				}
  1382 				 
  4622 				
  1383 				/* create the translated term */
  4623 				$result = $this->msgstr_exists ( $value, $msgid_post_ID, $curlang ) ;
  1384 				$sslug = $parent_term->slug.'_'.strtolower($translang);
  4624 				if ( $result === false ) {
  1385 				$args = array('parent' => $parent_term->term_id, 'slug' => $sslug,'description' => $line);
  4625 					$msgstr_post_ID = $this->insert_one_cpt_and_meta( $value, $the_context, 'msgstr', 0, $entry );
  1386 				$existing = get_term_by('slug', $sslug, DTAXONAME, OBJECT);
  4626 					$nbname[1]++;
  1387 				if ($existing == null && !is_wp_error($existing)) { /* perhaps in another lang */
  4627 					wp_set_object_terms( $msgstr_post_ID, $curlang, TAXONAME );
  1388 					/* msgstr don't exist */
       
  1389 					/* is content plural */
       
  1390 					if (false === strpos($line,XPLURAL)) {			
       
  1391 						$theline = htmlentities($line);			
       
  1392 					} else {
       
  1393 						$plurals = explode (XPLURAL,$line);
       
  1394 						$theline = htmlentities($plurals[0]);	/* in term slug only first*/
       
  1395 					}	
       
  1396 	 		 
       
  1397 					$result = $this->xili_dic_insert_term($theline, DTAXONAME, $args);
       
  1398 					if (!is_wp_error($result)) wp_set_object_terms((int) $result['term_id'], strtolower($translang), XDDICTLANGS,false);
       
  1399 					$nbtline++;	
       
  1400 				} else {
  4628 				} else {
  1401 					/* test slug of existing term */
  4629 					$msgstr_post_ID = $result[0];
  1402 					if ($line != $existing->description) {
  4630 				}
  1403 						$this->xili_dic_update_term($existing->term_id, DTAXONAME, $args);
  4631 				
  1404 						$nbuline++;
  4632 				// create link according lang
  1405 					}
  4633 				
  1406 				}		
  4634 				$res = get_post_meta ( $msgid_post_ID, $this->msglang_meta, false );
       
  4635 				$thelangs =  ( is_array ( $res ) &&  array() != $res ) ? $res[0]  : array();
       
  4636 				$thelangs['msgstrlangs'][$curlang]['msgstr'] = $msgstr_post_ID;
       
  4637 				update_post_meta ( $msgid_post_ID, $this->msglang_meta, $thelangs );
       
  4638 				update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $msgid_post_ID );
       
  4639 						
       
  4640 			}
       
  4641 			
       
  4642 			$nbname[0] += count( $wp_locale_array_trans ) ; 	
       
  4643 		}
       
  4644 		
       
  4645 		$this->importing_mode = false ;
       
  4646 		return $nbname;
       
  4647 		
       
  4648 	}
       
  4649 	
       
  4650 	/** 
       
  4651 	 * taxonomy's terms in array (name - description)
       
  4652 	 * by default taxonomy
       
  4653 	 *
       
  4654 	 */
       
  4655 	function xili_read_catsterms_cpt( $taxonomy = 'category', $local_tag = '[local]' ){
       
  4656 		$this->importing_mode = true ;
       
  4657 		$nbnames = array ( 0, 0 ); // term, description
       
  4658 		$listcategories = get_terms( $taxonomy, array('hide_empty' => false));
       
  4659 		foreach ($listcategories as $category) {
       
  4660 			
       
  4661 			$result = $this->msgid_exists ( $category->name ) ;
       
  4662 			
       
  4663 			$t_entry = array();
       
  4664 			$t_entry['extracted_comments'] = sprintf ( $local_tag.' name from %s with slug %s', $taxonomy, $category->slug ) ;
       
  4665 			$entry = (object) $t_entry ;
       
  4666 			
       
  4667 			if ( $result === false ) {
       
  4668 				// create the msgid 
       
  4669 				$msgid_post_ID = $this->insert_one_cpt_and_meta( $category->name, null, 'msgid', 0, $entry ) ;
       
  4670 				$nbnames[0]++;
  1407 			} else {
  4671 			} else {
  1408 			/* echo msgid exist */
  4672 				$msgid_post_ID = $result[0];
  1409 				$parent_term = get_term($cur_id['term_id'],DTAXONAME,OBJECT,'edit');
  4673 				// add comment in existing ?
  1410 				
  4674 			}
  1411 				/* verify translated term msgstr */
  4675 			
  1412 				if (''!=$line) {
  4676 			
  1413 					
  4677 			$result = $this->msgid_exists ( $category->description ) ;
  1414 					$sslug = $parent_term->slug.'_'.strtolower($translang);
  4678 			
  1415 					$args = array('parent' => $parent_term->term_id, 'slug' => $sslug, 'description' => $line);
  4679 			$t_entry = array();
  1416 					$existing = get_term_by('slug', $sslug, DTAXONAME, OBJECT);
  4680 			$t_entry['extracted_comments'] = sprintf ( $this->local_tag.' desc from %s with slug %s', $taxonomy, $category->slug ) ;
  1417 					if ($existing == null && !is_wp_error($existing)) {
  4681 			$entry = (object) $t_entry ;
  1418 						/* no term msgstr */
  4682 			
  1419 						/* is content plural */
  4683 			if ( $result === false ) {
  1420 						if (false === strpos($line,XPLURAL)) {			
  4684 				// create the msgid
  1421 							$theline = htmlentities($line);			
  4685 				$msgid_post_ID = $this->insert_one_cpt_and_meta( $category->description, null, 'msgid', 0, $entry ) ;
  1422 						} else {
  4686 				$nbnames[1]++;
  1423 							$plurals = explode (XPLURAL,$line);
  4687 			} else {
  1424 							$theline = htmlentities($plurals[0]);	/* in term slug only first*/
  4688 				$msgid_post_ID = $result[0];
  1425 						}
  4689 				// add comment in existing ?
  1426 						$result = $this->xili_dic_insert_term($theline, DTAXONAME, $args);
  4690 			}
  1427 						if (!is_wp_error($result)) 
  4691 			
  1428 							wp_set_object_terms((int) $result['term_id'], strtolower($translang), XDDICTLANGS,false);
  4692 		}
  1429 						$nbtline++;
  4693 		
  1430 					} else {
  4694 		$this->importing_mode = false ;
  1431 						/* term exists */ 
  4695 		return $nbnames;
  1432 						if ($line != $existing->description) {
  4696 	}
  1433 							$this->xili_dic_update_term($existing->term_id, DTAXONAME, $args);
  4697 		
  1434 							$nbuline++;
  4698 	/**
  1435 						}
  4699 	 * Scan terms in themes files
  1436 					}		
  4700 	 *
  1437 				} /* empty line */
  4701 	 */
  1438 			} /* parent exist */
  4702 	function scan_import_theme_terms( $callback, $display ) {
  1439 	 	} /* loop */
  4703 		$path = $this->get_template_directory ;
  1440 	 	return array($nbline,$nbtline,$nbuline);  //root id lines, translated lines and updated translated lines
       
  1441 	}
       
  1442 	
       
  1443 	/* cat's terms in array (name - slug - description)*/
       
  1444 	function xili_read_catsterms(){
       
  1445 		$listcategories = get_terms('category', array('hide_empty' => false));
       
  1446 		foreach ($listcategories as $category) {
       
  1447 			$catterms[] = Array($category->name,$category->description);
       
  1448 		}
       
  1449 		return $catterms;
       
  1450 	}
       
  1451 	/* array in tables */
       
  1452 	function xili_importcatsterms_in_tables($catterms= Array()){
       
  1453 		$nbname = 0;
       
  1454 		$nbdesc = 0;
       
  1455 		foreach ($catterms as $onecat) {
       
  1456 	     
       
  1457 			$cur_id = is_term($onecat[0], DTAXONAME);
       
  1458 			if ($cur_id == 0) {
       
  1459 				 
       
  1460 				$args = array('description' => $onecat[0]);
       
  1461 				$result = $this->xili_dic_insert_term( $onecat[0], DTAXONAME, $args);
       
  1462 				$nbname++;
       
  1463 			}
       
  1464 			$cur_id = is_term(htmlentities($onecat[1]), DTAXONAME);
       
  1465 			if ($cur_id == 0 && ""!=$onecat[1]) {
       
  1466 				 
       
  1467 				$args = array('description' => $onecat[1]);
       
  1468 				$result = $this->xili_dic_insert_term(htmlentities($onecat[1]), DTAXONAME, $args);
       
  1469 				$nbdesc++;
       
  1470 			}
       
  1471 		}
       
  1472 		return array($nbname,$nbdesc);
       
  1473 	}
       
  1474 	
       
  1475 		
       
  1476 	function scan_import_theme_terms($callback,$display) {
       
  1477 		$path = get_template_directory();
       
  1478 		$themefiles = array();
  4704 		$themefiles = array();
  1479 		 
  4705 		 
  1480 		$dir_handle = @opendir($path) or die("Unable to open $path"); 
  4706 		$dir_handle = @opendir($path) or die("Unable to open $path"); 
  1481 	 
  4707 	 
  1482 		while ($file = readdir($dir_handle)) { 
  4708 		while ($file = readdir($dir_handle)) { 
  1521 		} else {
  4747 		} else {
  1522 			$this->tempoutput .= "<br /><strong>".__('List of found terms','xili-dictionary').": </strong><br />";
  4748 			$this->tempoutput .= "<br /><strong>".__('List of found terms','xili-dictionary').": </strong><br />";
  1523 			$this->tempoutput .= implode (', ',$resultterms);
  4749 			$this->tempoutput .= implode (', ',$resultterms);
  1524 		}
  4750 		}
  1525 	}
  4751 	}
  1526 	/*
  4752 	
  1527 	 * Import theme terms array in table 
       
  1528 	 *
       
  1529 	 *
       
  1530 	 */
       
  1531 	function xili_importthemeterms_in_tables($themeterms= Array()){
       
  1532 		$nbname = 0;
       
  1533 		 
       
  1534 		foreach ($themeterms as $onecat) {
       
  1535 	     
       
  1536 			$cur_id = is_term($onecat, DTAXONAME);
       
  1537 			if ($cur_id == 0) {
       
  1538 				
       
  1539 				$args = array('description' => $onecat);
       
  1540 				$result = $this->xili_dic_insert_term(htmlentities($onecat), DTAXONAME, $args);
       
  1541 				$nbname++;
       
  1542 			}
       
  1543 		}
       
  1544 		return $nbname;
       
  1545 	}
       
  1546 	/**
  4753 	/**
  1547 	 * Recursive search of files in a path
  4754 	 * Recursive search of files in a path
  1548 	 * @since 1.0
  4755 	 * @since 1.0
  1549 	 *
  4756 	 *
  1550 	 */
  4757 	 */
  1568 	}
  4775 	}
  1569 	/**
  4776 	/**
  1570 	 * display lines of files in special sidebox
  4777 	 * display lines of files in special sidebox
  1571 	 * @since 1.0
  4778 	 * @since 1.0
  1572 	 */
  4779 	 */
  1573 	function available_mo_files($path , $filename) {
  4780 	function available_mo_files( $path , $filename ) {
  1574   		//echo $filename . " in : " . "/".str_replace("/","",str_replace(get_template_directory(),'',$path)) . "<br />";
  4781   		$langfolder = str_replace($this->get_template_directory, '', $path);
  1575   		echo str_replace(".mo","",$filename ). " (".$this->ossep.str_replace($this->ossep,"",str_replace(get_template_directory(),'',$path)).")<br />";
  4782   		if  ( $langfolder == "" ) $langfolder = '/';
  1576 	}		
  4783   		$shortfilename = str_replace(".mo","",$filename );
       
  4784   		$alert = '<span style="color:red;">'.__('Uncommon filename','xili-dictionary').'</span>' ;
       
  4785   		if ( strlen($shortfilename)!=5 && strlen($shortfilename) != 2  ) {
       
  4786   		  if ( false === strpos( $shortfilename, 'local-' ) ) {
       
  4787   		  	$message = $alert;
       
  4788   		  } else {
       
  4789   		  	$message = '<em>'.__("Site's values",'xili-dictionary').'</em>';
       
  4790   		  }
       
  4791   			
       
  4792   		} else if (  false === strpos( $shortfilename, '_' ) && strlen($shortfilename) == 5 )  {
       
  4793   			$message = $alert; 
       
  4794   		} else {
       
  4795   			$message = '';
       
  4796   		}
       
  4797   		  		
       
  4798   		echo $shortfilename . " (". $langfolder . ") " . $message . "<br />";
       
  4799 	}
       
  4800 	
       
  4801 	
       
  4802 	/**
       
  4803 	 * Contextual help
       
  4804 	 *
       
  4805 	 * @since 1.2.2
       
  4806 	 */
       
  4807 	 function add_help_text($contextual_help, $screen_id, $screen) { 
       
  4808 	  //error_log($screen->id);
       
  4809 	  $more_infos =    
       
  4810 		      '<p><strong>' . __('For more information:') . '</strong></p>' .
       
  4811 		      '<p>' . __('<a href="http://wiki.xiligroup.org" target="_blank">Xili Plugins Documentation and WIKI</a>', 'xili-dictionary') . '</p>' .
       
  4812 		      '<p>' . __('<a href="http://dev.xiligroup.com/xili-dictionary" target="_blank">Xili-dictionary Plugin Documentation</a>','xili-dictionary') . '</p>' .
       
  4813 		      '<p>' . __('<a href="http://codex.wordpress.org/" target="_blank">WordPress Documentation</a>','xili-dictionary') . '</p>' .
       
  4814 		      '<p>' . __('<a href="http://forum2.dev.xiligroup.com/" target="_blank">Support Forums</a>','xili-dictionary') . '</p>' ;
       
  4815 		      
       
  4816 	  if ( 'xdmsg_page_dictionary_page' == $screen->id ) {
       
  4817 	    	$about_infos =
       
  4818 		      '<p>' . __('Things to remember to set xili-dictionary:','xili-dictionary') . '</p>' .
       
  4819 		      '<ul>' .
       
  4820 		      '<li>' . __('Verify that the theme is localizable (like kubrick, fusion or twentyten).','xili-dictionary') . '</li>' .
       
  4821 		      '<li>' . __('Define the list of targeted languages.','xili-dictionary') . '</li>' .
       
  4822 		      '<li>' . __('Prepare a sub-folder .po and .mo files for each language (use the default delivered with the theme or add the pot of the theme and put them inside.', 'xili-dictionary') . '</li>' .
       
  4823 		      '<li>' . __('If you have files: import them to create a base dictionary. If not : add a term or use buttons of import and export metabox.', 'xili-dictionary') . '</li>' .
       
  4824 		      '</ul>' ;
       
  4825 		     
       
  4826 		  	$screen->add_help_tab( array(
       
  4827 	 				'id'      => 'about-xili-dictionary',
       
  4828 					'title'   => __('About xili-dictionary','xili-dictionary'),
       
  4829 					'content' => $about_infos,
       
  4830 			  ));
       
  4831 		  	$screen->add_help_tab( array(
       
  4832 	 				'id'      => 'more-infos',
       
  4833 					'title'   => __('For more infos','xili-dictionary'),
       
  4834 					'content' => $more_infos,
       
  4835 			  ));
       
  4836 			  
       
  4837 	  } elseif ( in_array ($screen->id, array('xdmsg', 'edit-xdmsg') ) ) {
       
  4838 	  	if ( 'edit-xdmsg' == $screen->id ) {
       
  4839 	  	
       
  4840 			$about_infos_edit_msg =
       
  4841 		      '<p>' . __('Things to remember about the list of translations (msgstr) of term (msgid) with xili-dictionary:','xili-dictionary') . '</p>'.
       
  4842 		      '<p>' . __('More details in next versions','xili-dictionary') . '</p>';      
       
  4843 	  	
       
  4844 	  		$screen->add_help_tab( array(
       
  4845 	 				'id'      => 'about-xili-dictionary-msg',
       
  4846 					'title'   => __('About MSG list page','xili-dictionary'),
       
  4847 					'content' => $about_infos_edit_msg,
       
  4848 			  ));
       
  4849 			  
       
  4850 	  	} else { // edit or new
       
  4851 	  		$about_infos_msg =
       
  4852 		      '<p>' . __('Things to remember before to create or edit a new translation (msgstr) or a term (msgid) with xili-dictionary:','xili-dictionary') . '</p>'.
       
  4853 		      '<p>' . __('More details in next versions','xili-dictionary') . '</p>';
       
  4854 		      
       
  4855 	  		$screen->add_help_tab( array(
       
  4856 	 				'id'      => 'about-xili-dictionary-msg',
       
  4857 					'title'   => __('About MSG edit','xili-dictionary'),
       
  4858 					'content' => $about_infos_msg,
       
  4859 			  ));
       
  4860 	  		
       
  4861 	  	}	  
       
  4862 	  	
       
  4863 	  	$screen->add_help_tab( array(
       
  4864 	 				'id'      => 'more-infos',
       
  4865 					'title'   => __('For more infos','xili-dictionary'),
       
  4866 					'content' => $more_infos,
       
  4867 			  ));	
       
  4868 	  	
       
  4869 	  }
       
  4870 	  return $contextual_help;
       
  4871 	}
       
  4872 	
       
  4873 	
       
  4874 	// called by each pointer
       
  4875 	function insert_news_pointer ( $case_news ) {
       
  4876 			wp_enqueue_style( 'wp-pointer' );
       
  4877 			wp_enqueue_script( 'wp-pointer', false, array('jquery') );
       
  4878 			++$this->news_id;
       
  4879 			$this->news_case[$this->news_id] = $case_news;	
       
  4880 	}
       
  4881 	// insert the pointers registered before
       
  4882 	function print_the_pointers_js (  ) { 
       
  4883 		if ( $this->news_id != 0 ) {
       
  4884 			for ($i = 1; $i <= $this->news_id; $i++) {
       
  4885 				$this->print_pointer_js ( $i );
       
  4886 			}
       
  4887 		}
       
  4888 	}
       
  4889 	
       
  4890 	function print_pointer_js ( $indice  ) {  ;
       
  4891 		
       
  4892 		$args = $this->localize_admin_js( $this->news_case[$indice], $indice );
       
  4893 		if ( $args['pointerText'] != '' ) { // only if user don't read it before
       
  4894 		?>
       
  4895 		<script type="text/javascript">
       
  4896 		//<![CDATA[
       
  4897 		jQuery(document).ready( function() {
       
  4898  	
       
  4899  	var strings<?php echo $indice; ?> = <?php echo json_encode( $args ); ?>;
       
  4900  	
       
  4901 	<?php /** Check that pointer support exists AND that text is not empty - inspired www.generalthreat.com */ ?>
       
  4902 	
       
  4903 	if(typeof(jQuery().pointer) != 'undefined' && strings<?php echo $indice; ?>.pointerText != '') {
       
  4904 		jQuery( strings<?php echo $indice; ?>.pointerDiv ).pointer({
       
  4905 			content    : strings<?php echo $indice; ?>.pointerText,
       
  4906 			position: { edge: strings<?php echo $indice; ?>.pointerEdge,
       
  4907 				at: strings<?php echo $indice; ?>.pointerAt,
       
  4908 				my: strings<?php echo $indice; ?>.pointerMy,
       
  4909 				offset: strings<?php echo $indice; ?>.pointerOffset
       
  4910 			},       
       
  4911 			close  : function() {
       
  4912 				jQuery.post( ajaxurl, {
       
  4913 					pointer: strings<?php echo $indice; ?>.pointerDismiss,
       
  4914 					action: 'dismiss-wp-pointer'
       
  4915 				});
       
  4916 			}
       
  4917 		}).pointer('open');
       
  4918 	}
       
  4919 });
       
  4920 		//]]>
       
  4921 		</script>
       
  4922 		<?php
       
  4923 		}
       
  4924 	}
       
  4925 	
       
  4926 	
       
  4927 	/**
       
  4928 	 * News pointer for tabs
       
  4929 	 *
       
  4930 	 * @since 2.6.2
       
  4931 	 *
       
  4932 	 */
       
  4933 	function localize_admin_js( $case_news, $news_id ) {
       
  4934  			$about = __('Docs about xili-dictionary', 'xili-dictionary');
       
  4935  			$pointer_edge = '';
       
  4936  			$pointer_at = '';
       
  4937  			$pointer_my = '';
       
  4938  		switch ( $case_news ) {
       
  4939  			
       
  4940  			case 'xd_new_version' :
       
  4941  				$pointer_text = '<h3>' . esc_js( __( 'xili-dictionary updated', 'xili-dictionary') ) . '</h3>';
       
  4942 				$pointer_text .= '<p>' . esc_js( sprintf( __( 'xili-dictionary was updated to version %s', 'xili-dictionary' ) , XILIDICTIONARY_VER) ). '.</p>';
       
  4943 				$pointer_text .= '<p>' . esc_js( __( 'Version 2.2 improves border-line situations, better messaging. Don’t forget to read latest wiki post about this plugin (see link below).', 'xili-dictionary')). ',</p>';
       
  4944 				$pointer_text .= '<p>' . esc_js( __( 'New boxes added in edit screen of a term: list of untranslated terms, shorcuts to update quickly .mo file', 'xili-dictionary')). ',</p>';
       
  4945 				$pointer_text .= '<p>' . esc_js( __( 'See list and edit a term from the ', 'xili-dictionary' ).' “<a href="edit.php?post_type=xdmsg">'. __('list of msgs','xili-dictionary')."</a>”" ). ',</p>';
       
  4946 				$pointer_text .= '<p>' . esc_js( __( 'New queries to detect untranslated terms,', 'xili-dictionary')). '</p>';
       
  4947 				$pointer_text .= '<p>' . esc_js( __( 'See submenu', 'xili-dictionary' ).' “<a href="edit.php?post_type=xdmsg&page=dictionary_page">'. __('Tools, Files po mo','xili-dictionary')."</a>”" ). '.</p>';
       
  4948 				$pointer_text .= '<p>' . esc_js( sprintf(__( 'Before to question dev.xiligroup support, do not forget to visit %s documentation', 'xili-dictionary' ), '<a href="http://wiki.xiligroup.org" title="'.$about.'" >wiki</a>' ) ). '.</p>';
       
  4949  				$pointer_dismiss = 'xd-new-version-'.str_replace('.', '-', XILIDICTIONARY_VER); 
       
  4950  				$pointer_div = '#menu-posts-xdmsg';
       
  4951  				$pointer_Offset = '0 0';
       
  4952  				$pointer_edge = 'left';
       
  4953  				$pointer_my = 'left';
       
  4954  				$pointer_at = 'right';
       
  4955 				break;
       
  4956  				
       
  4957 			default: // nothing 
       
  4958 				$pointer_text = ''; 
       
  4959 		}
  1577 
  4960 
  1578 } /* end of class */
  4961  			// inspired from www.generalthreat.com
       
  4962 		// Get the list of dismissed pointers for the user
       
  4963 		$dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
       
  4964 		if ( in_array( $pointer_dismiss, $dismissed ) && $pointer_dismiss == 'xd-new-version-'.str_replace('.', '-', XILIDICTIONARY_VER) ) {
       
  4965 			$pointer_text = '';
       
  4966 		// Check whether our pointer has been dismissed two times
       
  4967 		} elseif ( in_array( $pointer_dismiss, $dismissed ) && in_array( $pointer_dismiss.'-1', $dismissed ) ) {
       
  4968 			$pointer_text = '';
       
  4969 		} elseif ( in_array( $pointer_dismiss, $dismissed ) ) {
       
  4970 			$pointer_dismiss = $pointer_dismiss.'-1';
       
  4971 		}
  1579 
  4972 
  1580 /**** Functions that improve taxinomy.php ****/
  4973 		return array(
  1581 
  4974 			'pointerText' => html_entity_decode( (string) $pointer_text, ENT_QUOTES, 'UTF-8'),
  1582 /**
  4975 			'pointerDismiss' => $pointer_dismiss,
  1583  * get terms and add order in term's series that are in a taxonomy 
  4976 			'pointerDiv' => $pointer_div,
  1584  * (not in class for general use)
  4977 			'pointerEdge' => ( '' == $pointer_edge ) ? 'top' : $pointer_edge ,
  1585  * 
  4978 			'pointerAt' => ( '' == $pointer_at ) ? 'left top' : $pointer_at ,
  1586  * @since 0.9.8.2 - provided here if xili-tidy-tags plugin is not used
  4979 			'pointerMy' => ( '' == $pointer_my ) ? 'left top' : $pointer_my ,
  1587  *
  4980 			'pointerOffset' => $pointer_Offset,
  1588  */
  4981 			'newsID' => $news_id
  1589 if (!function_exists('get_terms_of_groups')) { 
  4982 		);
  1590 	function get_terms_of_groups ($group_ids, $taxonomy, $taxonomy_child, $order = '') {
  4983     }
       
  4984 	
       
  4985 		
       
  4986 	
       
  4987 	/**** Functions that improve taxinomy.php - avoid conflict if xl absent ****/
       
  4988 	function get_terms_of_groups_lite ($group_ids, $taxonomy, $taxonomy_child, $order = '') {
  1591 		global $wpdb;
  4989 		global $wpdb;
  1592 		if ( !is_array($group_ids) )
  4990 		if ( !is_array($group_ids) )
  1593 			$group_ids = array($group_ids);
  4991 			$group_ids = array($group_ids);
  1594 		$group_ids = array_map('intval', $group_ids);
  4992 		$group_ids = array_map('intval', $group_ids);
  1595 		$group_ids = implode(', ', $group_ids);
  4993 		$group_ids = implode(', ', $group_ids);
  1596 		$theorderby = '';
  4994 		$theorderby = '';
  1597 		$where = '';
  4995 		
  1598 		$defaults = array('orderby' => 'term_order', 'order' => 'ASC',
  4996 		// lite release
  1599 		'hide_empty' => true, 'exclude' => '', 'exclude_tree' => '', 'include' => '',
  4997 		if ($order == 'ASC' || $order == 'DESC') $theorderby = ' ORDER BY tr.term_order '.$order ;
  1600 		'number' => '', 'slug' => '', 'parent' => '',
  4998 			
  1601 		'name__like' => '',
  4999 		$query = "SELECT t.*, tt2.term_taxonomy_id, tt2.description,tt2.parent, tt2.count, tt2.taxonomy, tr.term_order FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN $wpdb->terms AS t ON t.term_id = tr.object_id INNER JOIN $wpdb->term_taxonomy AS tt2 ON tt2.term_id = tr.object_id WHERE tt.taxonomy IN ('".$taxonomy."') AND tt2.taxonomy = '".$taxonomy_child."' AND tt.term_id IN (".$group_ids.") ".$theorderby;
  1602 		'pad_counts' => false, 'offset' => '', 'search' => '');
  5000 		
  1603 		
  5001 		$listterms = $wpdb->get_results($query);
  1604 		if (is_array($order)) { 
  5002 		if ( ! $listterms )
  1605 			 
  5003 			return array();
  1606 			$r = &$order;
  5004 	
  1607 			$r = array_merge($defaults, $r);
  5005 		return $listterms;
  1608 			extract($r);
  5006 	}	
  1609 			
  5007 	// used onetime from v2 to v2.1
  1610 			if ($order == 'ASC' || $order == 'DESC') {
  5008 	function update_postmeta_msgid() {
  1611 				if ('term_order'== $orderby) {
  5009 		global $wpdb;
  1612 					$theorderby = ' ORDER BY tr.'.$orderby.' '.$order ;
  5010 		// scan msgid
  1613 				} elseif ('count'== $orderby || 'parent'== $orderby) {
  5011 		$query = sprintf("SELECT $wpdb->posts.ID 
  1614 					$theorderby = ' ORDER BY tt2.'.$orderby.' '.$order ;
  5012 			FROM $wpdb->posts
  1615 				} elseif ('term_id'== $orderby || 'name'== $orderby) {
  5013 			WHERE $wpdb->posts.post_type = '%s'
  1616 					$theorderby = ' ORDER BY t.'.$orderby.' '.$order ;
  5014 			AND $wpdb->posts.ID NOT IN
       
  5015 			( SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '%s' )
       
  5016 			ORDER BY $wpdb->posts.ID ASC", XDMSG, $this->msglang_meta );
       
  5017 		$listposts = $wpdb->get_results($query, ARRAY_A);
       
  5018 		// test if no postmeta lang
       
  5019 		$i = 0;
       
  5020 		if ( $listposts ) {
       
  5021 			foreach ( $listposts as $onepost ) { 
       
  5022 				if ( 'msgid' == get_post_meta ( $onepost['ID'], $this->msgtype_meta, true ) ) {
       
  5023 					// update
       
  5024 					update_post_meta ( $onepost['ID'], $this->msglang_meta, array()  );
       
  5025 					++$i;
  1617 				}
  5026 				}
  1618 			}
  5027 			}
  1619 			
  5028 		
  1620 			if ( !empty($name__like) )
  5029 		}
  1621 			$where .= " AND t.name LIKE '{$name__like}%'";
  5030 		if ( defined ( "WP_DEBUG" ) && WP_DEBUG == true ) error_log (  'XD MSG - Updated 2.0->2.1 '.count($i) ) ;
  1622 		
  5031 	}
  1623 			if ( '' != $parent ) {
  5032 } /* end of class */
  1624 				$parent = (int) $parent;
  5033 
  1625 				$where .= " AND tt2.parent = '$parent'";
  5034 
  1626 			}
  5035 /**
  1627 		
  5036  *  filter wp_upload_dir (/wp-includes/functions.php)
  1628 			if ( $hide_empty && !$hierarchical )
  5037  *
  1629 				$where .= ' AND tt2.count > 0'; 
  5038  * @since 1.0.5
  1630 			 
  5039  */
  1631 			if ( !empty($number) && '' == $parent ) {
  5040  function xili_upload_dir() {
  1632 				if( $offset )
  5041  	add_filter ( 'upload_dir', 'xili_change_upload_subdir');
  1633 					$limit = ' LIMIT ' . $offset . ',' . $number;
  5042  	$uploads= wp_upload_dir();
  1634 				else
  5043  	remove_filter ('upload_dir','xili_change_upload_subdir');
  1635 					$limit = ' LIMIT ' . $number;
  5044  	return $uploads;
  1636 		
  5045  }
  1637 			} else {
  5046  function xili_change_upload_subdir ($pre_uploads = array()) {
  1638 				$limit = '';
  5047  	$pre_uploads['path'] = $pre_uploads['basedir']."/languages"; /* normally easy to create this subfolder */
  1639 			}
  5048  	return $pre_uploads;
  1640 		
  5049  }
  1641 			if ( !empty($search) ) {
       
  1642 				$search = like_escape($search);
       
  1643 				$where .= " AND (t.name LIKE '%$search%')";
       
  1644 			}
       
  1645 		
       
  1646 		} else { 
       
  1647 			 
       
  1648 			if ($order == 'ASC' || $order == 'DESC') $theorderby = ' ORDER BY tr.term_order '.$order ;
       
  1649 		}	
       
  1650 		$query = "SELECT t.*, tt2.term_taxonomy_id, tt2.description,tt2.parent, tt2.count, tt2.taxonomy, tr.term_order FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN $wpdb->terms AS t ON t.term_id = tr.object_id INNER JOIN $wpdb->term_taxonomy AS tt2 ON tt2.term_id = tr.object_id WHERE tt.taxonomy IN ('".$taxonomy."') AND tt2.taxonomy = '".$taxonomy_child."' AND tt.term_id IN (".$group_ids.") ".$where.$theorderby.$limit;
       
  1651 		 //echo $query;
       
  1652 		$listterms = $wpdb->get_results($query);
       
  1653 		if (!$listterms)
       
  1654 				return array();
       
  1655 		return $listterms;
       
  1656 	}
       
  1657 }
       
  1658 
  5050 
  1659 /**
  5051 /**
  1660  * instantiation when xili-language is loaded
  5052  * instantiation when xili-language is loaded
  1661  */
  5053  */
  1662 function dictionary_start () {
  5054 function xili_dictionary_start () {
  1663 	global $wp_version;
  5055 	global $wp_version, $xili_dictionary ; // for barmenu
  1664 	if ($wp_version >= '2.8') $xili_dictionary = new xili_dictionary(); /* instantiation php4 for last century servers replace by =& */ 
  5056 	if ( $wp_version >= '3.2' ) $xili_dictionary = new xili_dictionary(); /* instantiation php4 for last century servers replace by =& */ 
  1665 }
  5057 }
  1666 add_action('plugins_loaded','dictionary_start'); 
  5058 add_action( 'plugins_loaded', 'xili_dictionary_start', 20 ); // after xili-language and xili_tidy_tags
  1667 
  5059 
  1668 /* © xiligroup dev 091108 10:00 */
  5060 /* © xiligroup dev 20120922 */
  1669 
  5061 
  1670 ?>
  5062 ?>