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 . '' ); ?>