--- 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 '<!---- xd css ----->'."\n";
+ echo '<style type="text/css" media="screen">'."\n";
+ echo 'form#xd-looping-settings > p { width:600px; padding:10px 20px; 10px 0; font-size:110%; }'."\n";
+ echo '.sub-field {border:1px #ccc solid; width:600px; padding:10px 20px ; margin:5px 0;}'."\n";
+ echo '.link-back > a { border:1px #ccc solid; width:80px; padding:4px 10px ; border-radius: 3px; margin-right:4px;}'."\n";
+ echo '.xd-looping-updated{ width:870px !important; }'."\n";
+ echo '</style>'."\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('<span class="alert">'.__('Error with File %s !', 'xili-dictionary').'</span> ('.$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 @@
<!--
window.location= <?php echo "'" . $url_redir . "'"; ?>;
//-->
- </script>
+ </script><br />
<?php
//}
}
@@ -1736,6 +1790,14 @@
$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 );
$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 ?>
+ <script type="text/javascript">
+ <!--
+ window.location= <?php echo "'" . $url_redir . "'"; ?>;
+ //-->
+ </script><br />
+<?php
} elseif ( $type == 'msgid' && isset ($_GET['msgaction']) && $_GET['msgaction'] == 'setlocal' ) {
check_admin_referer( 'xd-setlocal' );
@@ -1778,7 +1840,8 @@
} else {
- if ( !isset ( $thelangs['msgstrlangs'] ) && !isset ( $thechilds['msgid']['plural'] ) ) { // not yet translated
+ //2.3
+ if ( $post->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( __(' <a href="%s" >Create msgid_plural</a>', '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 @@
<?php
}
- function get_theme_name () {
+ function get_theme_name ( $child_of = true ) {
if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0
- $theme_name = get_option("stylesheet").' '.__('child of','xili-dictionary').' '.get_option("template");
+ $theme_name = get_option("stylesheet");
+ if ( $child_of ) $theme_name .= ' '.__('child of','xili-dictionary').' '.get_option("template");
} else {
$theme_name = get_option("template");
}
@@ -2456,7 +2521,7 @@
}
}
?>
-<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><?php printf ( __('xili-dictionary is a plugin (compatible with xili-language) to build a multilingual dictionary saved in the post tables of WordPress as custom post type (%s). With this dictionary, it is possible to create and update .mo file in the current theme folder. And more...','xili-dictionary'), '<em>' . $this->xdmsg . '</em>' ); ?>
</p>
<fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;">
<legend><?php echo __("Theme's informations:",'xili-dictionary').' ('. $theme_name .')'; ?></legend>
@@ -2568,12 +2633,12 @@
<div class="dialoglang">
<label for="language_file">
<select name="language_file" ><?php
- $extend = WPLANG;
+ $default_lang = ( defined ('WPLANG') ) ? WPLANG : '' ;
$listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' );//get_terms(TAXONAME, array('hide_empty' => false));
if ( $listlanguages ) {
foreach ($listlanguages as $reflanguage) {
echo '<option value="'.$reflanguage->name.'"';
- if ($extend == $reflanguage->name) {
+ if ( $default_lang == $reflanguage->name ) {
echo ' selected="selected"';
}
echo ">".__($reflanguage->description,'xili-dictionary').'</option>';
@@ -2726,11 +2791,12 @@
*/
function on_normal_3_content( $data ) {
extract( $data );
+ $default_lang_get = ( defined ('WPLANG') ) ? '&' . QUETAG . '=' . WPLANG : '' ;
?>
<h4 id="manage_file"><?php _e('The files','xili-dictionary') ;?></h4>
<a class="action-button blue-button" href="<?php echo $this->xd_settings_page.'&action=export'; ?>" title="<?php _e('Create or Update mo file in current theme folder','xili-dictionary') ?>"><?php _e('Export mo file','xili-dictionary') ?></a>
- <br /><?php _e('Import po/mo file','xili-dictionary') ?>:<a class="small-action-button" href="<?php echo $this->xd_settings_page.'&action=import'; ?>" title="<?php _e('Import an existing .po file from current theme folder','xili-dictionary') ?>">PO</a>
-<a class="small-action-button" href="<?php echo $this->xd_settings_page.'&action=importmo'; ?>" title="<?php _e('Import an existing .mo file from current theme folder','xili-dictionary') ?>">MO</a><br />
+ <br /><?php _e('Import po/mo file','xili-dictionary') ?>:<a class="small-action-button" href="edit.php?post_type=<?php echo XDMSG ?>&page=import_dictionary_page&extend=po<?php echo$default_lang_get ?>" title="<?php _e('Import an existing .po file from current theme folder','xili-dictionary') ?>">PO</a>
+<a class="small-action-button" href="edit.php?post_type=<?php echo XDMSG ?>&page=import_dictionary_page&extend=mo<?php echo$default_lang_get ?>" title="<?php _e('Import an existing .mo file from current theme folder','xili-dictionary') ?>">MO</a><br />
<br /><a class="action-button grey-button" href="<?php echo $this->xd_settings_page.'&action=exportpo'; ?>" title="<?php _e('Create or Update po file in current theme folder','xili-dictionary') ?>"><?php _e('Export po file','xili-dictionary') ?></a>
<h4 id="manage_categories"><?php _e('The taxonomies','xili-dictionary') ;?></h4>
@@ -2742,8 +2808,9 @@
} ?>
<a class="action-button blue-button" href="<?php echo $this->xd_settings_page.'&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>
- <h4 id="manage_dictionary"><?php _e('Dictionary','xili-dictionary') ;?></h4>
- <a class="action-button grey-button" href="?post_type=xdmsg&action=erasedictionary&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>
+<h4 id="manage_dictionary"><?php _e('Dictionary in database','xili-dictionary') ;?></h4>
+ <a class="action-button grey-button" href="edit.php?post_type=<?php echo XDMSG ?>&page=erase_dictionary_page" title="<?php _e('Erase selected terms of dictionary ! (but not .mo or .po files)','xili-dictionary') ?>"><?php _e('Erase (selection of) terms','xili-dictionary') ?></a>
+ <a class="action-button grey-button" href="<?php echo $this->xd_settings_page.'&action=importcurthemeterms'; ?>" title="<?php _e('Import terms for current theme files','xili-dictionary') ?>"><?php _e('Import terms from source files','xili-dictionary') ?></a>
<?php // erase and import theme
}
@@ -3082,7 +3149,7 @@
$mo = $this->from_cpt_to_POMO ( $selectlang, 'mo', $extract_array );
}
- if ( count ($mo->entries) > 0 ){ // 2.2
+ if ( isset ( $mo ) && count ($mo->entries) > 0 ){ // 2.2
if ( false === $this->Save_MO_to_file ($selectlang , $mo, $file ) ) {
$message .= $file.' '.sprintf(__('error during exporting in %2s %1s.mo file.','xili-dictionary'), $selectlang, $local);
} else {
@@ -3327,12 +3394,12 @@
case 'importcurthemeterms';
$actiontype = "importingcurthemeterms";
- $formtitle = __('Import all terms from current theme','xili-dictionary');
- $formhow = __('To import terms of the current theme, click below.','xili-dictionary');
+ $formtitle = __('Import all terms from current theme source','xili-dictionary');
+ $formhow = __('<em>Only use this possibility if no po, pot or mo file are provided by the theme maker. (this importer is experimental and only detect the I10n functions</em> __( , _e( , _x( , _ex( , _n( and _nx( ). <br /> To import terms of the current theme source files, click below.','xili-dictionary');
$submit_text = __('Import all terms »','xili-dictionary');
$this->tempoutput = '<strong>'.__('List of scanned files:','xili-dictionary').'</strong><br />';
- $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),2);
+ $themeterms = $this->scan_import_theme_terms( array(&$this,'build_scanned_files'), 2 );
$formhow = $this->tempoutput.'<br /><br /><strong>'.$formhow .'</strong>';
break;
@@ -3340,17 +3407,19 @@
case 'importingcurthemeterms'; // temporary inactive 2.1
$actiontype = "add";
$message .= ' '.__('All terms imported !','xili-dictionary'); $msg = 5 ;
- $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),0);
- if (is_array($themeterms)) {
- //$nbterms = $this->xili_importthemeterms_in_tables($themeterms);
+ $themeterms = $this->scan_import_theme_terms( array(&$this,'build_scanned_files'), 0 );
+ if ( is_array( $themeterms ) && $themeterms != array() ) {
+ $nbterms = $this->import_theme_terms ( $themeterms );
$message .= __('terms = ','xili-dictionary').$nbterms;
} else {
$message .= ' '.$readfile.__('theme’s terms pbs!','xili-dictionary');
}
- break;
+ break;
+
case 'reset';
$actiontype = "add";
- break;
+ break;
+
default:
$actiontype = "add";
$message .= ' '.__('Find below the list of terms.','xili-dictionary');
@@ -3373,7 +3442,7 @@
$themessages[2] = __('A term was updated.','xili-dictionary');
$themessages[3] = __('A term was deleted.','xili-dictionary');
$themessages[4] = __('terms imported from WP: ','xili-dictionary') . $message;
- $themessages[5] = __('All terms imported !','xili-dictionary');
+ $themessages[5] = __('All terms imported !','xili-dictionary') . '('.$message.')';
$themessages[6] = 'beta testing log: '.$message ;
$themessages[7] = __('All terms erased !','xili-dictionary');
$themessages[8] = __('Error when adding !','xili-dictionary');
@@ -3820,10 +3889,12 @@
$t = ( $lang == $theme_name ) ? 't': ''; /* from UI to select .pot */
}
+ $langfolder = $this->get_langfolder(); // 2.3
+
if ( $local == false ) {
- $pofile = $this->get_template_directory.$this->langfolder.$lang.'.po'.$t;
+ $pofile = $this->get_template_directory.$langfolder.$lang.'.po'.$t;
} else {
- $pofile = $this->get_template_directory.$this->langfolder.'local-'.$lang.'.po'; // fixed 2.1.1
+ $pofile = $this->get_template_directory.$langfolder.'local-'.$lang.'.po'; // fixed 2.1.1
}
if ( file_exists( $pofile ) ) {
@@ -3837,6 +3908,76 @@
}
}
+ function get_langfolder() {
+ $xili_settings = get_option('xili_dictionary_settings');
+ $langfolderset = $xili_settings['langs_folder'];
+ $full_folder = ( $langfolderset !='' ) ? $langfolderset.'/' : '/';
+ return $full_folder ;
+ }
+
+ /**
+ * Import POMO file in respective class
+ *
+ *
+ * @since 2.3
+ */
+ function import_POMO ( $extend = 'po', $lang = 'en_US', $local = '' , $pomofile = '', $multilocal = true ) {
+ if ( in_array ( $extend, array ( 'po', 'mo') ) ) {
+
+ if ( $extend == 'po' ) {
+ $pomo = new PO();
+
+ if ( function_exists('the_theme_domain') ) { // xili-language detect it
+ if ( $lang == the_theme_domain() ) $extend = 'pot';
+ } else {
+ if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0
+ $theme_name = get_option("stylesheet");
+ } else {
+ $theme_name = get_option("template");
+ }
+ if ( $lang == $theme_name ) $extend = 'pot' ; /* from UI to select .pot */
+ }
+
+ } else {
+ $pomo = new MO();
+ }
+ $path = "";
+ $langfolder = $this->get_langfolder();
+ if ( is_multisite() && $multilocal ) {
+ if ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) {
+ $path = $uploads['basedir']."/languages/";
+ }
+ } else {
+ $path = $this->get_template_directory . $langfolder;
+ }
+ if ( $pomofile == "" && $local != '' ) {
+
+ $pomofile = $path . $local . '-' . $lang. '.' . $extend ;
+
+ } else if ( '' == $pomofile ) {
+
+ $pomofile = $path . $lang . '.' . $extend ;
+
+ }
+
+ if ( file_exists( $pomofile ) ) {
+ if ( !$pomo->import_from_file( $pomofile ) ) {
+ return false;
+ } else {
+ return $pomo;
+ }
+ } else {
+ return false;
+ }
+
+
+ } else {
+ return false;
+ }
+
+ }
+
+
/**
* Import MO file in class PO
*
@@ -4694,6 +4835,43 @@
$this->importing_mode = false ;
return $nbnames;
}
+
+ function import_theme_terms ( $id_terms ) {
+ $count = 0;
+ if ( function_exists('the_theme_domain') ) {// in new xili-language
+ $theme = the_theme_domain() ;
+ } else {
+ $theme = $this->get_theme_name(false) ;
+ }
+
+ foreach ( $id_terms as $one_term ) {
+ $context = ( isset($one_term['ctxt'] ) ) ? $one_term['ctxt'] : null ;
+ $t_entry = array();
+ $t_entry['extracted_comments'] = sprintf ( 'From theme %s', $theme ) ;
+ $entry = (object) $t_entry ;
+ if ( isset( $one_term['plural'] ) ) {
+ $result = $this->msgid_exists ( $one_term['msgid'], $context ) ;
+ if ( $result === false ) {
+ $msgid_post_ID = $this->insert_one_cpt_and_meta( $one_term['msgid'], $context, 'msgid', 0, $entry ) ;
+ $count++;
+ }
+ $result = $this->msgid_exists ( $one_term['plural'], $context ) ;
+ if ( $result === false ) {
+ $msgid_plural_post_ID = $this->insert_one_cpt_and_meta( $one_term['plural'], $context, 'msgid_plural', $msgid_post_ID, $entry ) ;
+ $count++;
+ }
+
+
+ } else {
+ $result = $this->msgid_exists ( $one_term['msgid'] ) ;
+ if ( $result === false ) {
+ $msgid_post_ID = $this->insert_one_cpt_and_meta( $one_term['msgid'], $context, 'msgid', 0, $entry ) ;
+ $count++;
+ }
+ }
+ }
+ return $count;
+ }
/**
* Scan terms in themes files
@@ -4726,27 +4904,94 @@
$lines = @file( $path.'/'.$themefile);
$t=0;
foreach ($lines as $line) {
- $i = preg_match_all("/_[_e]\('(.*)', ?'/Ui", $line, $matches,PREG_PATTERN_ORDER);
+
+ $i = preg_match_all("/_[_e]\(( *)['\"](.*)['\"],( *)['\"]/Ui", $line, $matches, PREG_PATTERN_ORDER ); //' only single //2.3
if ($i > 0) {
- $resultterms = array_merge ($resultterms, $matches[1]);
+ $line_terms = array();
+ foreach ( $matches[2] as $one_match ) {
+ $line_terms[] = array ( 'msgid' => $one_match );
+ }
+
+ $resultterms = array_merge ( $resultterms, $line_terms);
+ $t += $i;
+ }
+ // single context
+ $i = preg_match_all("/_(e*)x\(( *)['\"](.*)['\"],( *)['\"](.*)['\"]/Ui", $line, $matches, PREG_PATTERN_ORDER ); //'' only single //2.3
+ if ($i > 0) {
+ $line_terms = array();
+ foreach ( $matches[3] as $key => $one_match ) {
+ $line_terms[] = array ( 'msgid' => $one_match, 'ctxt' => $matches[5][$key] );
+ //error_log ( '---xxxx---'. $matches[5][$key] ) ;
+ }
+
+ $resultterms = array_merge ( $resultterms, $line_terms);
$t += $i;
}
+
+ // plural function _n( $single, $plural, $number, $domain = 'default' )
+ $i = preg_match_all("/_n\(( *)['\"](.*)['\"],( *)['\"](.*)['\"]/Ui", $line, $matches, PREG_PATTERN_ORDER ); //'' only single //2.3
+ if ($i > 0) {
+ $line_terms = array();
+ foreach ( $matches[2] as $key => $one_match ) {
+ $line_terms[] = array ( 'msgid' => $one_match, 'plural' => $matches[4][$key] );
+ //error_log ( '---nnn---'. $matches[4][$key] ) ;
+ }
+
+ $resultterms = array_merge ( $resultterms, $line_terms);
+ $t += $i;
+ }
+
+ // plural context function _nx($single, $plural, $number, $context, $domain = 'default')
+ $i = preg_match_all("/_nx\(( *)['\"](.*)['\"],( *)['\"](.*)['\"],(.*),( *)['\"](.*)['\"]/Ui", $line, $matches, PREG_PATTERN_ORDER ); //'' only single //2.3
+ if ($i > 0) {
+ $line_terms = array();
+ foreach ( $matches[2] as $key => $one_match ) {
+ $line_terms[] = array ( 'msgid' => $one_match, 'plural' => $matches[4][$key], 'ctxt' => $matches[7][$key] );
+ //error_log ( '---nnn'.$matches[4][$key].'xxx---'. $matches[7][$key] ) ;
+ }
+
+ $resultterms = array_merge ( $resultterms, $line_terms);
+ $t += $i;
+ }
+
+
}
if ($display >= 1)
call_user_func($callback, $themefile, $t);
}
}
- if ($display == 2)
- call_user_func($callback, $themefile, $t, $resultterms);
+
+ $result_terms = ( $resultterms != array() ) ? $this->super_unique($resultterms) : array() ;
+ if ( $display == 2 )
+ call_user_func($callback, $themefile, $t, $result_terms);
- return $resultterms;
+ return $result_terms;
}
- function build_scanned_files ($themefile, $t, $resultterms = array()) {
- if ($resultterms == array()) {
+
+ /* in comment http://fr2.php.net/manual/en/function.array-unique.php */
+ function super_unique($array) {
+ $result = array_map("unserialize", array_unique(array_map("serialize", $array)));
+
+ foreach ($result as $key => $value) {
+ if ( is_array($value) )
+ {
+ $result[$key] = $this->super_unique($value);
+ }
+ }
+
+ return $result;
+ }
+
+ function build_scanned_files ( $themefile, $t, $resultterms = array() ) {
+ if ( $resultterms == array() ) {
$this->tempoutput .= "- ".$themefile." (".$t.") ";
} else {
$this->tempoutput .= "<br /><strong>".__('List of found terms','xili-dictionary').": </strong><br />";
- $this->tempoutput .= implode (', ',$resultterms);
+ $resultterms_msgid = array();
+ foreach ( $resultterms as $resultterm ) {
+ $resultterms_msgid[] = htmlspecialchars($resultterm['msgid']);
+ }
+ $this->tempoutput .= implode ( ', ', $resultterms_msgid );
}
}
@@ -5029,6 +5274,1136 @@
}
if ( defined ( "WP_DEBUG" ) && WP_DEBUG == true ) error_log ( 'XD MSG - Updated 2.0->2.1 '.count($i) ) ;
}
+
+ /****************** NEW ADMIN UI *******************/
+ /** since 2.3 **/
+
+ function admin_menus() {
+
+ $hooks = array();
+
+ $hooks[] = add_submenu_page('edit.php?post_type='.XDMSG,
+ __( 'Erasing', 'xili-dictionary' ),
+ __( 'Erase', 'xili-dictionary' ),
+ 'import',
+ 'erase_dictionary_page', array(&$this,'xili_dictionary_erase')
+ );
+ $hooks[] = add_submenu_page('edit.php?post_type='.XDMSG,
+ __( 'Importing files', 'xili-dictionary' ),
+ __( 'Import', 'xili-dictionary' ),
+ 'import',
+ 'import_dictionary_page', array(&$this,'xili_dictionary_import')
+ );
+
+ // Fudge the highlighted subnav item when on a XD admin page
+ foreach( $hooks as $hook ) {
+ add_action( "admin_head-$hook", array(&$this,'modify_menu_highlight' ));
+ }
+
+ }
+ function admin_sub_menus_hide () {
+
+ remove_submenu_page( 'edit.php?post_type='.XDMSG, 'erase_dictionary_page' );
+ remove_submenu_page( 'edit.php?post_type='.XDMSG, 'import_dictionary_page' );
+
+
+ }
+
+ function modify_menu_highlight() {
+ global $plugin_page, $submenu_file;
+
+ // This tweaks the Tools subnav menu to only show one XD menu item
+ if ( in_array( $plugin_page, array( 'erase_dictionary_page', 'import_dictionary_page' ) ) )
+ $submenu_file = 'dictionary_page';
+ }
+
+ /**
+ * Main settings section description for the settings page
+ *
+ * @since
+ */
+ function xd_erasing_setting_callback_main_section() {
+?>
+
+ <p><?php _e( "Here it now possible to erase your dictionary (here in WP database) after creating the .mo files (and saving the .po files which is readable with any text editor). <strong>This erasing process don't delete the .mo or .po files.</strong>", 'xili-dictionary' ); ?></p>
+
+ <?php
+ }
+
+ function xd_sub_selection__setting_callback_row() {
+ ?>
+ <div class="sub-field">
+ <input id="_xd_local" name="_xd_local" type="checkbox" id="_xd_local" value="local" <?php checked( ( 'local' == 'local' ) ); ?> />
+ <label for="_xd_local"><?php _e( 'Locale msgs only', 'xili-dictionary' ); ?></label>
+ <p class="description"><?php _e( 'Erase only locale msgs (as saved in local-xx_YY files)', 'xili-dictionary' ); ?></p>
+ </div>
+ <?php
+
+ $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
+ ?>
+ <div class="sub-field">
+ <label for="_xd_lang"><?php _e( 'Terms (msgid / msgstr) to erase', 'xili-dictionary' ); ?>: </label>
+ <select name="_xd_lang" id="_xd_lang" class='postform'>
+ <option value=""> <?php _e('Original (msgid) and translations or Select language...','xili-dictionary') ?> </option>
+ <option value="all-lang"> <?php _e('Translations (msgstr) in all languages','xili-dictionary') ?> </option>
+ <?php
+ foreach ($listlanguages as $language) {
+ $selected = ( isset ( $_GET[QUETAG] ) && $language->name == $_GET[QUETAG] ) ? "selected=selected" : "" ;
+ echo '<option value="'.$language->name.'" '.$selected.' >'. sprintf(__('Translations (msgstr) in %s','xili-dictionary'), __($language->description, 'xili-dictionary')).'</option>';
+ }
+
+ ?>
+ </select>
+ <p class="description"><?php _e( 'Language of the translated terms to be erased. Without selection, Original (msgid) AND translation (msgstr) will both be erased.', 'xili-dictionary' ); ?></p>
+ </div>
+ <div class="sub-field">
+ <?php
+
+ if ( is_child_theme() ) {
+ $cur_theme_name = get_option("stylesheet");
+ } else {
+ $cur_theme_name = get_option("template");
+ }
+ $listterms = get_terms( 'origin', array('hide_empty' => false) );
+ echo '<div class="dialogorigin">';
+ if ( $listterms ) {
+ $checkline = __ ( 'Check Origin(s) to be erased', 'xili-dictionary' ).':<br />';
+ $i = 0;
+ echo '<table class="checktheme" ><tr>';
+ foreach ( $listterms as $onetheme) {
+ $checked = ( $onetheme->name == $cur_theme_name ) ? 'checked="checked"' : '' ;
+ $checkline .= '<td><input type="checkbox" '. $checked .' id="theme-'.$onetheme->term_id.'" name="theme-'.$onetheme->term_id.'" value="'.$onetheme->slug.'" /> ' . $onetheme->name .'</td>';
+ $i++;
+ if ( ($i % 2) == 0 ) $checkline .= '</tr><tr>';
+ }
+ echo $checkline.'</tr></table>';
+ }
+ echo '</div>'; ?>
+ <p class="description"><?php _e( 'Origins of the msgs to be erased. Without selection, msg without origin will be erased', 'xili-dictionary' ); ?></p>
+ </div>
+
+ <?php }
+
+ function xd_erasing_setting_callback_row() {
+ ?>
+
+ <input name="_xd_looping_rows" type="text" id="_xd_looping_rows" value="50" class="small-text" />
+ <label for="_xd_looping_rows"><?php _e( 'Number of entries in one step', 'xili-dictionary' ); ?></label>
+
+ <?php
+ }
+
+ /**
+ * Edit Delay Time setting field
+ *
+ * @since
+ */
+ function xd_erasing_setting_callback_delay_time() {
+?>
+
+ <input name="_xd_looping_delay_time" type="text" id="_xd_looping_delay_time" value=".5" class="small-text" />
+ <label for="_xd_looping_delay_time"><?php _e( 'second(s) delay between each group of rows', 'xili-dictionary' ); ?></label>
+ <p class="description"><?php _e( 'Keep this high to prevent too-many-connection issues.', 'xili-dictionary' ); ?></p>
+
+<?php
+}
+
+ function xd_erasing_init_settings () {
+ add_settings_section( 'xd_erasing_main', __( 'Erasing the dictionary', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_main_section'), 'xd_erasing' );
+
+ // erasing sub-selections
+ add_settings_field( '_xd_sub_selection', __( 'What to erase ?', 'xili-dictionary' ), array(&$this,'xd_sub_selection__setting_callback_row'), 'xd_erasing', 'xd_erasing_main' );
+ register_setting( 'xd_erasing_main', '_xd_sub_selection', '_xd_sub_selection_define' );
+
+ // ajax section
+ add_settings_section( 'xd_erasing_tech', __( 'Technical settings', 'xili-dictionary' ), array(&$this,'xd_setting_callback_tech_section'), 'xd_erasing' );
+
+ // erasing rows step
+ add_settings_field( '_xd_looping_rows', __( 'Entries step', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_row'), 'xd_erasing', 'xd_erasing_tech' );
+ register_setting( 'xd_erasing_tech', '_xd_looping_rows', 'sanitize_title' );
+
+ // Delay Time
+ add_settings_field( '_xd_looping_delay_time', __( 'Delay Time', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_delay_time'), 'xd_erasing', 'xd_erasing_tech' );
+ register_setting ( 'xd_erasing_tech', '_xd_looping_delay_time', 'intval' );
+
+
+ }
+
+ function xili_dictionary_erase() {
+ ?>
+
+ <div class="wrap">
+
+ <?php screen_icon( 'tools' ); ?>
+
+ <h2 class="nav-tab-wrapper"><?php _e( 'Erasing Dictionary lines', 'xili-dictionary' ); ?></h2>
+
+ <form action="#" method="post" id="xd-looping-settings">
+
+ <?php settings_fields( 'xd_erasing' ); delete_option( '_xd_erasing_step'); // echo get_option( '_xd_erasing_step', 1 ); ?>
+
+ <?php do_settings_sections( 'xd_erasing' ); ?>
+ <h4 class="link-back"><?php printf(__('<a href="%s">Back</a> to the list of msgs and tools','xili-dictionary'), admin_url() . 'edit.php?post_type='.XDMSG.'&page=dictionary_page' ); ?></h4>
+ <p class="submit">
+ <input type="button" name="submit" class="button-primary" id="xd-looping-start" value="<?php _e( 'Start erasing', 'xili-dictionary' ); ?>" onclick="xd_erasing_start()" />
+ <input type="button" name="submit" class="button-primary" id="xd-looping-stop" value="<?php _e( 'Stop', 'xili-dictionary' ); ?>" onclick="xd_looping_stop()" />
+ <img id="xd-looping-progress" src="">
+ </p>
+
+ <div class="xd-looping-updated" id="xd-looping-message"></div>
+ </form>
+ </div>
+
+ <?php
+ }
+
+ function admin_head() {
+
+ ?>
+ <script language="javascript">
+
+ var xd_looping_is_running = false;
+ var xd_looping_run_timer;
+ var xd_looping_delay_time = 0;
+
+ function xd_importing_grab_data() {
+ var values = {};
+ jQuery.each(jQuery('#xd-looping-settings').serializeArray(), function(i, field) {
+ values[field.name] = field.value;
+ });
+
+ if( values['_xd_looping_restart'] ) {
+ jQuery('#_xd_looping_restart').removeAttr("checked");
+ }
+
+ if( values['_xd_looping_delay_time'] ) {
+ xd_looping_delay_time = values['_xd_looping_delay_time'] * 1000;
+ }
+
+ values['action'] = 'xd_importing_process';
+ values['_ajax_nonce'] = '<?php echo wp_create_nonce( 'xd_importing_process' ); ?>';
+
+ return values;
+ }
+
+ function xd_importing_start() {
+ if( false == xd_looping_is_running ) {
+ xd_looping_is_running = true;
+ jQuery('#xd-looping-start').hide();
+ jQuery('#xd-looping-stop').show();
+ jQuery('#xd-looping-progress').show();
+ xd_looping_log( '<p class="loading"><?php echo esc_js(__( 'Starting Importing', 'xili-dictionary' )); ?></p>' );
+ xd_importing_run();
+ }
+ }
+
+ function xd_importing_run() {
+ jQuery.post(ajaxurl, xd_importing_grab_data(), function(response) {
+ var response_length = response.length - 1;
+ response = response.substring(0,response_length);
+ xd_importing_success(response);
+ });
+ }
+
+ function xd_importing_success(response) {
+ xd_looping_log(response);
+ var possuccess = response.indexOf ("success",0);
+ var poserror = response.indexOf ("error",0);
+ if ( possuccess != -1 || poserror != -1 || response.indexOf('error') > -1 ) {
+ xd_looping_log('<p><?php echo esc_js(__("Go to the list of msgs:","xili-dictionary")); ?> <a href="<?php echo admin_url(); ?>edit.php?post_type=<?php echo XDMSG ?>&page=dictionary_page">Continue</a></p>');
+
+ xd_looping_stop();
+ } else if( xd_looping_is_running ) { // keep going
+ jQuery('#xd-looping-progress').show();
+ clearTimeout( xd_looping_run_timer );
+ xd_looping_run_timer = setTimeout( 'xd_importing_run()', xd_looping_delay_time );
+ } else {
+
+ xd_looping_stop();
+ }
+ }
+
+
+ function xd_erasing_grab_data() {
+ var values = {};
+ jQuery.each(jQuery('#xd-looping-settings').serializeArray(), function(i, field) {
+ values[field.name] = field.value;
+ });
+
+ if( values['_xd_looping_restart'] ) {
+ jQuery('#_xd_looping_restart').removeAttr("checked");
+ }
+
+ if( values['_xd_looping_delay_time'] ) {
+ xd_looping_delay_time = values['_xd_looping_delay_time'] * 1000;
+ }
+
+ values['action'] = 'xd_erasing_process';
+ values['_ajax_nonce'] = '<?php echo wp_create_nonce( 'xd_erasing_process' ); ?>';
+
+ return values;
+ }
+
+
+
+ function xd_erasing_start() {
+ if( false == xd_looping_is_running ) {
+ xd_looping_is_running = true;
+ jQuery('#xd-looping-start').hide();
+ jQuery('#xd-looping-stop').show();
+ jQuery('#xd-looping-progress').show();
+ xd_looping_log( '<p class="loading"><?php echo esc_js( __( 'Starting Erasing', 'xili-dictionary' ) ) ; ?></p>' );
+ xd_erasing_run();
+ }
+ }
+
+ function xd_erasing_run() {
+ jQuery.post(ajaxurl, xd_erasing_grab_data(), function(response) {
+ var response_length = response.length - 1;
+ response = response.substring(0,response_length);
+ xd_erasing_success(response);
+ });
+ }
+
+ function xd_erasing_success(response) {
+ xd_looping_log(response);
+ var possuccess = response.indexOf ("success",0);
+ var poserror = response.indexOf ("error",0);
+ if ( possuccess != -1 || poserror != -1 || response.indexOf('error') > -1 ) {
+ xd_looping_log('<p><?php echo esc_js(__("Go to the list of msgs:","xili-dictionary")); ?> <a href="<?php echo admin_url(); ?>edit.php?post_type=<?php echo XDMSG ?>&page=dictionary_page">Continue</a></p>');
+ xd_looping_stop();
+ } else if( xd_looping_is_running ) { // keep going
+ jQuery('#xd-looping-progress').show();
+ clearTimeout( xd_looping_run_timer );
+ xd_looping_run_timer = setTimeout( 'xd_erasing_run()', xd_looping_delay_time );
+ } else {
+ xd_looping_stop();
+ }
+ }
+
+ function xd_looping_stop() {
+ jQuery('#xd-looping-start').show();
+ jQuery('#xd-looping-stop').hide();
+ jQuery('#xd-looping-progress').hide();
+ jQuery('#xd-looping-message p').removeClass( 'loading' );
+ xd_looping_is_running = false;
+ clearTimeout( xd_looping_run_timer );
+ }
+
+ function xd_looping_log(text) {
+ if ( jQuery('#xd-looping-message').css('display') == 'none' ) {
+ jQuery('#xd-looping-message').show();
+ }
+ if ( text ) {
+ jQuery('#xd-looping-message p').removeClass( 'loading' );
+ jQuery('#xd-looping-message').prepend( text );
+ }
+ }
+
+ </script>
+ <style type="text/css" media="screen">
+ /*<![CDATA[*/
+
+ div.xd-looping-updated,
+ div.xd-looping-warning {
+ border-radius: 3px 3px 3px 3px;
+ border-style: solid;
+ border-width: 1px;
+ padding: 5px 5px 5px 5px;
+ }
+
+ div.xd-looping-updated {
+ height: 300px;
+ overflow: auto;
+ display: none;
+ background-color: #FFFFE0;
+ border-color: #E6DB55;
+ font-family: monospace;
+ font-weight: bold;
+ }
+
+ div.xd-looping-updated p {
+ margin: 0.5em 0;
+ padding: 2px;
+ float: left;
+ clear: left;
+ }
+
+ div.xd-looping-updated p.loading {
+ padding: 2px 20px 2px 2px;
+ background-image: url('<?php echo admin_url(); ?>images/wpspin_light.gif');
+ background-repeat: no-repeat;
+ background-position: center right;
+ }
+
+ #xd-looping-stop {
+ display:none;
+ }
+
+ #xd-looping-progress {
+ display:none;
+ }
+
+ /*]]>*/
+ </style>
+
+ <?php
+ }
+
+
+ function erasing_process_callback() {
+
+ check_ajax_referer( 'xd_erasing_process' );
+
+ if ( ! ini_get( 'safe_mode' ) ) {
+ set_time_limit( 0 );
+ ini_set( 'memory_limit', '256M' );
+ ini_set( 'implicit_flush', '1' );
+ ignore_user_abort( true );
+ }
+
+ // Save step and count so that it can be restarted.
+ if ( ! get_option( '_xd_erasing_step' ) ) {
+ update_option( '_xd_erasing_step', 1 );
+ update_option( '_xd_erasing_start', 0 );
+ }
+
+ $step = (int) get_option( '_xd_erasing_step', 1 );
+ $min = (int) get_option( '_xd_erasing_start', 0 );
+ $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50;
+ $max = ( $min + $count ) - 1;
+ $start = $min;
+
+
+ switch ( $step ) {
+
+ // STEP 1. Prepare and count.
+ case 1 :
+ $count_lines = $this->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 = "<p$class>";
+ $after = '</p>';
+ //$query = get_option( '_xd_erasing_query' );
+
+ //if ( ! empty( $query ) )
+ //$before = '<p class="loading" title="' . esc_attr( $query ) . '">';
+
+ 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() {
+ ?>
+
+ <div class="wrap">
+
+ <?php screen_icon( 'tools' ); ?>
+
+ <h2 class="nav-tab-wrapper"><?php _e( 'Importing files (.po, .pot, .mo)', 'xili-dictionary' ); ?></h2>
+
+ <form action="#" method="post" id="xd-looping-settings">
+
+ <?php settings_fields( 'xd_importing' ); delete_option( '_xd_importing_step'); ?>
+
+ <?php do_settings_sections( 'xd_importing' ); ?>
+
+ <h4 class="link-back"><?php printf(__('<a href="%s">Back</a> to the list of msgs and tools','xili-dictionary'), admin_url() . 'edit.php?post_type='.XDMSG.'&page=dictionary_page' ); ?></h4>
+ <p class="submit">
+ <input type="button" name="submit" class="button-primary" id="xd-looping-start" value="<?php _e( 'Start importing', 'xili-dictionary' ); ?>" onclick="xd_importing_start()" />
+ <input type="button" name="submit" class="button-primary" id="xd-looping-stop" value="<?php _e( 'Stop', 'xili-dictionary' ); ?>" onclick="xd_importing_stop()" />
+ <img id="xd-looping-progress" src="">
+ </p>
+
+ <div class="xd-looping-updated" id="xd-looping-message"></div>
+ </form>
+ </div>
+ <script type="text/javascript">
+ //<![CDATA[
+ <?php
+ if ( function_exists('the_theme_domain') ) {// in new xili-language
+ echo 'var potfile = "'.the_theme_domain().'";';
+ } else {
+ echo 'var potfile = "'.$this->get_theme_name(false).'";';
+ }
+ ?>
+jQuery(document).ready( function() {
+
+ function bbtvalue ( pot ) {
+ var x = jQuery('#_xd_file_extend').val();
+ var lo = jQuery('#_xd_local').val();
+ var la = jQuery('#_xd_lang').val();
+ var t = '<?php echo esc_js(__( 'Start importing', 'xili-dictionary' )); ?>';
+ if ( jQuery('#_xd_local').is(':checked') ) {
+ jQuery("#xd-looping-start").val( t+" : "+lo+"-"+la+'.'+x );
+ } else {
+ jQuery("#xd-looping-start").val( t+' : '+la+'.'+x+pot );
+ }
+ }
+
+ jQuery('#_xd_file_extend').change(function() {
+ var x = jQuery(this).val();
+ if ( x == 'po') {
+ jQuery('#po-comment-option').show();
+ jQuery("#_xd_lang").append( new Option( potfile+'.pot', potfile) );
+ } else {
+ jQuery('#po-comment-option').hide();
+ jQuery("#_xd_lang").find("option[value='"+potfile+"']").remove();
+ }
+ bbtvalue ('');
+ });
+
+ jQuery('#_xd_local').change(function() {
+ bbtvalue ( '' );
+ });
+
+ jQuery('#_xd_lang').change(function() {
+ var x = jQuery(this).val();
+ t = '';
+ if ( potfile == x ) {
+ t = 't';
+ jQuery('#_xd_local').attr('checked',false);
+ jQuery('#_xd_local').prop('disabled',true);
+ } else {
+ jQuery('#_xd_local').prop('disabled',false);
+ };
+ bbtvalue ( t );
+ });
+
+
+ var x = jQuery('#_xd_file_extend').val();
+ if ( x == 'po' ) {
+ jQuery('#po-comment-option').show();
+ jQuery("#_xd_lang").append( new Option( potfile+'.pot', potfile ) );
+ } else {
+ jQuery('#po-comment-option').hide();
+ jQuery("#_xd_lang").find("option[value='"+potfile+"']").remove();
+ }
+
+ bbtvalue ('');
+
+});
+ //]]>
+ </script>
+<?php
+ }
+
+ function xd_importing_init_settings () {
+ add_settings_section( 'xd_importing_main', __( 'Importing the files', 'xili-dictionary' ), array(&$this,'xd_importing_setting_callback_main_section'), 'xd_importing' );
+
+ //
+ add_settings_field( '_xd_importing_type', __( 'Define the file to import', 'xili-dictionary' ), array(&$this,'xd_file_importing_setting_callback_row'), 'xd_importing', 'xd_importing_main' );
+ register_setting( 'xd_importing_main', '_xd_importing_type', '_xd_importing_type_define' );
+
+ // ajax section
+ add_settings_section( 'xd_importing_tech', __( 'Technical settings', 'xili-dictionary' ), array(&$this,'xd_setting_callback_tech_section'), 'xd_importing' );
+
+ // erasing rows step
+ add_settings_field( '_xd_looping_rows', __( 'Entries step', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_row'), 'xd_importing', 'xd_importing_tech' );
+ register_setting( 'xd_importing_tech', '_xd_looping_rows', 'sanitize_title' );
+
+ // Delay Time
+ add_settings_field( '_xd_looping_delay_time', __( 'Delay Time', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_delay_time'), 'xd_importing', 'xd_importing_tech' );
+ register_setting ( 'xd_importing_tech', '_xd_looping_delay_time', 'intval' );
+
+ }
+
+ function xd_setting_callback_tech_section () {
+ ?>
+ <p><?php _e( "These settings below are reserved for future uses, leave values 'as is'.", 'xili-dictionary' ); ?></p>
+ <?php
+ }
+
+
+ /**
+ * Main settings section description for the settings page
+ *
+ * @since
+ */
+ function xd_importing_setting_callback_main_section() {
+ $extend = ( isset( $_GET['extend'] ) ) ? $_GET['extend'] : 'po';
+?>
+
+ <p><?php printf(__( "Here it is possible to import the .%s file inside the dictionary.", 'xili-dictionary' ), '<strong>' . $extend . '</strong>' ) ; ?></p>
+
+ <?php
+ }
+
+ function xd_file_importing_setting_callback_row() {
+ $extend = ( isset( $_GET['extend'] ) ) ? $_GET['extend'] : 'po';
+ // pop up to build
+ ?>
+ <div class="sub-field">
+ <label for="_xd_file_extend"><?php _e( 'Type', 'xili-dictionary' ); ?>: <strong>.</strong></label>
+ <select name="_xd_file_extend" id="_xd_file_extend" class='postform'>
+ <option value="" <?php selected( "", $extend ); ?>> <?php _e('Select type...','xili-dictionary') ?> </option>
+ <option value="po" <?php selected( "po", $extend ); ?>> <?php _e('PO file','xili-dictionary') ?> </option>
+ <option value="mo" <?php selected( "mo", $extend ); ?>> <?php _e('MO file','xili-dictionary') ?> </option>
+ </select>
+
+ <p class="description"><?php _e( 'Type of file: .mo or .po', 'xili-dictionary' ); ?></p>
+ </div>
+<?php // _xd_multi_local
+ if ( is_multisite() && is_super_admin() && !$this->xililanguage_ms ) {
+?>
+ <div class="sub-field">
+ <label for="_xd_multi_local"><?php _e( 'Folder', 'xili-dictionary' ); ?>: </label>
+ <select name="_xd_multi_local" id="_xd_multi_local" class='postform'>
+ <option value="blog-dir"> <?php _e('Site file (blogs.dir)','xili-dictionary') ?> </option>
+ <option value="theme-dir"> <?php _e('Original theme file','xili-dictionary') ?> </option>
+ </select>
+
+ <p class="description"><?php _e( 'As superadmin, define origin of file', 'xili-dictionary' ); ?></p>
+ </div>
+<?php
+ }
+ // local file
+?>
+ <div class="sub-field">
+ <input id="_xd_local" name="_xd_local" type="checkbox" id="_xd_local" value="local" <?php checked( ( $extend == 'mo' ) ); ?> />
+ <label for="_xd_local"><?php _e( 'Locale msgs', 'xili-dictionary' ); ?></label>
+ <p class="description"><?php _e( 'Import locale file (local-xx_YY)', 'xili-dictionary' ); ?></p>
+ </div>
+<?php
+ $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false));
+ ?>
+ <div class="sub-field">
+ <label for="_xd_lang"><?php _e( 'Language', 'xili-dictionary' ); ?>: </label>
+<select name="_xd_lang" id="_xd_lang" class='postform'>
+ <option value=""> <?php _e('Select language','xili-dictionary') ?> </option>
+
+ <?php
+ foreach ($listlanguages as $language) {
+ $selected = ( isset ( $_GET[QUETAG] ) && $language->name == $_GET[QUETAG] ) ? "selected=selected" : "" ;
+ echo '<option value="'.$language->name.'" '.$selected.' >'.__($language->description, 'xili-dictionary').'</option>';
+ }
+
+ ?>
+</select>
+<p class="description"><?php _e( 'Language of the file', 'xili-dictionary' ); ?></p>
+</div>
+<div class="sub-field">
+<label for="_origin_theme"><?php _e( 'Name of current theme', 'xili-dictionary' ); ?> : <?php echo $this->get_theme_name(false); ?></label>
+<input id="_origin_theme" name="_origin_theme" type="hidden" id="_origin_theme" value="<?php echo $this->get_theme_name(false); ?>" />
+<p class="description"><?php _e( 'Used to assign origin taxonomy', 'xili-dictionary' ); ?></p>
+</div>
+ <?php
+
+ ?>
+
+
+
+<?php
+ //if ( $extend == 'po' ) {
+?>
+ <div id="po-comment-option" class="sub-field" style="display:none;" >
+ <label for="_importing_po_comments"> <?php _e( 'What about comments', 'xili-dictionary' ); ?>:
+ <select name="_importing_po_comments" id="_importing_po_comments">
+ <option value="" ><?php _e('No change','xili-dictionary'); ?></option>
+ <option value="replace" ><?php _e('Imported comments replace those in list','xili-dictionary'); ?></option>
+ <option value="append" ><?php _e('Imported comments be appended...','xili-dictionary'); ?></option>
+ </select>
+ </label>
+ </div>
+ <?php
+ //}
+ }
+
+ function _xd_importing_type_define( $input ) {
+ return $input;
+ }
+
+ function importing_process_callback () {
+ check_ajax_referer( 'xd_importing_process' );
+
+ if ( ! ini_get( 'safe_mode' ) ) {
+ set_time_limit( 0 );
+ ini_set( 'memory_limit', '256M' );
+ ini_set( 'implicit_flush', '1' );
+ ignore_user_abort( true );
+ }
+
+ // Save step and count so that it can be restarted.
+ if ( ! get_option( '_xd_importing_step' ) ) {
+ update_option( '_xd_importing_step', 1 );
+ update_option( '_xd_importing_start', 0 );
+ }
+
+ $step = (int) get_option( '_xd_importing_step', 1 );
+ $min = (int) get_option( '_xd_importing_start', 0 );
+ $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50;
+ $max = ( $min + $count ) - 1;
+ $start = $min;
+
+
+
+ $pomofile = ""; // future use
+ $lang = ( ! empty( $_POST['_xd_lang'] ) ) ? $_POST['_xd_lang'] : 'en_US';
+ $type = ( ! empty( $_POST['_xd_file_extend'] ) ) ? $_POST['_xd_file_extend'] : 'po';
+ $local_file = ( ! empty( $_POST['_xd_local'] ) ) ? $_POST['_xd_local'] : '';
+ $local_file2 = ( $local_file == '' ) ? '' : $local_file.'-' ;
+ $multilocal = ( $_POST['_xd_multi_local'] == 'blog-dir' ) ? true : false; // find in original theme in multisite
+
+ switch ( $step ) {
+
+ // STEP 1. Clean all tables.
+ case 1 :
+ $count_entries = $this->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 */