diff -r f507feede89a -r 09a1c134465b web/wp-content/plugins/xili-dictionary/xili-dictionary.php --- a/web/wp-content/plugins/xili-dictionary/xili-dictionary.php Wed Dec 19 12:35:13 2012 -0800 +++ b/web/wp-content/plugins/xili-dictionary/xili-dictionary.php Wed Dec 19 17:46:52 2012 -0800 @@ -4,13 +4,14 @@ Plugin URI: http://dev.xiligroup.com/xili-dictionary/ 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 - Author: dev.xiligroup - MS -Version: 2.2.0 +Version: 2.3.0 Author URI: http://dev.xiligroup.com License: GPLv2 Text Domain: xili-dictionary Domain Path: /languages/ */ +# 2.3.0 - 121118 - add ajax functions for import and erase functions # 2.2.0 - 120922 - fixes issues with .mo and .po inserts - better messages and warning # 2.1.3 - 120728 - fixes # 2.1.2 - 120715 - list in msg edit - new query - new metabox - new pointers - ... @@ -34,7 +35,7 @@ # beta 0.9.3 - first published - 090131 MS -define('XILIDICTIONARY_VER','2.2.0'); +define('XILIDICTIONARY_VER','2.3.0'); include_once(ABSPATH . WPINC . '/pomo/po.php'); /* not included in wp-settings */ @@ -97,6 +98,9 @@ var $langs_group_id; /* group ID and Term Taxo ID */ var $langs_group_tt_id; + // temp mo/po object + + var $temp_po; public function xili_dictionary( $langsfolder = '/' ) { // ?? php4 @@ -148,8 +152,21 @@ /* admin */ add_action( 'admin_init', array(&$this,'admin_init') ); // 1.3.0 add_action( 'admin_init', array(&$this,'ext_style_init') ); // 2.1 + add_action( 'admin_init', array(&$this,'xd_erasing_init_settings') ); // 2.3 + add_action( 'admin_init', array(&$this,'xd_importing_init_settings') ); // 2.3 + add_action( 'admin_menu', array(&$this,'xili_add_dict_pages') ); + add_action( 'admin_menu', array(&$this,'admin_menus'), 10 ); // 2.3 + add_action( 'admin_menu', array(&$this,'admin_sub_menus_hide'), 11 ); + + // Attach to the admin head with our ajax requests cycle and css + add_action( 'admin_head', array( $this, 'admin_head' ) ); + + // Attach to the admin ajax request to process cycles + add_action( 'wp_ajax_xd_erasing_process', array( $this, 'erasing_process_callback' ) ); // 2.3 + add_action( 'wp_ajax_xd_importing_process', array( $this, 'importing_process_callback' ) ); // 2.3 + add_action( 'add_meta_boxes', array(&$this, 'add_custom_box_in_post_msg') ); // 2.1.2 add_action( 'init', array(&$this, 'xili_dictionary_register_taxonomies')); // and init @@ -183,6 +200,7 @@ add_filter( 'post_updated_messages', array(&$this, 'msg_post_messages')); add_action( 'before_delete_post', array(&$this, 'msgid_post_links_delete') ); + add_action( 'admin_print_styles-post.php', array(&$this, 'print_styles_xdmsg_edit') ); add_action( 'admin_print_styles-post-new.php', array(&$this, 'print_styles_xdmsg_edit') ); @@ -192,6 +210,8 @@ add_action( 'admin_print_styles-edit.php', array(&$this, 'print_styles_xdmsg_list') ); // list of msgs add_action( 'admin_print_styles-xdmsg_page_dictionary_page', array(&$this, 'print_styles_xdmsg_tool') ); + add_action( 'admin_print_styles-xdmsg_page_erase_dictionary_page', array(&$this, 'print_styles_new_ui') ); + add_action( 'admin_print_styles-xdmsg_page_import_dictionary_page', array(&$this, 'print_styles_new_ui') ); add_action( 'add_meta_boxes_' . XDMSG, array(&$this, 'msg_update_action')); // to locally update files from editing... @@ -433,6 +453,22 @@ if ( $this->exists_style_ext && $this->xili_settings['external_xd_style'] == "on" ) wp_enqueue_style( 'xili_dictionary_stylesheet' ); } + /** + * add styles in new screens (import / erase) + * + */ + function print_styles_new_ui ( ) { + + echo ''."\n"; + echo ''."\n"; + + } + /** * style for new dashboard @@ -486,7 +522,8 @@ $term = 'en_US'; $args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'en_us'); $theids = $this->safe_lang_term_creation ( $term, $args ); - wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); + if ( !is_wp_error($theids) ) + wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); /* default values */ if ( ''!= WPLANG && ( strlen( WPLANG )==5 || strlen( WPLANG ) == 2 ) ) : // for japanese @@ -504,7 +541,8 @@ $args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug); $theids = $this->safe_lang_term_creation ( $term, $args ) ; - wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); + if ( !is_wp_error($theids) ) + wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); } @@ -614,6 +652,8 @@ if ( $res != '' && is_array ( $thelangs ) ) { unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr'] ) ; + if ( isset ( $thelangs['msgstrlangs'][$target_lang] ) && $thelangs['msgstrlangs'][$target_lang] == array( ) ) unset ( $thelangs['msgstrlangs'][$target_lang] ); // 2.3 + if ( isset ( $thelangs['msgstrlangs'] ) && $thelangs['msgstrlangs'] == array( ) ) unset ( $thelangs['msgstrlangs'] ); // 2.3 update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta } } elseif ( false !== strpos( $type, 'msgstr_' ) && $target_lang != '' ) { @@ -624,8 +664,9 @@ $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); if ( $res != '' && is_array ( $thelangs ) ) { unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] ) ; - // delete childs or trash ?? - // ?? recursive + if ( isset ( $thelangs['msgstrlangs'][$target_lang] ) && $thelangs['msgstrlangs'][$target_lang] == array( ) ) unset ( $thelangs['msgstrlangs'][$target_lang] ); // 2.3 + if ( isset ( $thelangs['msgstrlangs'] ) && $thelangs['msgstrlangs'] == array( ) ) unset ( $thelangs['msgstrlangs'] ); // 2.3 + update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta } } else { @@ -859,7 +900,7 @@ $mo = $this->from_cpt_to_POMO ( $selectlang, 'mo', $extract_array ); } - if ( count ($mo->entries) > 0 ){ + if ( isset ( $mo ) && count ($mo->entries) > 0 ){ if ( false === $this->Save_MO_to_file ( $selectlang , $mo, $file ) ) { $this->msg_action_message = sprintf(''.__('Error with File %s !', 'xili-dictionary').' ('.$file.')', $local.$selectlang.'.mo'); @@ -1120,17 +1161,11 @@ return false; } - /** - * import po and mo in cpts series - * - * @since 2.0 - * @return - */ - function from_pomo_to_cpts ( $po, $curlang = 'en_US' ) { + // used by new ajax + + function pomo_entry_to_xdmsg ( $pomsgid, $pomsgstr, $curlang = 'en_US', $args = array('importing_po_comments'=> '', 'origin_theme' =>'' ) ) { $nblines = array( 0, 0); // id, str count - $this->importing_mode = true ; - foreach ( $po->entries as $pomsgid => $pomsgstr ) { - // test if msgid exists + // test if msgid exists $result = $this->msgid_exists ( $pomsgstr->singular, $pomsgstr->context ) ; if ( $result === false ) { @@ -1140,15 +1175,15 @@ $nblines[0]++ ; } else { $msgid_post_ID = $result[0]; - if ( $this->importing_po_comments != '' ) { - $this->insert_comments( $msgid_post_ID, $pomsgstr, $this->importing_po_comments ); + if ( $args['importing_po_comments'] != '' ) { + $this->insert_comments( $msgid_post_ID, $pomsgstr, $args['importing_po_comments'] ); } } // add origin taxonomy - if ( ''!= $this->origin_theme ) - wp_set_object_terms( $msgid_post_ID, $this->origin_theme, 'origin', true ); // true to append to existing + if ( ''!= $args['origin_theme'] ) + wp_set_object_terms( $msgid_post_ID, $args['origin_theme'], 'origin', true ); // true to append to existing if ( $pomsgstr->is_plural != null ) { // create msgid plural (child of msgid) @@ -1218,7 +1253,26 @@ $i++; } } + return $nblines; + } + + /** + * import po and mo in cpts series + * + * @since 2.0 + * @updated 2.3 pomo_entry_to_xdmsg outside + * @return + */ + function from_pomo_to_cpts ( $po, $curlang = 'en_US' ) { + $nblines = array( 0, 0); // id, str count + $this->importing_mode = true ; + foreach ( $po->entries as $pomsgid => $pomsgstr ) { + $lines = $this->pomo_entry_to_xdmsg ( $pomsgid, $pomsgstr, $curlang, array ( 'importing_po_comments'=>$this->importing_po_comments, 'origin_theme'=>$this->origin_theme ) ); // global value + + $nblines[0] += $lines[0]; + $nblines[1] += $lines[1]; + } $this->importing_mode = false ; return $nblines; @@ -1719,7 +1773,7 @@ } // redirect - //if ( $translated_post_ID > 0 && $this->xili_settings['creation_redirect'] == 'redirect') { + $url_redir = admin_url().'post.php?post='.$translated_post_ID.'&action=edit'; ?> @@ -1727,7 +1781,7 @@ - +
insert_one_cpt_and_meta ( __('XD say id to plural: ', 'xili-dictionary').$temp_post_msg_id->post_content , null, 'msgid_plural' , $msgid_id ); $res = get_post_meta ( $msgid_id, $this->msgchild_meta, false ); $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); + $url_redir = admin_url().'post.php?post='.$msgid_plural_post_ID.'&action=edit'; + //2.3 ?> +
+post_status !='auto-draft' && !isset ( $thelangs['msgstrlangs'] ) && !isset ( $thechilds['msgid']['plural'] ) ) { // not yet translated $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgid_plural', 'xd-plural' ) ; printf( __(' Create msgid_plural', 'xili-dictionary'), $nonce_url ); @@ -2251,7 +2314,7 @@ //$this->thehook = add_management_page(__('Xili Dictionary','xili-dictionary'), __('xili Dictionary','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings')); $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') ); - + add_action( "admin_head-".$this->thehook, array(&$this,'modify_menu_highlight' )); add_action('load-'.$this->thehook, array(&$this,'on_load_page')); add_action( 'admin_print_scripts-'.$this->thehook, array(&$this,'admin_enqueue_scripts') ); @@ -2272,9 +2335,10 @@ wp_enqueue_script('wp-lists'); wp_enqueue_script('postbox'); + add_meta_box('xili-dictionary-sidebox-style', __('XD style settings','xili-dictionary'), array(&$this,'on_sidebox_style_content'), $this->thehook , 'side', 'core'); add_meta_box('xili-dictionary-sidebox-message', __('Message','xili-dictionary'), array(&$this,'on_sidebox_message_content'), $this->thehook , 'side', 'core'); add_meta_box('xili-dictionary-sidebox-info', __('Info','xili-dictionary'), array(&$this,'on_sidebox_info_content'), $this->thehook , 'side', 'core'); - add_meta_box('xili-dictionary-sidebox-style', __('XD style settings','xili-dictionary'), array(&$this,'on_sidebox_style_content'), $this->thehook , 'side', 'core'); + } /** @@ -2429,9 +2493,10 @@ -

+

' . $this->xdmsg . '' ); ?>

@@ -2568,12 +2633,12 @@
+ get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); + ?> +
+ + +

+
+
+ false) ); + echo '
'; + if ( $listterms ) { + $checkline = __ ( 'Check Origin(s) to be erased', 'xili-dictionary' ).':
'; + $i = 0; + echo ''; + foreach ( $listterms as $onetheme) { + $checked = ( $onetheme->name == $cur_theme_name ) ? 'checked="checked"' : '' ; + $checkline .= ''; + $i++; + if ( ($i % 2) == 0 ) $checkline .= ''; + } + echo $checkline.'
 ' . $onetheme->name .'
'; + } + echo '
'; ?> +

+
+ + + + + + + + + + +

+ + + +
+ + + + + +
+ + + + + +

+ + + +

+ +
+
+
+ + + + + + caching_msgs_to_erase ( ); + + if ( $count_lines > 0 ) { + update_option( '_xd_erasing_step', $step + 1 ); + update_option( '_xd_erasing_start', 0 ); + update_option( '_xd_erasing_count_lines', $count_lines ); + $this->looping_output( sprintf( __('Lines found ! ( %2$s lines)', 'xili-dictionary' ), '', $count_lines ) ); + + } else { + delete_option( '_xd_erasing_step' ); + delete_option( '_xd_erasing_start' ); + delete_option( '_xd_erasing_count_lines' ); + delete_option( '_xd_deletion_type' ); + delete_option ( '_xd_cache_temp_array_IDs' ); + $this->looping_output( __( 'No msgs to erase', 'xili-dictionary' ), 'error' ); + + } + break; + // STEP 2. Loop + case 2 : + $count_lines = get_option( '_xd_erasing_count_lines', $max + 1 ); + //error_log ('---- count-lines='. $count_lines .', start='. $start ); + $back = $this->erasing_msgs( $start ); + if ( in_array( $back , array( 'no-list', 'loop-over', 'loop-full' ) ) ) { + update_option( '_xd_erasing_step', $step + 1 ); + update_option( '_xd_erasing_start', 0 ); + if ( empty( $start ) || $back == 'no-list' ) { + + if ( 'loop-full' == $back ) { + $this->looping_output( sprintf(__( 'No more msgs to erase (%s)', 'xili-dictionary' ), $back ) , 'loading' ); + } else { + $this->looping_output( sprintf(__( 'No msgs to erase (%s)', 'xili-dictionary' ), $back ) , 'error' ); + + } + } + + } else { + + update_option( '_xd_erasing_start', $max + 1 ); + + $count_lines = get_option( '_xd_erasing_count_lines', $max + 1 ); + $end = ( $count_lines > $max ) ? $max + 1 : $count_lines ; + + $this->looping_output( sprintf( __( 'Erasing msgs (%1$s - %2$s)', 'xili-dictionary' ), $min, $end ), 'loading' ); + + } + + break; + + + default: + $count_lines = get_option( '_xd_erasing_count_lines', $max + 1 ); + delete_option( '_xd_erasing_step' ); + delete_option( '_xd_erasing_start' ); + delete_option( '_xd_erasing_count_lines'); + delete_option( '_xd_deletion_type' ); + delete_option ( '_xd_cache_temp_array_IDs' ); + + $this->looping_output( sprintf( __( 'Erasing Complete (%1$s)', 'xili-dictionary' ), $count_lines ), 'success' ); + break; + + } + } + + private static function looping_output( $output = '', $type = '' ) { + + switch ( $type ) { + + case 'success': + $class = ' class="success"'; + break; + case 'error': + $class = ' class="error"'; + break; + default: + $class = ' class="loading"'; + break; + } + + // Get the last query + $before = ""; + $after = '

'; + //$query = get_option( '_xd_erasing_query' ); + + //if ( ! empty( $query ) ) + //$before = '

'; + + echo $before . $output . $after; + } + + private static function erasing_msgs ( $start ) { + global $xili_dictionary; + // $listdictiolines = $xili_dictionary->get_msgs_to_erase ( $start ); + $id_list = get_option ( '_xd_cache_temp_array_IDs' ); + if ( $id_list ) { //$listdictiolines + + + $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50; + + $only_local = ( isset ( $_POST['_xd_local'] ) ) ? true : false ; + + $selected_lang = ( isset ( $_POST['_xd_lang'] ) ) ? $_POST['_xd_lang'] : "" ; + + $deletion_type = get_option( '_xd_deletion_type' ); + + // loop + $count_lines = count( $id_list ); + //error_log ('type='. $deletion_type . ', count-lines='. $count_lines .', start='.$start); + $i = 0; + foreach ( $id_list as $one_id ) { + // to exit loop when only ids remain in loop + //if ( in_array( $deletion_type , array ( 'all_str', 'only_local' ) ) ) { + $i++; + if ( $i < $start ) continue; + if ( $i > ($start + $count) - 1 ) return 'loop'; + if ( $i > $count_lines ) return 'loop-over'; + //} + //error_log ('count='.$count . ' one_id='. $one_id . ', i='. $i ); + $res = get_post_meta ( $one_id, $xili_dictionary->msglang_meta, false ); + $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); + + + switch ( $deletion_type ) { + + case 'all': + wp_delete_post( $one_id, false ) ; + break; + + case 'only_local': // id and all str or all str + + if ( isset ( $thelangs['msgstrlangs'] ) ) { + foreach ( $thelangs['msgstrlangs'] as $curlang => $msgtr ) { + + $res = get_post_meta ( $one_id, $xili_dictionary->msgchild_meta, false ); + $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); + if ( isset ( $thechilds['msgid']['plural'] ) ) { + $msgstrs_arr = $xili_dictionary->get_cpt_msgstr( $one_id, $curlang, true ); + if ( $msgstrs_arr ) { + foreach ( $msgstrs_arr as $msgstrs ) { + if ( $selected_lang == "all-lang" ) + wp_delete_post( $msgstrs->ID, false ) ; + } + } + + } else { + + $msgstrs = $xili_dictionary->get_cpt_msgstr( $one_id, $curlang, false ); // affiner plural + + // delete only msgstr of $oneline->ID + + if ( $msgstrs != false && $selected_lang == "all-lang" ) { + wp_delete_post( $msgstrs->ID, false ) ; + } + } + } + } + // clean msgid + // msgid_post_links_delete + // delete msgid - if $selected_lang == "" + if ( $selected_lang == "" ) { + wp_delete_post( $one_id, false ) ; + } + break; + + case 'str_one_lang': + + $res = get_post_meta ( $one_id, $xili_dictionary->msgchild_meta, false ); + $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); + if ( isset ( $thechilds['msgid']['plural'] ) ) { + $msgstrs_arr = $xili_dictionary->get_cpt_msgstr( $one_id, $selected_lang, true ); + if ( $msgstrs_arr ) { + foreach ( $msgstrs_arr as $msgstrs ) { + wp_delete_post( $msgstrs->ID, false ) ; + } + } + + } else { + + // delete msgstr of this lang of $oneline->ID + $msgstrs = $xili_dictionary->get_cpt_msgstr( $one_id, $selected_lang, false ); + // clean msgid (inside delete_post) + + // delete str + if ( $msgstrs ) + wp_delete_post( $msgstrs->ID, false ) ; + } + break; + + case 'all_str': + + wp_delete_post( $one_id, false ) ; // id is cleaned by delete filter + + break; + } + } + return 'loop-full'; + } else { + return 'nolist'; + } + + } + + function caching_msgs_to_erase ( ) { + + $list = $this->get_msgs_to_erase ( 0 ) ; + + if ( $list ) { + $id_list = array(); + foreach ( $list as $one ) { + $id_list[] = $one->ID; + } + update_option( '_xd_cache_temp_array_IDs', $id_list ); + return count ( $list ); + } else { + return 0; + } + + + } + + + private static function get_msgs_to_erase ( $start ) { + global $xili_dictionary; + // sub-selection according msg origin (theme) + $origins = array(); + $listterms = get_terms( 'origin', array('hide_empty' => false) ); + foreach ( $listterms as $onetheme) { + if ( isset ( $_POST[ 'theme-'.$onetheme->term_id ] ) ) { + $origins[] = $onetheme->slug; + } + } + //error_log ( serialize ( $origins ) ); + $deletion_type = ''; + $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50; + + $only_local = ( isset ( $_POST['_xd_local'] ) ) ? true : false ; + + $selected_lang = ( isset ( $_POST['_xd_lang'] ) ) ? $_POST['_xd_lang'] : "" ; + + + // check origin checked + + if ( $selected_lang == "" && $only_local == false ) { + $query = array( + 'numberposts' => -1, 'offset' => 0, + 'category' => 0, 'orderby' => 'ID', + 'order' => 'ASC', 'include' => array(), + 'exclude' => array(), 'post_type' => XDMSG, + 'suppress_filters' => true + ); + $deletion_type = 'all'; + + } else if ( ( $selected_lang == "" || $selected_lang == "all-lang" ) && $only_local == true ) { + + $query = array( + 'numberposts' => -1, 'offset' => 0, + 'category' => 0, 'orderby' => 'ID', + 'order' => 'ASC', 'include' => array(), + 'exclude' => array(), 'post_type' => XDMSG, + 'suppress_filters' => true, + 'meta_query' => array( + 'relation' => 'AND', + array( + 'key' => $xili_dictionary->msgtype_meta, + 'value' => 'msgid', + 'compare' => '=' + ), + array( + 'key' => $xili_dictionary->msg_extracted_comments, + 'value' => $xili_dictionary->local_tag, + 'compare' => 'LIKE' + ) + ) + ); + $deletion_type = 'only_local'; + + } else if ( $selected_lang == "all-lang" && $only_local == false ) { + + $query = array( + 'numberposts' => -1, 'offset' => 0, + 'category' => 0, 'orderby' => 'ID', + 'order' => 'ASC', 'include' => array(), + 'exclude' => array(), 'post_type' => XDMSG, + 'suppress_filters' => true, + 'meta_query' => array( + array( + 'key' => $xili_dictionary->msgtype_meta, + 'value' => array( 'msgstr', 'msgstr_0', 'msgstr_1' ), + 'compare' => 'IN' + ) + ) + ); + + $deletion_type = 'all_str'; + + } else if ( $selected_lang != "" && $selected_lang != "all-lang" ) { + + + // only msgstr + $query = array( + 'numberposts' => -1, 'offset' => 0, + 'category' => 0, 'orderby' => 'ID', + 'order' => 'ASC', 'include' => array(), + 'exclude' => array(), 'post_type' => XDMSG, + 'suppress_filters' => true, + 'meta_query' => array( + 'relation' => 'AND', + array( + 'key' => $xili_dictionary->msgtype_meta, + 'value' => 'msgid', + 'compare' => '=' + ), + array( + 'key' => $xili_dictionary->msglang_meta, + 'value' => $selected_lang, + 'compare' => 'LIKE' + ) + ) + ); + + if ( $only_local ) { + + $query['meta_query'][] = array( + 'key' => $xili_dictionary->msg_extracted_comments, + 'value' => $xili_dictionary->local_tag, + 'compare' => 'LIKE' + ); + } + + + + $deletion_type = 'str_one_lang'; + } + + if ( $origins != array() ) { + + if ( count ( $origins ) == 1 ) { + + $array_tax = array( + 'taxonomy' => 'origin', + 'field' => 'slug', + 'terms' => $origins[0] + ); + + } else { + + $array_tax = array( + 'taxonomy' => 'origin', + 'field' => 'slug', + 'terms' => $origins, + 'operator' => 'IN' + ); + } + $query['tax_query'] = array( $array_tax ) ; + + } + + $listdictiolines = get_posts( $query ); + + if ( $listdictiolines ) { + update_option( '_xd_deletion_type', $deletion_type ); + return $listdictiolines; + } else { + return false; + } + } + + /**** importing new UI *****/ + // since 2.3 + + function xili_dictionary_import() { + ?> + +

+ + + + + +
+ + + + + + +

+ + + +

+ +
+
+
+ + +

+ + +

' . $extend . '' ) ; ?>

+ + +
+ + + +

+
+xililanguage_ms ) { +?> +
+ + + +

+
+ +
+ /> + +

+
+get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); + ?> +
+ + +

+
+
+ + +

+
+ + + + + + + caching_file( $type, $lang, $local_file, $pomofile, $multilocal ); + if ( false != $count_entries ) { + update_option( '_xd_importing_step', $step + 1 ); + update_option( '_xd_importing_start', 0 ); + update_option( '_xd_importing_count_entries', $count_entries ); + + $this->looping_output( sprintf( __('File %3$s%2$s.%1$s found ! (%4$s entries)', 'xili-dictionary' ), $type, $lang, $local_file2, $count_entries ) ); + } else { + delete_option( '_xd_importing_step' ); + delete_option( '_xd_importing_start' ); + delete_option( '_xd_cache_pomo_file' ); + delete_option( '_xd_importing_count_entries'); + if ( false === strpos( $lang , '_' ) && $type == 'po' ) { $type = 'pot'; } // special case + $this->looping_output( sprintf( __('Impossible to find file %3$s%2$s.%1$s (%4$s)', 'xili-dictionary' ), $type, $lang, $local_file2, $pomofile ), 'error' ); + } + break; + + // STEP 2. Loop + case 2 : + + if ( $this->importing_msgs( $start, $lang ) ) { + update_option( '_xd_importing_step', $step + 1 ); + update_option( '_xd_importing_start', 0 ); + if ( empty( $start ) ) { + + $this->looping_output( __( 'No msgs to import', 'xili-dictionary' ), 'error' ); + } + + } else { + update_option( '_xd_importing_start', $max + 1 ); + + $count_entries = get_option( '_xd_importing_count_entries', $max + 1 ); + $end = ( $count_entries > $max ) ? $max + 1 : $count_entries ; + $this->looping_output( sprintf( __( 'Importing msgs (%1$s - %2$s)', 'xili-dictionary' ), $min, $end ) ); + + } + break; + + default : + delete_option( '_xd_importing_step' ); + delete_option( '_xd_importing_start' ); + delete_option( '_xd_cache_pomo_file' ); + delete_option( '_xd_importing_count_entries'); + + $this->looping_output( __( 'Importation Complete', 'xili-dictionary' ), 'success' ); + + break; + + } + + } + + private static function caching_file( $type, $lang, $local_file = '', $pomofile = '', $multilocal = true ) { + global $xili_dictionary; // called by ajax + + // search file + $temp_po = $xili_dictionary->import_POMO ( $type, $lang, $local_file, $pomofile, $multilocal ); + if ( false !== $temp_po ) { + // cache file + update_option( '_xd_cache_pomo_file', $temp_po ); + + return count ( $temp_po->entries ) ; + } else { + return false; + } + } + + private static function importing_msgs( $start, $lang ) { + global $xili_dictionary; // called by ajax + + $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50; + $importing_po_comments = ( isset ( $_POST['_importing_po_comments'] ) ) ? $_POST['_importing_po_comments'] : '' ; + $origin_theme = $_POST['_origin_theme']; + //$temp_po = $xili_dictionary->pomo_import_PO ( $lang ); + + $temp_po = get_option( '_xd_cache_pomo_file', false ); + $count_entries = count( $temp_po->entries ); + if ( false !== $temp_po && ( $start < $count_entries ) ) { + $i = 0; + foreach ( $temp_po->entries as $pomsgid => $pomsgstr ) { + $i++; + if ( $i < $start ) continue; + if ( $i > ($start + $count) -1 ) break; + if ( $i > $count_entries ) break; + + $lines = $xili_dictionary->pomo_entry_to_xdmsg ( $pomsgid, $pomsgstr, $lang, array( 'importing_po_comments'=>$importing_po_comments, 'origin_theme'=>$origin_theme ) ); + + //error_log ( $i . '------------->' . $pomsgstr->singular .'---ID--'. $lines[0] . '---STR--' . $lines[1] ); + + } + + //error_log ('count='.count( $temp_po->entries ).' start='.$start); + return false; + } + return true; + } + + + + } /* end of class */