changeset 204 | 09a1c134465b |
parent 194 | 32102edaa81b |
203:f507feede89a | 204:09a1c134465b |
---|---|
2 /* |
2 /* |
3 Plugin Name: xili-dictionary |
3 Plugin Name: xili-dictionary |
4 Plugin URI: http://dev.xiligroup.com/xili-dictionary/ |
4 Plugin URI: http://dev.xiligroup.com/xili-dictionary/ |
5 Description: 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 - |
5 Description: A tool using wordpress's CPT and taxonomy for localized themes or multilingual themes managed by xili-language - a powerful tool to create .mo file(s) on the fly in the theme's folder and more... - ONLY for >= WP 3.2.1 - |
6 Author: dev.xiligroup - MS |
6 Author: dev.xiligroup - MS |
7 Version: 2.2.0 |
7 Version: 2.3.0 |
8 Author URI: http://dev.xiligroup.com |
8 Author URI: http://dev.xiligroup.com |
9 License: GPLv2 |
9 License: GPLv2 |
10 Text Domain: xili-dictionary |
10 Text Domain: xili-dictionary |
11 Domain Path: /languages/ |
11 Domain Path: /languages/ |
12 */ |
12 */ |
13 |
13 |
14 # 2.3.0 - 121118 - add ajax functions for import and erase functions |
|
14 # 2.2.0 - 120922 - fixes issues with .mo and .po inserts - better messages and warning |
15 # 2.2.0 - 120922 - fixes issues with .mo and .po inserts - better messages and warning |
15 # 2.1.3 - 120728 - fixes |
16 # 2.1.3 - 120728 - fixes |
16 # 2.1.2 - 120715 - list in msg edit - new query - new metabox - new pointers - ... |
17 # 2.1.2 - 120715 - list in msg edit - new query - new metabox - new pointers - ... |
17 # 2.1.1 - 120710 - fixes - new icons |
18 # 2.1.1 - 120710 - fixes - new icons |
18 # 2.1.0 - 120507 - options to save on new local-xx_XX.mo and more... needs XL 2.6 |
19 # 2.1.0 - 120507 - options to save on new local-xx_XX.mo and more... needs XL 2.6 |
32 # beta 1.4.4 - 111221 - fixes |
33 # beta 1.4.4 - 111221 - fixes |
33 # between 0.9.3 and 1.4.4 see version 1.4.4 - 20120219 |
34 # between 0.9.3 and 1.4.4 see version 1.4.4 - 20120219 |
34 # beta 0.9.3 - first published - 090131 MS |
35 # beta 0.9.3 - first published - 090131 MS |
35 |
36 |
36 |
37 |
37 define('XILIDICTIONARY_VER','2.2.0'); |
38 define('XILIDICTIONARY_VER','2.3.0'); |
38 |
39 |
39 include_once(ABSPATH . WPINC . '/pomo/po.php'); /* not included in wp-settings */ |
40 include_once(ABSPATH . WPINC . '/pomo/po.php'); /* not included in wp-settings */ |
40 |
41 |
41 // the class |
42 // the class |
42 class xili_dictionary { |
43 class xili_dictionary { |
95 var $create_line_lang = ''; // line between box |
96 var $create_line_lang = ''; // line between box |
96 |
97 |
97 var $langs_group_id; /* group ID and Term Taxo ID */ |
98 var $langs_group_id; /* group ID and Term Taxo ID */ |
98 var $langs_group_tt_id; |
99 var $langs_group_tt_id; |
99 |
100 |
101 // temp mo/po object |
|
102 |
|
103 var $temp_po; |
|
100 |
104 |
101 |
105 |
102 public function xili_dictionary( $langsfolder = '/' ) { // ?? php4 |
106 public function xili_dictionary( $langsfolder = '/' ) { // ?? php4 |
103 $this->__construct( $langsfolder ); |
107 $this->__construct( $langsfolder ); |
104 } |
108 } |
146 $this->fill_default_languages_list(); |
150 $this->fill_default_languages_list(); |
147 /* Actions */ |
151 /* Actions */ |
148 /* admin */ |
152 /* admin */ |
149 add_action( 'admin_init', array(&$this,'admin_init') ); // 1.3.0 |
153 add_action( 'admin_init', array(&$this,'admin_init') ); // 1.3.0 |
150 add_action( 'admin_init', array(&$this,'ext_style_init') ); // 2.1 |
154 add_action( 'admin_init', array(&$this,'ext_style_init') ); // 2.1 |
155 add_action( 'admin_init', array(&$this,'xd_erasing_init_settings') ); // 2.3 |
|
156 add_action( 'admin_init', array(&$this,'xd_importing_init_settings') ); // 2.3 |
|
157 |
|
151 add_action( 'admin_menu', array(&$this,'xili_add_dict_pages') ); |
158 add_action( 'admin_menu', array(&$this,'xili_add_dict_pages') ); |
159 |
|
160 add_action( 'admin_menu', array(&$this,'admin_menus'), 10 ); // 2.3 |
|
161 add_action( 'admin_menu', array(&$this,'admin_sub_menus_hide'), 11 ); |
|
162 |
|
163 // Attach to the admin head with our ajax requests cycle and css |
|
164 add_action( 'admin_head', array( $this, 'admin_head' ) ); |
|
165 |
|
166 // Attach to the admin ajax request to process cycles |
|
167 add_action( 'wp_ajax_xd_erasing_process', array( $this, 'erasing_process_callback' ) ); // 2.3 |
|
168 add_action( 'wp_ajax_xd_importing_process', array( $this, 'importing_process_callback' ) ); // 2.3 |
|
152 |
169 |
153 add_action( 'add_meta_boxes', array(&$this, 'add_custom_box_in_post_msg') ); // 2.1.2 |
170 add_action( 'add_meta_boxes', array(&$this, 'add_custom_box_in_post_msg') ); // 2.1.2 |
154 |
171 |
155 add_action( 'init', array(&$this, 'xili_dictionary_register_taxonomies')); // and init |
172 add_action( 'init', array(&$this, 'xili_dictionary_register_taxonomies')); // and init |
156 |
173 |
181 add_action( 'save_post', array(&$this, 'msgid_post_new_create'),12 ,2 ); |
198 add_action( 'save_post', array(&$this, 'msgid_post_new_create'),12 ,2 ); |
182 add_action( 'save_post', array(&$this, 'update_msg_comments'),13, 2 ); // comments and contexts |
199 add_action( 'save_post', array(&$this, 'update_msg_comments'),13, 2 ); // comments and contexts |
183 add_filter( 'post_updated_messages', array(&$this, 'msg_post_messages')); |
200 add_filter( 'post_updated_messages', array(&$this, 'msg_post_messages')); |
184 |
201 |
185 add_action( 'before_delete_post', array(&$this, 'msgid_post_links_delete') ); |
202 add_action( 'before_delete_post', array(&$this, 'msgid_post_links_delete') ); |
203 |
|
186 add_action( 'admin_print_styles-post.php', array(&$this, 'print_styles_xdmsg_edit') ); |
204 add_action( 'admin_print_styles-post.php', array(&$this, 'print_styles_xdmsg_edit') ); |
187 add_action( 'admin_print_styles-post-new.php', array(&$this, 'print_styles_xdmsg_edit') ); |
205 add_action( 'admin_print_styles-post-new.php', array(&$this, 'print_styles_xdmsg_edit') ); |
188 |
206 |
189 add_action( 'admin_print_styles-post.php', array(&$this,'admin_enqueue_styles') ); |
207 add_action( 'admin_print_styles-post.php', array(&$this,'admin_enqueue_styles') ); |
190 add_action( 'admin_print_scripts-post.php', array(&$this,'admin_enqueue_scripts') ); |
208 add_action( 'admin_print_scripts-post.php', array(&$this,'admin_enqueue_scripts') ); |
191 |
209 |
192 add_action( 'admin_print_styles-edit.php', array(&$this, 'print_styles_xdmsg_list') ); // list of msgs |
210 add_action( 'admin_print_styles-edit.php', array(&$this, 'print_styles_xdmsg_list') ); // list of msgs |
193 |
211 |
194 add_action( 'admin_print_styles-xdmsg_page_dictionary_page', array(&$this, 'print_styles_xdmsg_tool') ); |
212 add_action( 'admin_print_styles-xdmsg_page_dictionary_page', array(&$this, 'print_styles_xdmsg_tool') ); |
213 add_action( 'admin_print_styles-xdmsg_page_erase_dictionary_page', array(&$this, 'print_styles_new_ui') ); |
|
214 add_action( 'admin_print_styles-xdmsg_page_import_dictionary_page', array(&$this, 'print_styles_new_ui') ); |
|
195 |
215 |
196 |
216 |
197 add_action( 'add_meta_boxes_' . XDMSG, array(&$this, 'msg_update_action')); // to locally update files from editing... |
217 add_action( 'add_meta_boxes_' . XDMSG, array(&$this, 'msg_update_action')); // to locally update files from editing... |
198 } |
218 } |
199 |
219 |
431 |
451 |
432 echo '</style>'."\n"; |
452 echo '</style>'."\n"; |
433 if ( $this->exists_style_ext && $this->xili_settings['external_xd_style'] == "on" ) wp_enqueue_style( 'xili_dictionary_stylesheet' ); |
453 if ( $this->exists_style_ext && $this->xili_settings['external_xd_style'] == "on" ) wp_enqueue_style( 'xili_dictionary_stylesheet' ); |
434 } |
454 } |
435 |
455 |
456 /** |
|
457 * add styles in new screens (import / erase) |
|
458 * |
|
459 */ |
|
460 function print_styles_new_ui ( ) { |
|
461 |
|
462 echo '<!---- xd css ----->'."\n"; |
|
463 echo '<style type="text/css" media="screen">'."\n"; |
|
464 echo 'form#xd-looping-settings > p { width:600px; padding:10px 20px; 10px 0; font-size:110%; }'."\n"; |
|
465 echo '.sub-field {border:1px #ccc solid; width:600px; padding:10px 20px ; margin:5px 0;}'."\n"; |
|
466 echo '.link-back > a { border:1px #ccc solid; width:80px; padding:4px 10px ; border-radius: 3px; margin-right:4px;}'."\n"; |
|
467 echo '.xd-looping-updated{ width:870px !important; }'."\n"; |
|
468 echo '</style>'."\n"; |
|
469 |
|
470 } |
|
471 |
|
436 |
472 |
437 /** |
473 /** |
438 * style for new dashboard |
474 * style for new dashboard |
439 * @since 2.1 |
475 * @since 2.1 |
440 * |
476 * |
484 ); |
520 ); |
485 |
521 |
486 $term = 'en_US'; |
522 $term = 'en_US'; |
487 $args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'en_us'); |
523 $args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'en_us'); |
488 $theids = $this->safe_lang_term_creation ( $term, $args ); |
524 $theids = $this->safe_lang_term_creation ( $term, $args ); |
489 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
525 if ( !is_wp_error($theids) ) |
526 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
|
490 |
527 |
491 /* default values */ |
528 /* default values */ |
492 if ( ''!= WPLANG && ( strlen( WPLANG )==5 || strlen( WPLANG ) == 2 ) ) : // for japanese |
529 if ( ''!= WPLANG && ( strlen( WPLANG )==5 || strlen( WPLANG ) == 2 ) ) : // for japanese |
493 $this->default_lang = WPLANG; |
530 $this->default_lang = WPLANG; |
494 else: |
531 else: |
502 $term = 'fr_FR'; $desc = 'French'; $slug = 'fr_fr' ; |
539 $term = 'fr_FR'; $desc = 'French'; $slug = 'fr_fr' ; |
503 } |
540 } |
504 $args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug); |
541 $args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug); |
505 |
542 |
506 $theids = $this->safe_lang_term_creation ( $term, $args ) ; |
543 $theids = $this->safe_lang_term_creation ( $term, $args ) ; |
507 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
544 if ( !is_wp_error($theids) ) |
545 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
|
508 |
546 |
509 } |
547 } |
510 |
548 |
511 /** |
549 /** |
512 * Safe language term creation (if XL inactive) |
550 * Safe language term creation (if XL inactive) |
612 $res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); |
650 $res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); |
613 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
651 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
614 if ( $res != '' && is_array ( $thelangs ) ) { |
652 if ( $res != '' && is_array ( $thelangs ) ) { |
615 |
653 |
616 unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr'] ) ; |
654 unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr'] ) ; |
655 if ( isset ( $thelangs['msgstrlangs'][$target_lang] ) && $thelangs['msgstrlangs'][$target_lang] == array( ) ) unset ( $thelangs['msgstrlangs'][$target_lang] ); // 2.3 |
|
656 if ( isset ( $thelangs['msgstrlangs'] ) && $thelangs['msgstrlangs'] == array( ) ) unset ( $thelangs['msgstrlangs'] ); // 2.3 |
|
617 update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta |
657 update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta |
618 } |
658 } |
619 } elseif ( false !== strpos( $type, 'msgstr_' ) && $target_lang != '' ) { |
659 } elseif ( false !== strpos( $type, 'msgstr_' ) && $target_lang != '' ) { |
620 $indices = explode ('_', $type); |
660 $indices = explode ('_', $type); |
621 $msgid_ID = get_post_meta ( $post_id, $this->msgidlang_meta , true); |
661 $msgid_ID = get_post_meta ( $post_id, $this->msgidlang_meta , true); |
622 if ( $indices[1] == 0 ) { |
662 if ( $indices[1] == 0 ) { |
623 $res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); |
663 $res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); |
624 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
664 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
625 if ( $res != '' && is_array ( $thelangs ) ) { |
665 if ( $res != '' && is_array ( $thelangs ) ) { |
626 unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] ) ; |
666 unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] ) ; |
627 // delete childs or trash ?? |
667 if ( isset ( $thelangs['msgstrlangs'][$target_lang] ) && $thelangs['msgstrlangs'][$target_lang] == array( ) ) unset ( $thelangs['msgstrlangs'][$target_lang] ); // 2.3 |
628 // ?? recursive |
668 if ( isset ( $thelangs['msgstrlangs'] ) && $thelangs['msgstrlangs'] == array( ) ) unset ( $thelangs['msgstrlangs'] ); // 2.3 |
669 |
|
629 update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta |
670 update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta |
630 } |
671 } |
631 } else { |
672 } else { |
632 $res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); |
673 $res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); |
633 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
674 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
857 $file = ''; |
898 $file = ''; |
858 } |
899 } |
859 $mo = $this->from_cpt_to_POMO ( $selectlang, 'mo', $extract_array ); |
900 $mo = $this->from_cpt_to_POMO ( $selectlang, 'mo', $extract_array ); |
860 } |
901 } |
861 |
902 |
862 if ( count ($mo->entries) > 0 ){ |
903 if ( isset ( $mo ) && count ($mo->entries) > 0 ){ |
863 |
904 |
864 if ( false === $this->Save_MO_to_file ( $selectlang , $mo, $file ) ) { |
905 if ( false === $this->Save_MO_to_file ( $selectlang , $mo, $file ) ) { |
865 $this->msg_action_message = sprintf('<span class="alert">'.__('Error with File %s !', 'xili-dictionary').'</span> ('.$file.')', $local.$selectlang.'.mo'); |
906 $this->msg_action_message = sprintf('<span class="alert">'.__('Error with File %s !', 'xili-dictionary').'</span> ('.$file.')', $local.$selectlang.'.mo'); |
866 } else { |
907 } else { |
867 $this->msg_action_message = sprintf(__('File %1s updated with %2s msgids', 'xili-dictionary'), $local.$selectlang.'.mo', count ($mo->entries) ); |
908 $this->msg_action_message = sprintf(__('File %1s updated with %2s msgids', 'xili-dictionary'), $local.$selectlang.'.mo', count ($mo->entries) ); |
1118 } |
1159 } |
1119 } |
1160 } |
1120 return false; |
1161 return false; |
1121 } |
1162 } |
1122 |
1163 |
1123 /** |
1164 // used by new ajax |
1124 * import po and mo in cpts series |
1165 |
1125 * |
1166 function pomo_entry_to_xdmsg ( $pomsgid, $pomsgstr, $curlang = 'en_US', $args = array('importing_po_comments'=> '', 'origin_theme' =>'' ) ) { |
1126 * @since 2.0 |
|
1127 * @return |
|
1128 */ |
|
1129 function from_pomo_to_cpts ( $po, $curlang = 'en_US' ) { |
|
1130 $nblines = array( 0, 0); // id, str count |
1167 $nblines = array( 0, 0); // id, str count |
1131 $this->importing_mode = true ; |
1168 // test if msgid exists |
1132 foreach ( $po->entries as $pomsgid => $pomsgstr ) { |
|
1133 // test if msgid exists |
|
1134 $result = $this->msgid_exists ( $pomsgstr->singular, $pomsgstr->context ) ; |
1169 $result = $this->msgid_exists ( $pomsgstr->singular, $pomsgstr->context ) ; |
1135 |
1170 |
1136 if ( $result === false ) { |
1171 if ( $result === false ) { |
1137 // create the msgid |
1172 // create the msgid |
1138 $type = 'msgid'; |
1173 $type = 'msgid'; |
1139 $msgid_post_ID = $this->insert_one_cpt_and_meta( $pomsgstr->singular, $pomsgstr->context, $type, 0, $pomsgstr ) ; |
1174 $msgid_post_ID = $this->insert_one_cpt_and_meta( $pomsgstr->singular, $pomsgstr->context, $type, 0, $pomsgstr ) ; |
1140 $nblines[0]++ ; |
1175 $nblines[0]++ ; |
1141 } else { |
1176 } else { |
1142 $msgid_post_ID = $result[0]; |
1177 $msgid_post_ID = $result[0]; |
1143 if ( $this->importing_po_comments != '' ) { |
1178 if ( $args['importing_po_comments'] != '' ) { |
1144 $this->insert_comments( $msgid_post_ID, $pomsgstr, $this->importing_po_comments ); |
1179 $this->insert_comments( $msgid_post_ID, $pomsgstr, $args['importing_po_comments'] ); |
1145 } |
1180 } |
1146 |
1181 |
1147 } |
1182 } |
1148 |
1183 |
1149 // add origin taxonomy |
1184 // add origin taxonomy |
1150 if ( ''!= $this->origin_theme ) |
1185 if ( ''!= $args['origin_theme'] ) |
1151 wp_set_object_terms( $msgid_post_ID, $this->origin_theme, 'origin', true ); // true to append to existing |
1186 wp_set_object_terms( $msgid_post_ID, $args['origin_theme'], 'origin', true ); // true to append to existing |
1152 |
1187 |
1153 if ( $pomsgstr->is_plural != null ) { |
1188 if ( $pomsgstr->is_plural != null ) { |
1154 // create msgid plural (child of msgid) |
1189 // create msgid plural (child of msgid) |
1155 // $pomsgstr->plural, $msgid_post_ID |
1190 // $pomsgstr->plural, $msgid_post_ID |
1156 $result = $this->msgid_exists ( $pomsgstr->plural ) ; |
1191 $result = $this->msgid_exists ( $pomsgstr->plural ) ; |
1216 } // only first str |
1251 } // only first str |
1217 |
1252 |
1218 $i++; |
1253 $i++; |
1219 } |
1254 } |
1220 } |
1255 } |
1221 |
1256 return $nblines; |
1257 } |
|
1258 |
|
1259 /** |
|
1260 * import po and mo in cpts series |
|
1261 * |
|
1262 * @since 2.0 |
|
1263 * @updated 2.3 pomo_entry_to_xdmsg outside |
|
1264 * @return |
|
1265 */ |
|
1266 function from_pomo_to_cpts ( $po, $curlang = 'en_US' ) { |
|
1267 $nblines = array( 0, 0); // id, str count |
|
1268 $this->importing_mode = true ; |
|
1269 foreach ( $po->entries as $pomsgid => $pomsgstr ) { |
|
1270 |
|
1271 $lines = $this->pomo_entry_to_xdmsg ( $pomsgid, $pomsgstr, $curlang, array ( 'importing_po_comments'=>$this->importing_po_comments, 'origin_theme'=>$this->origin_theme ) ); // global value |
|
1272 |
|
1273 $nblines[0] += $lines[0]; |
|
1274 $nblines[1] += $lines[1]; |
|
1275 |
|
1222 } |
1276 } |
1223 $this->importing_mode = false ; |
1277 $this->importing_mode = false ; |
1224 return $nblines; |
1278 return $nblines; |
1225 } |
1279 } |
1226 |
1280 |
1717 |
1771 |
1718 //printf( 'msgstr[1] created in %s <br/>', $target_lang ) ; |
1772 //printf( 'msgstr[1] created in %s <br/>', $target_lang ) ; |
1719 } |
1773 } |
1720 // redirect |
1774 // redirect |
1721 |
1775 |
1722 //if ( $translated_post_ID > 0 && $this->xili_settings['creation_redirect'] == 'redirect') { |
1776 |
1723 $url_redir = admin_url().'post.php?post='.$translated_post_ID.'&action=edit'; |
1777 $url_redir = admin_url().'post.php?post='.$translated_post_ID.'&action=edit'; |
1724 |
1778 |
1725 ?> |
1779 ?> |
1726 <script type="text/javascript"> |
1780 <script type="text/javascript"> |
1727 <!-- |
1781 <!-- |
1728 window.location= <?php echo "'" . $url_redir . "'"; ?>; |
1782 window.location= <?php echo "'" . $url_redir . "'"; ?>; |
1729 //--> |
1783 //--> |
1730 </script> |
1784 </script><br /> |
1731 <?php |
1785 <?php |
1732 //} |
1786 //} |
1733 } |
1787 } |
1734 } elseif ( isset ($_GET['msgaction']) && $_GET['msgaction'] == 'msgid_plural' && !isset( $thelangs['msgstrlangs'] ) ) { |
1788 } elseif ( isset ($_GET['msgaction']) && $_GET['msgaction'] == 'msgid_plural' && !isset( $thelangs['msgstrlangs'] ) ) { |
1735 check_admin_referer( 'xd-plural' ); |
1789 check_admin_referer( 'xd-plural' ); |
1736 $msgid_plural_post_ID = $this->insert_one_cpt_and_meta ( __('XD say id to plural: ', 'xili-dictionary').$temp_post_msg_id->post_content , null, 'msgid_plural' , $msgid_id ); |
1790 $msgid_plural_post_ID = $this->insert_one_cpt_and_meta ( __('XD say id to plural: ', 'xili-dictionary').$temp_post_msg_id->post_content , null, 'msgid_plural' , $msgid_id ); |
1737 $res = get_post_meta ( $msgid_id, $this->msgchild_meta, false ); |
1791 $res = get_post_meta ( $msgid_id, $this->msgchild_meta, false ); |
1738 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
1792 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
1793 $url_redir = admin_url().'post.php?post='.$msgid_plural_post_ID.'&action=edit'; |
|
1794 //2.3 ?> |
|
1795 <script type="text/javascript"> |
|
1796 <!-- |
|
1797 window.location= <?php echo "'" . $url_redir . "'"; ?>; |
|
1798 //--> |
|
1799 </script><br /> |
|
1800 <?php |
|
1739 |
1801 |
1740 } elseif ( $type == 'msgid' && isset ($_GET['msgaction']) && $_GET['msgaction'] == 'setlocal' ) { |
1802 } elseif ( $type == 'msgid' && isset ($_GET['msgaction']) && $_GET['msgaction'] == 'setlocal' ) { |
1741 check_admin_referer( 'xd-setlocal' ); |
1803 check_admin_referer( 'xd-setlocal' ); |
1742 $extracted_comments = get_post_meta ( $msgid_id, $this->msg_extracted_comments, true ); |
1804 $extracted_comments = get_post_meta ( $msgid_id, $this->msg_extracted_comments, true ); |
1743 $extracted_comments = $this->local_tag .' '. $extracted_comments; |
1805 $extracted_comments = $this->local_tag .' '. $extracted_comments; |
1776 $line .= sprintf( __('( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'),'post.php?post='.$thechilds['msgid']['plural'].'&action=edit', $thechilds['msgid']['plural'], __('Edit') ) ; |
1838 $line .= sprintf( __('( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'),'post.php?post='.$thechilds['msgid']['plural'].'&action=edit', $thechilds['msgid']['plural'], __('Edit') ) ; |
1777 $this->hightlight_line ( $line, $type, 'msgid_plural' ); |
1839 $this->hightlight_line ( $line, $type, 'msgid_plural' ); |
1778 |
1840 |
1779 |
1841 |
1780 } else { |
1842 } else { |
1781 if ( !isset ( $thelangs['msgstrlangs'] ) && !isset ( $thechilds['msgid']['plural'] ) ) { // not yet translated |
1843 //2.3 |
1844 if ( $post->post_status !='auto-draft' && !isset ( $thelangs['msgstrlangs'] ) && !isset ( $thechilds['msgid']['plural'] ) ) { // not yet translated |
|
1782 |
1845 |
1783 $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgid_plural', 'xd-plural' ) ; |
1846 $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgid_plural', 'xd-plural' ) ; |
1784 printf( __(' <a href="%s" >Create msgid_plural</a>', 'xili-dictionary'), $nonce_url ); |
1847 printf( __(' <a href="%s" >Create msgid_plural</a>', 'xili-dictionary'), $nonce_url ); |
1785 echo '<br />'; |
1848 echo '<br />'; |
1786 } |
1849 } |
2249 function xili_add_dict_pages() { |
2312 function xili_add_dict_pages() { |
2250 |
2313 |
2251 //$this->thehook = add_management_page(__('Xili Dictionary','xili-dictionary'), __('xili Dictionary','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings')); |
2314 //$this->thehook = add_management_page(__('Xili Dictionary','xili-dictionary'), __('xili Dictionary','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings')); |
2252 |
2315 |
2253 $this->thehook = add_submenu_page( 'edit.php?post_type='.XDMSG, __('Xili Dictionary','xili-dictionary'), __('Tools, Files po mo','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings') ); |
2316 $this->thehook = add_submenu_page( 'edit.php?post_type='.XDMSG, __('Xili Dictionary','xili-dictionary'), __('Tools, Files po mo','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings') ); |
2254 |
2317 add_action( "admin_head-".$this->thehook, array(&$this,'modify_menu_highlight' )); |
2255 add_action('load-'.$this->thehook, array(&$this,'on_load_page')); |
2318 add_action('load-'.$this->thehook, array(&$this,'on_load_page')); |
2256 |
2319 |
2257 add_action( 'admin_print_scripts-'.$this->thehook, array(&$this,'admin_enqueue_scripts') ); |
2320 add_action( 'admin_print_scripts-'.$this->thehook, array(&$this,'admin_enqueue_scripts') ); |
2258 add_action( 'admin_print_styles-'.$this->thehook, array(&$this,'admin_enqueue_styles') ); |
2321 add_action( 'admin_print_styles-'.$this->thehook, array(&$this,'admin_enqueue_styles') ); |
2259 |
2322 |
2270 function on_load_page() { |
2333 function on_load_page() { |
2271 wp_enqueue_script('common'); |
2334 wp_enqueue_script('common'); |
2272 wp_enqueue_script('wp-lists'); |
2335 wp_enqueue_script('wp-lists'); |
2273 wp_enqueue_script('postbox'); |
2336 wp_enqueue_script('postbox'); |
2274 |
2337 |
2338 add_meta_box('xili-dictionary-sidebox-style', __('XD style settings','xili-dictionary'), array(&$this,'on_sidebox_style_content'), $this->thehook , 'side', 'core'); |
|
2275 add_meta_box('xili-dictionary-sidebox-message', __('Message','xili-dictionary'), array(&$this,'on_sidebox_message_content'), $this->thehook , 'side', 'core'); |
2339 add_meta_box('xili-dictionary-sidebox-message', __('Message','xili-dictionary'), array(&$this,'on_sidebox_message_content'), $this->thehook , 'side', 'core'); |
2276 add_meta_box('xili-dictionary-sidebox-info', __('Info','xili-dictionary'), array(&$this,'on_sidebox_info_content'), $this->thehook , 'side', 'core'); |
2340 add_meta_box('xili-dictionary-sidebox-info', __('Info','xili-dictionary'), array(&$this,'on_sidebox_info_content'), $this->thehook , 'side', 'core'); |
2277 add_meta_box('xili-dictionary-sidebox-style', __('XD style settings','xili-dictionary'), array(&$this,'on_sidebox_style_content'), $this->thehook , 'side', 'core'); |
2341 |
2278 } |
2342 } |
2279 |
2343 |
2280 /** |
2344 /** |
2281 * Add action link(s) to plugins page |
2345 * Add action link(s) to plugins page |
2282 * |
2346 * |
2427 <h4><?php _e('Note:','xili-dictionary') ?></h4> |
2491 <h4><?php _e('Note:','xili-dictionary') ?></h4> |
2428 <p><?php echo $message; ?></p> |
2492 <p><?php echo $message; ?></p> |
2429 <?php |
2493 <?php |
2430 } |
2494 } |
2431 |
2495 |
2432 function get_theme_name () { |
2496 function get_theme_name ( $child_of = true ) { |
2433 if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0 |
2497 if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0 |
2434 $theme_name = get_option("stylesheet").' '.__('child of','xili-dictionary').' '.get_option("template"); |
2498 $theme_name = get_option("stylesheet"); |
2499 if ( $child_of ) $theme_name .= ' '.__('child of','xili-dictionary').' '.get_option("template"); |
|
2435 } else { |
2500 } else { |
2436 $theme_name = get_option("template"); |
2501 $theme_name = get_option("template"); |
2437 } |
2502 } |
2438 return $theme_name; |
2503 return $theme_name; |
2439 } |
2504 } |
2454 echo '<p>'.__('xili-language plugin is not activated !','xili-dictionary').'</p><br />'; |
2519 echo '<p>'.__('xili-language plugin is not activated !','xili-dictionary').'</p><br />'; |
2455 break; |
2520 break; |
2456 } |
2521 } |
2457 } |
2522 } |
2458 ?> |
2523 ?> |
2459 <p><?php _e('xili-dictionary is a plugin (compatible with xili-language) to build a multilingual dictionary saved in the taxonomy tables of WordPress. With this dictionary, it is possible to create and update .mo file in the current theme folder. And more...','xili-dictionary') ?> |
2524 <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>' ); ?> |
2460 </p> |
2525 </p> |
2461 <fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"> |
2526 <fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"> |
2462 <legend><?php echo __("Theme's informations:",'xili-dictionary').' ('. $theme_name .')'; ?></legend> |
2527 <legend><?php echo __("Theme's informations:",'xili-dictionary').' ('. $theme_name .')'; ?></legend> |
2463 <p> |
2528 <p> |
2464 <?php $langfolder = $this->xili_settings['langs_folder']; |
2529 <?php $langfolder = $this->xili_settings['langs_folder']; |
2566 |
2631 |
2567 // left column ?> |
2632 // left column ?> |
2568 <div class="dialoglang"> |
2633 <div class="dialoglang"> |
2569 <label for="language_file"> |
2634 <label for="language_file"> |
2570 <select name="language_file" ><?php |
2635 <select name="language_file" ><?php |
2571 $extend = WPLANG; |
2636 $default_lang = ( defined ('WPLANG') ) ? WPLANG : '' ; |
2572 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' );//get_terms(TAXONAME, array('hide_empty' => false)); |
2637 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' );//get_terms(TAXONAME, array('hide_empty' => false)); |
2573 if ( $listlanguages ) { |
2638 if ( $listlanguages ) { |
2574 foreach ($listlanguages as $reflanguage) { |
2639 foreach ($listlanguages as $reflanguage) { |
2575 echo '<option value="'.$reflanguage->name.'"'; |
2640 echo '<option value="'.$reflanguage->name.'"'; |
2576 if ($extend == $reflanguage->name) { |
2641 if ( $default_lang == $reflanguage->name ) { |
2577 echo ' selected="selected"'; |
2642 echo ' selected="selected"'; |
2578 } |
2643 } |
2579 echo ">".__($reflanguage->description,'xili-dictionary').'</option>'; |
2644 echo ">".__($reflanguage->description,'xili-dictionary').'</option>'; |
2580 |
2645 |
2581 } |
2646 } |
2724 * @updated 1.0.2 |
2789 * @updated 1.0.2 |
2725 * manage files |
2790 * manage files |
2726 */ |
2791 */ |
2727 function on_normal_3_content( $data ) { |
2792 function on_normal_3_content( $data ) { |
2728 extract( $data ); |
2793 extract( $data ); |
2794 $default_lang_get = ( defined ('WPLANG') ) ? '&' . QUETAG . '=' . WPLANG : '' ; |
|
2729 ?> |
2795 ?> |
2730 <h4 id="manage_file"><?php _e('The files','xili-dictionary') ;?></h4> |
2796 <h4 id="manage_file"><?php _e('The files','xili-dictionary') ;?></h4> |
2731 <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> |
2797 <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> |
2732 <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> |
2798 <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> |
2733 <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 /> |
2799 <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 /> |
2734 <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> |
2800 <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> |
2735 |
2801 |
2736 <h4 id="manage_categories"><?php _e('The taxonomies','xili-dictionary') ;?></h4> |
2802 <h4 id="manage_categories"><?php _e('The taxonomies','xili-dictionary') ;?></h4> |
2737 <a class="action-button blue-button" href="<?php echo $this->xd_settings_page.'&action=importtaxonomy'; ?>" title="<?php _e('Import name and description of taxonomy','xili-dictionary') ?>"><?php _e('Import terms of taxonomy','xili-dictionary') ?></a> |
2803 <a class="action-button blue-button" href="<?php echo $this->xd_settings_page.'&action=importtaxonomy'; ?>" title="<?php _e('Import name and description of taxonomy','xili-dictionary') ?>"><?php _e('Import terms of taxonomy','xili-dictionary') ?></a> |
2738 |
2804 |
2740 <?php if ( class_exists ('xili_language') && XILILANGUAGE_VER > '2.3.9' ) { |
2806 <?php if ( class_exists ('xili_language') && XILILANGUAGE_VER > '2.3.9' ) { |
2741 _e ( '…and comment, locale, date terms.', 'xili-dictionary' ); echo '<br /><br />'; |
2807 _e ( '…and comment, locale, date terms.', 'xili-dictionary' ); echo '<br /><br />'; |
2742 } ?> |
2808 } ?> |
2743 <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> |
2809 <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> |
2744 |
2810 |
2745 <h4 id="manage_dictionary"><?php _e('Dictionary','xili-dictionary') ;?></h4> |
2811 <h4 id="manage_dictionary"><?php _e('Dictionary in database','xili-dictionary') ;?></h4> |
2746 <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> |
2812 <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> |
2813 <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> |
|
2747 |
2814 |
2748 <?php // erase and import theme |
2815 <?php // erase and import theme |
2749 } |
2816 } |
2750 |
2817 |
2751 /** |
2818 /** |
3080 $file = ''; |
3147 $file = ''; |
3081 } |
3148 } |
3082 |
3149 |
3083 $mo = $this->from_cpt_to_POMO ( $selectlang, 'mo', $extract_array ); |
3150 $mo = $this->from_cpt_to_POMO ( $selectlang, 'mo', $extract_array ); |
3084 } |
3151 } |
3085 if ( count ($mo->entries) > 0 ){ // 2.2 |
3152 if ( isset ( $mo ) && count ($mo->entries) > 0 ){ // 2.2 |
3086 if ( false === $this->Save_MO_to_file ($selectlang , $mo, $file ) ) { |
3153 if ( false === $this->Save_MO_to_file ($selectlang , $mo, $file ) ) { |
3087 $message .= $file.' '.sprintf(__('error during exporting in %2s %1s.mo file.','xili-dictionary'), $selectlang, $local); |
3154 $message .= $file.' '.sprintf(__('error during exporting in %2s %1s.mo file.','xili-dictionary'), $selectlang, $local); |
3088 } else { |
3155 } else { |
3089 $message .= ' '.sprintf(__('exported in %2s %1s.mo file with %3s msgids.','xili-dictionary'),$selectlang, $local, count ($mo->entries)); |
3156 $message .= ' '.sprintf(__('exported in %2s %1s.mo file with %3s msgids.','xili-dictionary'),$selectlang, $local, count ($mo->entries)); |
3090 } |
3157 } |
3325 // for next update |
3392 // for next update |
3326 break; |
3393 break; |
3327 |
3394 |
3328 case 'importcurthemeterms'; |
3395 case 'importcurthemeterms'; |
3329 $actiontype = "importingcurthemeterms"; |
3396 $actiontype = "importingcurthemeterms"; |
3330 $formtitle = __('Import all terms from current theme','xili-dictionary'); |
3397 $formtitle = __('Import all terms from current theme source','xili-dictionary'); |
3331 $formhow = __('To import terms of the current theme, click below.','xili-dictionary'); |
3398 $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'); |
3332 $submit_text = __('Import all terms »','xili-dictionary'); |
3399 $submit_text = __('Import all terms »','xili-dictionary'); |
3333 |
3400 |
3334 $this->tempoutput = '<strong>'.__('List of scanned files:','xili-dictionary').'</strong><br />'; |
3401 $this->tempoutput = '<strong>'.__('List of scanned files:','xili-dictionary').'</strong><br />'; |
3335 $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),2); |
3402 $themeterms = $this->scan_import_theme_terms( array(&$this,'build_scanned_files'), 2 ); |
3336 $formhow = $this->tempoutput.'<br /><br /><strong>'.$formhow .'</strong>'; |
3403 $formhow = $this->tempoutput.'<br /><br /><strong>'.$formhow .'</strong>'; |
3337 |
3404 |
3338 break; |
3405 break; |
3339 |
3406 |
3340 case 'importingcurthemeterms'; // temporary inactive 2.1 |
3407 case 'importingcurthemeterms'; // temporary inactive 2.1 |
3341 $actiontype = "add"; |
3408 $actiontype = "add"; |
3342 $message .= ' '.__('All terms imported !','xili-dictionary'); $msg = 5 ; |
3409 $message .= ' '.__('All terms imported !','xili-dictionary'); $msg = 5 ; |
3343 $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),0); |
3410 $themeterms = $this->scan_import_theme_terms( array(&$this,'build_scanned_files'), 0 ); |
3344 if (is_array($themeterms)) { |
3411 if ( is_array( $themeterms ) && $themeterms != array() ) { |
3345 //$nbterms = $this->xili_importthemeterms_in_tables($themeterms); |
3412 $nbterms = $this->import_theme_terms ( $themeterms ); |
3346 $message .= __('terms = ','xili-dictionary').$nbterms; |
3413 $message .= __('terms = ','xili-dictionary').$nbterms; |
3347 } else { |
3414 } else { |
3348 $message .= ' '.$readfile.__('theme’s terms pbs!','xili-dictionary'); |
3415 $message .= ' '.$readfile.__('theme’s terms pbs!','xili-dictionary'); |
3349 } |
3416 } |
3350 break; |
3417 break; |
3418 |
|
3351 case 'reset'; |
3419 case 'reset'; |
3352 $actiontype = "add"; |
3420 $actiontype = "add"; |
3353 break; |
3421 break; |
3422 |
|
3354 default: |
3423 default: |
3355 $actiontype = "add"; |
3424 $actiontype = "add"; |
3356 $message .= ' '.__('Find below the list of terms.','xili-dictionary'); |
3425 $message .= ' '.__('Find below the list of terms.','xili-dictionary'); |
3357 |
3426 |
3358 } |
3427 } |
3371 if ($msg == 0 && $message != '' ) $msg = 6 ; //by temporary default |
3440 if ($msg == 0 && $message != '' ) $msg = 6 ; //by temporary default |
3372 $themessages[1] = __('A new term was added.','xili-dictionary'); |
3441 $themessages[1] = __('A new term was added.','xili-dictionary'); |
3373 $themessages[2] = __('A term was updated.','xili-dictionary'); |
3442 $themessages[2] = __('A term was updated.','xili-dictionary'); |
3374 $themessages[3] = __('A term was deleted.','xili-dictionary'); |
3443 $themessages[3] = __('A term was deleted.','xili-dictionary'); |
3375 $themessages[4] = __('terms imported from WP: ','xili-dictionary') . $message; |
3444 $themessages[4] = __('terms imported from WP: ','xili-dictionary') . $message; |
3376 $themessages[5] = __('All terms imported !','xili-dictionary'); |
3445 $themessages[5] = __('All terms imported !','xili-dictionary') . '('.$message.')'; |
3377 $themessages[6] = 'beta testing log: '.$message ; |
3446 $themessages[6] = 'beta testing log: '.$message ; |
3378 $themessages[7] = __('All terms erased !','xili-dictionary'); |
3447 $themessages[7] = __('All terms erased !','xili-dictionary'); |
3379 $themessages[8] = __('Error when adding !','xili-dictionary'); |
3448 $themessages[8] = __('Error when adding !','xili-dictionary'); |
3380 $themessages[9] = __('Error when updating !','xili-dictionary'); |
3449 $themessages[9] = __('Error when updating !','xili-dictionary'); |
3381 |
3450 |
3818 $theme_name = get_option("template"); |
3887 $theme_name = get_option("template"); |
3819 } |
3888 } |
3820 $t = ( $lang == $theme_name ) ? 't': ''; /* from UI to select .pot */ |
3889 $t = ( $lang == $theme_name ) ? 't': ''; /* from UI to select .pot */ |
3821 } |
3890 } |
3822 |
3891 |
3892 $langfolder = $this->get_langfolder(); // 2.3 |
|
3893 |
|
3823 if ( $local == false ) { |
3894 if ( $local == false ) { |
3824 $pofile = $this->get_template_directory.$this->langfolder.$lang.'.po'.$t; |
3895 $pofile = $this->get_template_directory.$langfolder.$lang.'.po'.$t; |
3825 } else { |
3896 } else { |
3826 $pofile = $this->get_template_directory.$this->langfolder.'local-'.$lang.'.po'; // fixed 2.1.1 |
3897 $pofile = $this->get_template_directory.$langfolder.'local-'.$lang.'.po'; // fixed 2.1.1 |
3827 } |
3898 } |
3828 |
3899 |
3829 if ( file_exists( $pofile ) ) { |
3900 if ( file_exists( $pofile ) ) { |
3830 if ( !$po->import_from_file( $pofile ) ) { |
3901 if ( !$po->import_from_file( $pofile ) ) { |
3831 return false; |
3902 return false; |
3835 } else { |
3906 } else { |
3836 return false; |
3907 return false; |
3837 } |
3908 } |
3838 } |
3909 } |
3839 |
3910 |
3911 function get_langfolder() { |
|
3912 $xili_settings = get_option('xili_dictionary_settings'); |
|
3913 $langfolderset = $xili_settings['langs_folder']; |
|
3914 $full_folder = ( $langfolderset !='' ) ? $langfolderset.'/' : '/'; |
|
3915 return $full_folder ; |
|
3916 } |
|
3917 |
|
3918 /** |
|
3919 * Import POMO file in respective class |
|
3920 * |
|
3921 * |
|
3922 * @since 2.3 |
|
3923 */ |
|
3924 function import_POMO ( $extend = 'po', $lang = 'en_US', $local = '' , $pomofile = '', $multilocal = true ) { |
|
3925 if ( in_array ( $extend, array ( 'po', 'mo') ) ) { |
|
3926 |
|
3927 if ( $extend == 'po' ) { |
|
3928 $pomo = new PO(); |
|
3929 |
|
3930 if ( function_exists('the_theme_domain') ) { // xili-language detect it |
|
3931 if ( $lang == the_theme_domain() ) $extend = 'pot'; |
|
3932 } else { |
|
3933 if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0 |
|
3934 $theme_name = get_option("stylesheet"); |
|
3935 } else { |
|
3936 $theme_name = get_option("template"); |
|
3937 } |
|
3938 if ( $lang == $theme_name ) $extend = 'pot' ; /* from UI to select .pot */ |
|
3939 } |
|
3940 |
|
3941 } else { |
|
3942 $pomo = new MO(); |
|
3943 } |
|
3944 $path = ""; |
|
3945 $langfolder = $this->get_langfolder(); |
|
3946 if ( is_multisite() && $multilocal ) { |
|
3947 if ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) { |
|
3948 $path = $uploads['basedir']."/languages/"; |
|
3949 } |
|
3950 } else { |
|
3951 $path = $this->get_template_directory . $langfolder; |
|
3952 } |
|
3953 if ( $pomofile == "" && $local != '' ) { |
|
3954 |
|
3955 $pomofile = $path . $local . '-' . $lang. '.' . $extend ; |
|
3956 |
|
3957 } else if ( '' == $pomofile ) { |
|
3958 |
|
3959 $pomofile = $path . $lang . '.' . $extend ; |
|
3960 |
|
3961 } |
|
3962 |
|
3963 if ( file_exists( $pomofile ) ) { |
|
3964 if ( !$pomo->import_from_file( $pomofile ) ) { |
|
3965 return false; |
|
3966 } else { |
|
3967 return $pomo; |
|
3968 } |
|
3969 } else { |
|
3970 return false; |
|
3971 } |
|
3972 |
|
3973 |
|
3974 } else { |
|
3975 return false; |
|
3976 } |
|
3977 |
|
3978 } |
|
3979 |
|
3980 |
|
3840 /** |
3981 /** |
3841 * Import MO file in class PO |
3982 * Import MO file in class PO |
3842 * |
3983 * |
3843 * |
3984 * |
3844 * @since 1.0.2 - only WP >= 2.8.4 |
3985 * @since 1.0.2 - only WP >= 2.8.4 |
4692 } |
4833 } |
4693 |
4834 |
4694 $this->importing_mode = false ; |
4835 $this->importing_mode = false ; |
4695 return $nbnames; |
4836 return $nbnames; |
4696 } |
4837 } |
4838 |
|
4839 function import_theme_terms ( $id_terms ) { |
|
4840 $count = 0; |
|
4841 if ( function_exists('the_theme_domain') ) {// in new xili-language |
|
4842 $theme = the_theme_domain() ; |
|
4843 } else { |
|
4844 $theme = $this->get_theme_name(false) ; |
|
4845 } |
|
4846 |
|
4847 foreach ( $id_terms as $one_term ) { |
|
4848 $context = ( isset($one_term['ctxt'] ) ) ? $one_term['ctxt'] : null ; |
|
4849 $t_entry = array(); |
|
4850 $t_entry['extracted_comments'] = sprintf ( 'From theme %s', $theme ) ; |
|
4851 $entry = (object) $t_entry ; |
|
4852 if ( isset( $one_term['plural'] ) ) { |
|
4853 $result = $this->msgid_exists ( $one_term['msgid'], $context ) ; |
|
4854 if ( $result === false ) { |
|
4855 $msgid_post_ID = $this->insert_one_cpt_and_meta( $one_term['msgid'], $context, 'msgid', 0, $entry ) ; |
|
4856 $count++; |
|
4857 } |
|
4858 $result = $this->msgid_exists ( $one_term['plural'], $context ) ; |
|
4859 if ( $result === false ) { |
|
4860 $msgid_plural_post_ID = $this->insert_one_cpt_and_meta( $one_term['plural'], $context, 'msgid_plural', $msgid_post_ID, $entry ) ; |
|
4861 $count++; |
|
4862 } |
|
4863 |
|
4864 |
|
4865 } else { |
|
4866 $result = $this->msgid_exists ( $one_term['msgid'] ) ; |
|
4867 if ( $result === false ) { |
|
4868 $msgid_post_ID = $this->insert_one_cpt_and_meta( $one_term['msgid'], $context, 'msgid', 0, $entry ) ; |
|
4869 $count++; |
|
4870 } |
|
4871 } |
|
4872 } |
|
4873 return $count; |
|
4874 } |
|
4697 |
4875 |
4698 /** |
4876 /** |
4699 * Scan terms in themes files |
4877 * Scan terms in themes files |
4700 * |
4878 * |
4701 */ |
4879 */ |
4724 $dualtexts = __('error'); |
4902 $dualtexts = __('error'); |
4725 } elseif ($themefile != 'functions.php'){ |
4903 } elseif ($themefile != 'functions.php'){ |
4726 $lines = @file( $path.'/'.$themefile); |
4904 $lines = @file( $path.'/'.$themefile); |
4727 $t=0; |
4905 $t=0; |
4728 foreach ($lines as $line) { |
4906 foreach ($lines as $line) { |
4729 $i = preg_match_all("/_[_e]\('(.*)', ?'/Ui", $line, $matches,PREG_PATTERN_ORDER); |
4907 |
4908 $i = preg_match_all("/_[_e]\(( *)['\"](.*)['\"],( *)['\"]/Ui", $line, $matches, PREG_PATTERN_ORDER ); //' only single //2.3 |
|
4730 if ($i > 0) { |
4909 if ($i > 0) { |
4731 $resultterms = array_merge ($resultterms, $matches[1]); |
4910 $line_terms = array(); |
4911 foreach ( $matches[2] as $one_match ) { |
|
4912 $line_terms[] = array ( 'msgid' => $one_match ); |
|
4913 } |
|
4914 |
|
4915 $resultterms = array_merge ( $resultterms, $line_terms); |
|
4732 $t += $i; |
4916 $t += $i; |
4733 } |
4917 } |
4918 // single context |
|
4919 $i = preg_match_all("/_(e*)x\(( *)['\"](.*)['\"],( *)['\"](.*)['\"]/Ui", $line, $matches, PREG_PATTERN_ORDER ); //'' only single //2.3 |
|
4920 if ($i > 0) { |
|
4921 $line_terms = array(); |
|
4922 foreach ( $matches[3] as $key => $one_match ) { |
|
4923 $line_terms[] = array ( 'msgid' => $one_match, 'ctxt' => $matches[5][$key] ); |
|
4924 //error_log ( '---xxxx---'. $matches[5][$key] ) ; |
|
4925 } |
|
4926 |
|
4927 $resultterms = array_merge ( $resultterms, $line_terms); |
|
4928 $t += $i; |
|
4929 } |
|
4930 |
|
4931 // plural function _n( $single, $plural, $number, $domain = 'default' ) |
|
4932 $i = preg_match_all("/_n\(( *)['\"](.*)['\"],( *)['\"](.*)['\"]/Ui", $line, $matches, PREG_PATTERN_ORDER ); //'' only single //2.3 |
|
4933 if ($i > 0) { |
|
4934 $line_terms = array(); |
|
4935 foreach ( $matches[2] as $key => $one_match ) { |
|
4936 $line_terms[] = array ( 'msgid' => $one_match, 'plural' => $matches[4][$key] ); |
|
4937 //error_log ( '---nnn---'. $matches[4][$key] ) ; |
|
4938 } |
|
4939 |
|
4940 $resultterms = array_merge ( $resultterms, $line_terms); |
|
4941 $t += $i; |
|
4942 } |
|
4943 |
|
4944 // plural context function _nx($single, $plural, $number, $context, $domain = 'default') |
|
4945 $i = preg_match_all("/_nx\(( *)['\"](.*)['\"],( *)['\"](.*)['\"],(.*),( *)['\"](.*)['\"]/Ui", $line, $matches, PREG_PATTERN_ORDER ); //'' only single //2.3 |
|
4946 if ($i > 0) { |
|
4947 $line_terms = array(); |
|
4948 foreach ( $matches[2] as $key => $one_match ) { |
|
4949 $line_terms[] = array ( 'msgid' => $one_match, 'plural' => $matches[4][$key], 'ctxt' => $matches[7][$key] ); |
|
4950 //error_log ( '---nnn'.$matches[4][$key].'xxx---'. $matches[7][$key] ) ; |
|
4951 } |
|
4952 |
|
4953 $resultterms = array_merge ( $resultterms, $line_terms); |
|
4954 $t += $i; |
|
4955 } |
|
4956 |
|
4957 |
|
4734 } |
4958 } |
4735 if ($display >= 1) |
4959 if ($display >= 1) |
4736 call_user_func($callback, $themefile, $t); |
4960 call_user_func($callback, $themefile, $t); |
4737 } |
4961 } |
4738 } |
4962 } |
4739 if ($display == 2) |
4963 |
4740 call_user_func($callback, $themefile, $t, $resultterms); |
4964 $result_terms = ( $resultterms != array() ) ? $this->super_unique($resultterms) : array() ; |
4741 |
4965 if ( $display == 2 ) |
4742 return $resultterms; |
4966 call_user_func($callback, $themefile, $t, $result_terms); |
4743 } |
4967 |
4744 function build_scanned_files ($themefile, $t, $resultterms = array()) { |
4968 return $result_terms; |
4745 if ($resultterms == array()) { |
4969 } |
4970 |
|
4971 /* in comment http://fr2.php.net/manual/en/function.array-unique.php */ |
|
4972 function super_unique($array) { |
|
4973 $result = array_map("unserialize", array_unique(array_map("serialize", $array))); |
|
4974 |
|
4975 foreach ($result as $key => $value) { |
|
4976 if ( is_array($value) ) |
|
4977 { |
|
4978 $result[$key] = $this->super_unique($value); |
|
4979 } |
|
4980 } |
|
4981 |
|
4982 return $result; |
|
4983 } |
|
4984 |
|
4985 function build_scanned_files ( $themefile, $t, $resultterms = array() ) { |
|
4986 if ( $resultterms == array() ) { |
|
4746 $this->tempoutput .= "- ".$themefile." (".$t.") "; |
4987 $this->tempoutput .= "- ".$themefile." (".$t.") "; |
4747 } else { |
4988 } else { |
4748 $this->tempoutput .= "<br /><strong>".__('List of found terms','xili-dictionary').": </strong><br />"; |
4989 $this->tempoutput .= "<br /><strong>".__('List of found terms','xili-dictionary').": </strong><br />"; |
4749 $this->tempoutput .= implode (', ',$resultterms); |
4990 $resultterms_msgid = array(); |
4991 foreach ( $resultterms as $resultterm ) { |
|
4992 $resultterms_msgid[] = htmlspecialchars($resultterm['msgid']); |
|
4993 } |
|
4994 $this->tempoutput .= implode ( ', ', $resultterms_msgid ); |
|
4750 } |
4995 } |
4751 } |
4996 } |
4752 |
4997 |
4753 /** |
4998 /** |
4754 * Recursive search of files in a path |
4999 * Recursive search of files in a path |
5027 } |
5272 } |
5028 |
5273 |
5029 } |
5274 } |
5030 if ( defined ( "WP_DEBUG" ) && WP_DEBUG == true ) error_log ( 'XD MSG - Updated 2.0->2.1 '.count($i) ) ; |
5275 if ( defined ( "WP_DEBUG" ) && WP_DEBUG == true ) error_log ( 'XD MSG - Updated 2.0->2.1 '.count($i) ) ; |
5031 } |
5276 } |
5277 |
|
5278 /****************** NEW ADMIN UI *******************/ |
|
5279 /** since 2.3 **/ |
|
5280 |
|
5281 function admin_menus() { |
|
5282 |
|
5283 $hooks = array(); |
|
5284 |
|
5285 $hooks[] = add_submenu_page('edit.php?post_type='.XDMSG, |
|
5286 __( 'Erasing', 'xili-dictionary' ), |
|
5287 __( 'Erase', 'xili-dictionary' ), |
|
5288 'import', |
|
5289 'erase_dictionary_page', array(&$this,'xili_dictionary_erase') |
|
5290 ); |
|
5291 $hooks[] = add_submenu_page('edit.php?post_type='.XDMSG, |
|
5292 __( 'Importing files', 'xili-dictionary' ), |
|
5293 __( 'Import', 'xili-dictionary' ), |
|
5294 'import', |
|
5295 'import_dictionary_page', array(&$this,'xili_dictionary_import') |
|
5296 ); |
|
5297 |
|
5298 // Fudge the highlighted subnav item when on a XD admin page |
|
5299 foreach( $hooks as $hook ) { |
|
5300 add_action( "admin_head-$hook", array(&$this,'modify_menu_highlight' )); |
|
5301 } |
|
5302 |
|
5303 } |
|
5304 function admin_sub_menus_hide () { |
|
5305 |
|
5306 remove_submenu_page( 'edit.php?post_type='.XDMSG, 'erase_dictionary_page' ); |
|
5307 remove_submenu_page( 'edit.php?post_type='.XDMSG, 'import_dictionary_page' ); |
|
5308 |
|
5309 |
|
5310 } |
|
5311 |
|
5312 function modify_menu_highlight() { |
|
5313 global $plugin_page, $submenu_file; |
|
5314 |
|
5315 // This tweaks the Tools subnav menu to only show one XD menu item |
|
5316 if ( in_array( $plugin_page, array( 'erase_dictionary_page', 'import_dictionary_page' ) ) ) |
|
5317 $submenu_file = 'dictionary_page'; |
|
5318 } |
|
5319 |
|
5320 /** |
|
5321 * Main settings section description for the settings page |
|
5322 * |
|
5323 * @since |
|
5324 */ |
|
5325 function xd_erasing_setting_callback_main_section() { |
|
5326 ?> |
|
5327 |
|
5328 <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> |
|
5329 |
|
5330 <?php |
|
5331 } |
|
5332 |
|
5333 function xd_sub_selection__setting_callback_row() { |
|
5334 ?> |
|
5335 <div class="sub-field"> |
|
5336 <input id="_xd_local" name="_xd_local" type="checkbox" id="_xd_local" value="local" <?php checked( ( 'local' == 'local' ) ); ?> /> |
|
5337 <label for="_xd_local"><?php _e( 'Locale msgs only', 'xili-dictionary' ); ?></label> |
|
5338 <p class="description"><?php _e( 'Erase only locale msgs (as saved in local-xx_YY files)', 'xili-dictionary' ); ?></p> |
|
5339 </div> |
|
5340 <?php |
|
5341 |
|
5342 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
|
5343 ?> |
|
5344 <div class="sub-field"> |
|
5345 <label for="_xd_lang"><?php _e( 'Terms (msgid / msgstr) to erase', 'xili-dictionary' ); ?>: </label> |
|
5346 <select name="_xd_lang" id="_xd_lang" class='postform'> |
|
5347 <option value=""> <?php _e('Original (msgid) and translations or Select language...','xili-dictionary') ?> </option> |
|
5348 <option value="all-lang"> <?php _e('Translations (msgstr) in all languages','xili-dictionary') ?> </option> |
|
5349 <?php |
|
5350 foreach ($listlanguages as $language) { |
|
5351 $selected = ( isset ( $_GET[QUETAG] ) && $language->name == $_GET[QUETAG] ) ? "selected=selected" : "" ; |
|
5352 echo '<option value="'.$language->name.'" '.$selected.' >'. sprintf(__('Translations (msgstr) in %s','xili-dictionary'), __($language->description, 'xili-dictionary')).'</option>'; |
|
5353 } |
|
5354 |
|
5355 ?> |
|
5356 </select> |
|
5357 <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> |
|
5358 </div> |
|
5359 <div class="sub-field"> |
|
5360 <?php |
|
5361 |
|
5362 if ( is_child_theme() ) { |
|
5363 $cur_theme_name = get_option("stylesheet"); |
|
5364 } else { |
|
5365 $cur_theme_name = get_option("template"); |
|
5366 } |
|
5367 $listterms = get_terms( 'origin', array('hide_empty' => false) ); |
|
5368 echo '<div class="dialogorigin">'; |
|
5369 if ( $listterms ) { |
|
5370 $checkline = __ ( 'Check Origin(s) to be erased', 'xili-dictionary' ).':<br />'; |
|
5371 $i = 0; |
|
5372 echo '<table class="checktheme" ><tr>'; |
|
5373 foreach ( $listterms as $onetheme) { |
|
5374 $checked = ( $onetheme->name == $cur_theme_name ) ? 'checked="checked"' : '' ; |
|
5375 $checkline .= '<td><input type="checkbox" '. $checked .' id="theme-'.$onetheme->term_id.'" name="theme-'.$onetheme->term_id.'" value="'.$onetheme->slug.'" /> ' . $onetheme->name .'</td>'; |
|
5376 $i++; |
|
5377 if ( ($i % 2) == 0 ) $checkline .= '</tr><tr>'; |
|
5378 } |
|
5379 echo $checkline.'</tr></table>'; |
|
5380 } |
|
5381 echo '</div>'; ?> |
|
5382 <p class="description"><?php _e( 'Origins of the msgs to be erased. Without selection, msg without origin will be erased', 'xili-dictionary' ); ?></p> |
|
5383 </div> |
|
5384 |
|
5385 <?php } |
|
5386 |
|
5387 function xd_erasing_setting_callback_row() { |
|
5388 ?> |
|
5389 |
|
5390 <input name="_xd_looping_rows" type="text" id="_xd_looping_rows" value="50" class="small-text" /> |
|
5391 <label for="_xd_looping_rows"><?php _e( 'Number of entries in one step', 'xili-dictionary' ); ?></label> |
|
5392 |
|
5393 <?php |
|
5394 } |
|
5395 |
|
5396 /** |
|
5397 * Edit Delay Time setting field |
|
5398 * |
|
5399 * @since |
|
5400 */ |
|
5401 function xd_erasing_setting_callback_delay_time() { |
|
5402 ?> |
|
5403 |
|
5404 <input name="_xd_looping_delay_time" type="text" id="_xd_looping_delay_time" value=".5" class="small-text" /> |
|
5405 <label for="_xd_looping_delay_time"><?php _e( 'second(s) delay between each group of rows', 'xili-dictionary' ); ?></label> |
|
5406 <p class="description"><?php _e( 'Keep this high to prevent too-many-connection issues.', 'xili-dictionary' ); ?></p> |
|
5407 |
|
5408 <?php |
|
5409 } |
|
5410 |
|
5411 function xd_erasing_init_settings () { |
|
5412 add_settings_section( 'xd_erasing_main', __( 'Erasing the dictionary', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_main_section'), 'xd_erasing' ); |
|
5413 |
|
5414 // erasing sub-selections |
|
5415 add_settings_field( '_xd_sub_selection', __( 'What to erase ?', 'xili-dictionary' ), array(&$this,'xd_sub_selection__setting_callback_row'), 'xd_erasing', 'xd_erasing_main' ); |
|
5416 register_setting( 'xd_erasing_main', '_xd_sub_selection', '_xd_sub_selection_define' ); |
|
5417 |
|
5418 // ajax section |
|
5419 add_settings_section( 'xd_erasing_tech', __( 'Technical settings', 'xili-dictionary' ), array(&$this,'xd_setting_callback_tech_section'), 'xd_erasing' ); |
|
5420 |
|
5421 // erasing rows step |
|
5422 add_settings_field( '_xd_looping_rows', __( 'Entries step', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_row'), 'xd_erasing', 'xd_erasing_tech' ); |
|
5423 register_setting( 'xd_erasing_tech', '_xd_looping_rows', 'sanitize_title' ); |
|
5424 |
|
5425 // Delay Time |
|
5426 add_settings_field( '_xd_looping_delay_time', __( 'Delay Time', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_delay_time'), 'xd_erasing', 'xd_erasing_tech' ); |
|
5427 register_setting ( 'xd_erasing_tech', '_xd_looping_delay_time', 'intval' ); |
|
5428 |
|
5429 |
|
5430 } |
|
5431 |
|
5432 function xili_dictionary_erase() { |
|
5433 ?> |
|
5434 |
|
5435 <div class="wrap"> |
|
5436 |
|
5437 <?php screen_icon( 'tools' ); ?> |
|
5438 |
|
5439 <h2 class="nav-tab-wrapper"><?php _e( 'Erasing Dictionary lines', 'xili-dictionary' ); ?></h2> |
|
5440 |
|
5441 <form action="#" method="post" id="xd-looping-settings"> |
|
5442 |
|
5443 <?php settings_fields( 'xd_erasing' ); delete_option( '_xd_erasing_step'); // echo get_option( '_xd_erasing_step', 1 ); ?> |
|
5444 |
|
5445 <?php do_settings_sections( 'xd_erasing' ); ?> |
|
5446 <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> |
|
5447 <p class="submit"> |
|
5448 <input type="button" name="submit" class="button-primary" id="xd-looping-start" value="<?php _e( 'Start erasing', 'xili-dictionary' ); ?>" onclick="xd_erasing_start()" /> |
|
5449 <input type="button" name="submit" class="button-primary" id="xd-looping-stop" value="<?php _e( 'Stop', 'xili-dictionary' ); ?>" onclick="xd_looping_stop()" /> |
|
5450 <img id="xd-looping-progress" src=""> |
|
5451 </p> |
|
5452 |
|
5453 <div class="xd-looping-updated" id="xd-looping-message"></div> |
|
5454 </form> |
|
5455 </div> |
|
5456 |
|
5457 <?php |
|
5458 } |
|
5459 |
|
5460 function admin_head() { |
|
5461 |
|
5462 ?> |
|
5463 <script language="javascript"> |
|
5464 |
|
5465 var xd_looping_is_running = false; |
|
5466 var xd_looping_run_timer; |
|
5467 var xd_looping_delay_time = 0; |
|
5468 |
|
5469 function xd_importing_grab_data() { |
|
5470 var values = {}; |
|
5471 jQuery.each(jQuery('#xd-looping-settings').serializeArray(), function(i, field) { |
|
5472 values[field.name] = field.value; |
|
5473 }); |
|
5474 |
|
5475 if( values['_xd_looping_restart'] ) { |
|
5476 jQuery('#_xd_looping_restart').removeAttr("checked"); |
|
5477 } |
|
5478 |
|
5479 if( values['_xd_looping_delay_time'] ) { |
|
5480 xd_looping_delay_time = values['_xd_looping_delay_time'] * 1000; |
|
5481 } |
|
5482 |
|
5483 values['action'] = 'xd_importing_process'; |
|
5484 values['_ajax_nonce'] = '<?php echo wp_create_nonce( 'xd_importing_process' ); ?>'; |
|
5485 |
|
5486 return values; |
|
5487 } |
|
5488 |
|
5489 function xd_importing_start() { |
|
5490 if( false == xd_looping_is_running ) { |
|
5491 xd_looping_is_running = true; |
|
5492 jQuery('#xd-looping-start').hide(); |
|
5493 jQuery('#xd-looping-stop').show(); |
|
5494 jQuery('#xd-looping-progress').show(); |
|
5495 xd_looping_log( '<p class="loading"><?php echo esc_js(__( 'Starting Importing', 'xili-dictionary' )); ?></p>' ); |
|
5496 xd_importing_run(); |
|
5497 } |
|
5498 } |
|
5499 |
|
5500 function xd_importing_run() { |
|
5501 jQuery.post(ajaxurl, xd_importing_grab_data(), function(response) { |
|
5502 var response_length = response.length - 1; |
|
5503 response = response.substring(0,response_length); |
|
5504 xd_importing_success(response); |
|
5505 }); |
|
5506 } |
|
5507 |
|
5508 function xd_importing_success(response) { |
|
5509 xd_looping_log(response); |
|
5510 var possuccess = response.indexOf ("success",0); |
|
5511 var poserror = response.indexOf ("error",0); |
|
5512 if ( possuccess != -1 || poserror != -1 || response.indexOf('error') > -1 ) { |
|
5513 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>'); |
|
5514 |
|
5515 xd_looping_stop(); |
|
5516 } else if( xd_looping_is_running ) { // keep going |
|
5517 jQuery('#xd-looping-progress').show(); |
|
5518 clearTimeout( xd_looping_run_timer ); |
|
5519 xd_looping_run_timer = setTimeout( 'xd_importing_run()', xd_looping_delay_time ); |
|
5520 } else { |
|
5521 |
|
5522 xd_looping_stop(); |
|
5523 } |
|
5524 } |
|
5525 |
|
5526 |
|
5527 function xd_erasing_grab_data() { |
|
5528 var values = {}; |
|
5529 jQuery.each(jQuery('#xd-looping-settings').serializeArray(), function(i, field) { |
|
5530 values[field.name] = field.value; |
|
5531 }); |
|
5532 |
|
5533 if( values['_xd_looping_restart'] ) { |
|
5534 jQuery('#_xd_looping_restart').removeAttr("checked"); |
|
5535 } |
|
5536 |
|
5537 if( values['_xd_looping_delay_time'] ) { |
|
5538 xd_looping_delay_time = values['_xd_looping_delay_time'] * 1000; |
|
5539 } |
|
5540 |
|
5541 values['action'] = 'xd_erasing_process'; |
|
5542 values['_ajax_nonce'] = '<?php echo wp_create_nonce( 'xd_erasing_process' ); ?>'; |
|
5543 |
|
5544 return values; |
|
5545 } |
|
5546 |
|
5547 |
|
5548 |
|
5549 function xd_erasing_start() { |
|
5550 if( false == xd_looping_is_running ) { |
|
5551 xd_looping_is_running = true; |
|
5552 jQuery('#xd-looping-start').hide(); |
|
5553 jQuery('#xd-looping-stop').show(); |
|
5554 jQuery('#xd-looping-progress').show(); |
|
5555 xd_looping_log( '<p class="loading"><?php echo esc_js( __( 'Starting Erasing', 'xili-dictionary' ) ) ; ?></p>' ); |
|
5556 xd_erasing_run(); |
|
5557 } |
|
5558 } |
|
5559 |
|
5560 function xd_erasing_run() { |
|
5561 jQuery.post(ajaxurl, xd_erasing_grab_data(), function(response) { |
|
5562 var response_length = response.length - 1; |
|
5563 response = response.substring(0,response_length); |
|
5564 xd_erasing_success(response); |
|
5565 }); |
|
5566 } |
|
5567 |
|
5568 function xd_erasing_success(response) { |
|
5569 xd_looping_log(response); |
|
5570 var possuccess = response.indexOf ("success",0); |
|
5571 var poserror = response.indexOf ("error",0); |
|
5572 if ( possuccess != -1 || poserror != -1 || response.indexOf('error') > -1 ) { |
|
5573 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>'); |
|
5574 xd_looping_stop(); |
|
5575 } else if( xd_looping_is_running ) { // keep going |
|
5576 jQuery('#xd-looping-progress').show(); |
|
5577 clearTimeout( xd_looping_run_timer ); |
|
5578 xd_looping_run_timer = setTimeout( 'xd_erasing_run()', xd_looping_delay_time ); |
|
5579 } else { |
|
5580 xd_looping_stop(); |
|
5581 } |
|
5582 } |
|
5583 |
|
5584 function xd_looping_stop() { |
|
5585 jQuery('#xd-looping-start').show(); |
|
5586 jQuery('#xd-looping-stop').hide(); |
|
5587 jQuery('#xd-looping-progress').hide(); |
|
5588 jQuery('#xd-looping-message p').removeClass( 'loading' ); |
|
5589 xd_looping_is_running = false; |
|
5590 clearTimeout( xd_looping_run_timer ); |
|
5591 } |
|
5592 |
|
5593 function xd_looping_log(text) { |
|
5594 if ( jQuery('#xd-looping-message').css('display') == 'none' ) { |
|
5595 jQuery('#xd-looping-message').show(); |
|
5596 } |
|
5597 if ( text ) { |
|
5598 jQuery('#xd-looping-message p').removeClass( 'loading' ); |
|
5599 jQuery('#xd-looping-message').prepend( text ); |
|
5600 } |
|
5601 } |
|
5602 |
|
5603 </script> |
|
5604 <style type="text/css" media="screen"> |
|
5605 /*<![CDATA[*/ |
|
5606 |
|
5607 div.xd-looping-updated, |
|
5608 div.xd-looping-warning { |
|
5609 border-radius: 3px 3px 3px 3px; |
|
5610 border-style: solid; |
|
5611 border-width: 1px; |
|
5612 padding: 5px 5px 5px 5px; |
|
5613 } |
|
5614 |
|
5615 div.xd-looping-updated { |
|
5616 height: 300px; |
|
5617 overflow: auto; |
|
5618 display: none; |
|
5619 background-color: #FFFFE0; |
|
5620 border-color: #E6DB55; |
|
5621 font-family: monospace; |
|
5622 font-weight: bold; |
|
5623 } |
|
5624 |
|
5625 div.xd-looping-updated p { |
|
5626 margin: 0.5em 0; |
|
5627 padding: 2px; |
|
5628 float: left; |
|
5629 clear: left; |
|
5630 } |
|
5631 |
|
5632 div.xd-looping-updated p.loading { |
|
5633 padding: 2px 20px 2px 2px; |
|
5634 background-image: url('<?php echo admin_url(); ?>images/wpspin_light.gif'); |
|
5635 background-repeat: no-repeat; |
|
5636 background-position: center right; |
|
5637 } |
|
5638 |
|
5639 #xd-looping-stop { |
|
5640 display:none; |
|
5641 } |
|
5642 |
|
5643 #xd-looping-progress { |
|
5644 display:none; |
|
5645 } |
|
5646 |
|
5647 /*]]>*/ |
|
5648 </style> |
|
5649 |
|
5650 <?php |
|
5651 } |
|
5652 |
|
5653 |
|
5654 function erasing_process_callback() { |
|
5655 |
|
5656 check_ajax_referer( 'xd_erasing_process' ); |
|
5657 |
|
5658 if ( ! ini_get( 'safe_mode' ) ) { |
|
5659 set_time_limit( 0 ); |
|
5660 ini_set( 'memory_limit', '256M' ); |
|
5661 ini_set( 'implicit_flush', '1' ); |
|
5662 ignore_user_abort( true ); |
|
5663 } |
|
5664 |
|
5665 // Save step and count so that it can be restarted. |
|
5666 if ( ! get_option( '_xd_erasing_step' ) ) { |
|
5667 update_option( '_xd_erasing_step', 1 ); |
|
5668 update_option( '_xd_erasing_start', 0 ); |
|
5669 } |
|
5670 |
|
5671 $step = (int) get_option( '_xd_erasing_step', 1 ); |
|
5672 $min = (int) get_option( '_xd_erasing_start', 0 ); |
|
5673 $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50; |
|
5674 $max = ( $min + $count ) - 1; |
|
5675 $start = $min; |
|
5676 |
|
5677 |
|
5678 switch ( $step ) { |
|
5679 |
|
5680 // STEP 1. Prepare and count. |
|
5681 case 1 : |
|
5682 $count_lines = $this->caching_msgs_to_erase ( ); |
|
5683 |
|
5684 if ( $count_lines > 0 ) { |
|
5685 update_option( '_xd_erasing_step', $step + 1 ); |
|
5686 update_option( '_xd_erasing_start', 0 ); |
|
5687 update_option( '_xd_erasing_count_lines', $count_lines ); |
|
5688 $this->looping_output( sprintf( __('Lines found ! ( %2$s lines)', 'xili-dictionary' ), '', $count_lines ) ); |
|
5689 |
|
5690 } else { |
|
5691 delete_option( '_xd_erasing_step' ); |
|
5692 delete_option( '_xd_erasing_start' ); |
|
5693 delete_option( '_xd_erasing_count_lines' ); |
|
5694 delete_option( '_xd_deletion_type' ); |
|
5695 delete_option ( '_xd_cache_temp_array_IDs' ); |
|
5696 $this->looping_output( __( 'No msgs to erase', 'xili-dictionary' ), 'error' ); |
|
5697 |
|
5698 } |
|
5699 break; |
|
5700 // STEP 2. Loop |
|
5701 case 2 : |
|
5702 $count_lines = get_option( '_xd_erasing_count_lines', $max + 1 ); |
|
5703 //error_log ('---- count-lines='. $count_lines .', start='. $start ); |
|
5704 $back = $this->erasing_msgs( $start ); |
|
5705 if ( in_array( $back , array( 'no-list', 'loop-over', 'loop-full' ) ) ) { |
|
5706 update_option( '_xd_erasing_step', $step + 1 ); |
|
5707 update_option( '_xd_erasing_start', 0 ); |
|
5708 if ( empty( $start ) || $back == 'no-list' ) { |
|
5709 |
|
5710 if ( 'loop-full' == $back ) { |
|
5711 $this->looping_output( sprintf(__( 'No more msgs to erase (%s)', 'xili-dictionary' ), $back ) , 'loading' ); |
|
5712 } else { |
|
5713 $this->looping_output( sprintf(__( 'No msgs to erase (%s)', 'xili-dictionary' ), $back ) , 'error' ); |
|
5714 |
|
5715 } |
|
5716 } |
|
5717 |
|
5718 } else { |
|
5719 |
|
5720 update_option( '_xd_erasing_start', $max + 1 ); |
|
5721 |
|
5722 $count_lines = get_option( '_xd_erasing_count_lines', $max + 1 ); |
|
5723 $end = ( $count_lines > $max ) ? $max + 1 : $count_lines ; |
|
5724 |
|
5725 $this->looping_output( sprintf( __( 'Erasing msgs (%1$s - %2$s)', 'xili-dictionary' ), $min, $end ), 'loading' ); |
|
5726 |
|
5727 } |
|
5728 |
|
5729 break; |
|
5730 |
|
5731 |
|
5732 default: |
|
5733 $count_lines = get_option( '_xd_erasing_count_lines', $max + 1 ); |
|
5734 delete_option( '_xd_erasing_step' ); |
|
5735 delete_option( '_xd_erasing_start' ); |
|
5736 delete_option( '_xd_erasing_count_lines'); |
|
5737 delete_option( '_xd_deletion_type' ); |
|
5738 delete_option ( '_xd_cache_temp_array_IDs' ); |
|
5739 |
|
5740 $this->looping_output( sprintf( __( 'Erasing Complete (%1$s)', 'xili-dictionary' ), $count_lines ), 'success' ); |
|
5741 break; |
|
5742 |
|
5743 } |
|
5744 } |
|
5745 |
|
5746 private static function looping_output( $output = '', $type = '' ) { |
|
5747 |
|
5748 switch ( $type ) { |
|
5749 |
|
5750 case 'success': |
|
5751 $class = ' class="success"'; |
|
5752 break; |
|
5753 case 'error': |
|
5754 $class = ' class="error"'; |
|
5755 break; |
|
5756 default: |
|
5757 $class = ' class="loading"'; |
|
5758 break; |
|
5759 } |
|
5760 |
|
5761 // Get the last query |
|
5762 $before = "<p$class>"; |
|
5763 $after = '</p>'; |
|
5764 //$query = get_option( '_xd_erasing_query' ); |
|
5765 |
|
5766 //if ( ! empty( $query ) ) |
|
5767 //$before = '<p class="loading" title="' . esc_attr( $query ) . '">'; |
|
5768 |
|
5769 echo $before . $output . $after; |
|
5770 } |
|
5771 |
|
5772 private static function erasing_msgs ( $start ) { |
|
5773 global $xili_dictionary; |
|
5774 // $listdictiolines = $xili_dictionary->get_msgs_to_erase ( $start ); |
|
5775 $id_list = get_option ( '_xd_cache_temp_array_IDs' ); |
|
5776 if ( $id_list ) { //$listdictiolines |
|
5777 |
|
5778 |
|
5779 $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50; |
|
5780 |
|
5781 $only_local = ( isset ( $_POST['_xd_local'] ) ) ? true : false ; |
|
5782 |
|
5783 $selected_lang = ( isset ( $_POST['_xd_lang'] ) ) ? $_POST['_xd_lang'] : "" ; |
|
5784 |
|
5785 $deletion_type = get_option( '_xd_deletion_type' ); |
|
5786 |
|
5787 // loop |
|
5788 $count_lines = count( $id_list ); |
|
5789 //error_log ('type='. $deletion_type . ', count-lines='. $count_lines .', start='.$start); |
|
5790 $i = 0; |
|
5791 foreach ( $id_list as $one_id ) { |
|
5792 // to exit loop when only ids remain in loop |
|
5793 //if ( in_array( $deletion_type , array ( 'all_str', 'only_local' ) ) ) { |
|
5794 $i++; |
|
5795 if ( $i < $start ) continue; |
|
5796 if ( $i > ($start + $count) - 1 ) return 'loop'; |
|
5797 if ( $i > $count_lines ) return 'loop-over'; |
|
5798 //} |
|
5799 //error_log ('count='.$count . ' one_id='. $one_id . ', i='. $i ); |
|
5800 $res = get_post_meta ( $one_id, $xili_dictionary->msglang_meta, false ); |
|
5801 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
5802 |
|
5803 |
|
5804 switch ( $deletion_type ) { |
|
5805 |
|
5806 case 'all': |
|
5807 wp_delete_post( $one_id, false ) ; |
|
5808 break; |
|
5809 |
|
5810 case 'only_local': // id and all str or all str |
|
5811 |
|
5812 if ( isset ( $thelangs['msgstrlangs'] ) ) { |
|
5813 foreach ( $thelangs['msgstrlangs'] as $curlang => $msgtr ) { |
|
5814 |
|
5815 $res = get_post_meta ( $one_id, $xili_dictionary->msgchild_meta, false ); |
|
5816 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
5817 if ( isset ( $thechilds['msgid']['plural'] ) ) { |
|
5818 $msgstrs_arr = $xili_dictionary->get_cpt_msgstr( $one_id, $curlang, true ); |
|
5819 if ( $msgstrs_arr ) { |
|
5820 foreach ( $msgstrs_arr as $msgstrs ) { |
|
5821 if ( $selected_lang == "all-lang" ) |
|
5822 wp_delete_post( $msgstrs->ID, false ) ; |
|
5823 } |
|
5824 } |
|
5825 |
|
5826 } else { |
|
5827 |
|
5828 $msgstrs = $xili_dictionary->get_cpt_msgstr( $one_id, $curlang, false ); // affiner plural |
|
5829 |
|
5830 // delete only msgstr of $oneline->ID |
|
5831 |
|
5832 if ( $msgstrs != false && $selected_lang == "all-lang" ) { |
|
5833 wp_delete_post( $msgstrs->ID, false ) ; |
|
5834 } |
|
5835 } |
|
5836 } |
|
5837 } |
|
5838 // clean msgid |
|
5839 // msgid_post_links_delete |
|
5840 // delete msgid - if $selected_lang == "" |
|
5841 if ( $selected_lang == "" ) { |
|
5842 wp_delete_post( $one_id, false ) ; |
|
5843 } |
|
5844 break; |
|
5845 |
|
5846 case 'str_one_lang': |
|
5847 |
|
5848 $res = get_post_meta ( $one_id, $xili_dictionary->msgchild_meta, false ); |
|
5849 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
5850 if ( isset ( $thechilds['msgid']['plural'] ) ) { |
|
5851 $msgstrs_arr = $xili_dictionary->get_cpt_msgstr( $one_id, $selected_lang, true ); |
|
5852 if ( $msgstrs_arr ) { |
|
5853 foreach ( $msgstrs_arr as $msgstrs ) { |
|
5854 wp_delete_post( $msgstrs->ID, false ) ; |
|
5855 } |
|
5856 } |
|
5857 |
|
5858 } else { |
|
5859 |
|
5860 // delete msgstr of this lang of $oneline->ID |
|
5861 $msgstrs = $xili_dictionary->get_cpt_msgstr( $one_id, $selected_lang, false ); |
|
5862 // clean msgid (inside delete_post) |
|
5863 |
|
5864 // delete str |
|
5865 if ( $msgstrs ) |
|
5866 wp_delete_post( $msgstrs->ID, false ) ; |
|
5867 } |
|
5868 break; |
|
5869 |
|
5870 case 'all_str': |
|
5871 |
|
5872 wp_delete_post( $one_id, false ) ; // id is cleaned by delete filter |
|
5873 |
|
5874 break; |
|
5875 } |
|
5876 } |
|
5877 return 'loop-full'; |
|
5878 } else { |
|
5879 return 'nolist'; |
|
5880 } |
|
5881 |
|
5882 } |
|
5883 |
|
5884 function caching_msgs_to_erase ( ) { |
|
5885 |
|
5886 $list = $this->get_msgs_to_erase ( 0 ) ; |
|
5887 |
|
5888 if ( $list ) { |
|
5889 $id_list = array(); |
|
5890 foreach ( $list as $one ) { |
|
5891 $id_list[] = $one->ID; |
|
5892 } |
|
5893 update_option( '_xd_cache_temp_array_IDs', $id_list ); |
|
5894 return count ( $list ); |
|
5895 } else { |
|
5896 return 0; |
|
5897 } |
|
5898 |
|
5899 |
|
5900 } |
|
5901 |
|
5902 |
|
5903 private static function get_msgs_to_erase ( $start ) { |
|
5904 global $xili_dictionary; |
|
5905 // sub-selection according msg origin (theme) |
|
5906 $origins = array(); |
|
5907 $listterms = get_terms( 'origin', array('hide_empty' => false) ); |
|
5908 foreach ( $listterms as $onetheme) { |
|
5909 if ( isset ( $_POST[ 'theme-'.$onetheme->term_id ] ) ) { |
|
5910 $origins[] = $onetheme->slug; |
|
5911 } |
|
5912 } |
|
5913 //error_log ( serialize ( $origins ) ); |
|
5914 $deletion_type = ''; |
|
5915 $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50; |
|
5916 |
|
5917 $only_local = ( isset ( $_POST['_xd_local'] ) ) ? true : false ; |
|
5918 |
|
5919 $selected_lang = ( isset ( $_POST['_xd_lang'] ) ) ? $_POST['_xd_lang'] : "" ; |
|
5920 |
|
5921 |
|
5922 // check origin checked |
|
5923 |
|
5924 if ( $selected_lang == "" && $only_local == false ) { |
|
5925 $query = array( |
|
5926 'numberposts' => -1, 'offset' => 0, |
|
5927 'category' => 0, 'orderby' => 'ID', |
|
5928 'order' => 'ASC', 'include' => array(), |
|
5929 'exclude' => array(), 'post_type' => XDMSG, |
|
5930 'suppress_filters' => true |
|
5931 ); |
|
5932 $deletion_type = 'all'; |
|
5933 |
|
5934 } else if ( ( $selected_lang == "" || $selected_lang == "all-lang" ) && $only_local == true ) { |
|
5935 |
|
5936 $query = array( |
|
5937 'numberposts' => -1, 'offset' => 0, |
|
5938 'category' => 0, 'orderby' => 'ID', |
|
5939 'order' => 'ASC', 'include' => array(), |
|
5940 'exclude' => array(), 'post_type' => XDMSG, |
|
5941 'suppress_filters' => true, |
|
5942 'meta_query' => array( |
|
5943 'relation' => 'AND', |
|
5944 array( |
|
5945 'key' => $xili_dictionary->msgtype_meta, |
|
5946 'value' => 'msgid', |
|
5947 'compare' => '=' |
|
5948 ), |
|
5949 array( |
|
5950 'key' => $xili_dictionary->msg_extracted_comments, |
|
5951 'value' => $xili_dictionary->local_tag, |
|
5952 'compare' => 'LIKE' |
|
5953 ) |
|
5954 ) |
|
5955 ); |
|
5956 $deletion_type = 'only_local'; |
|
5957 |
|
5958 } else if ( $selected_lang == "all-lang" && $only_local == false ) { |
|
5959 |
|
5960 $query = array( |
|
5961 'numberposts' => -1, 'offset' => 0, |
|
5962 'category' => 0, 'orderby' => 'ID', |
|
5963 'order' => 'ASC', 'include' => array(), |
|
5964 'exclude' => array(), 'post_type' => XDMSG, |
|
5965 'suppress_filters' => true, |
|
5966 'meta_query' => array( |
|
5967 array( |
|
5968 'key' => $xili_dictionary->msgtype_meta, |
|
5969 'value' => array( 'msgstr', 'msgstr_0', 'msgstr_1' ), |
|
5970 'compare' => 'IN' |
|
5971 ) |
|
5972 ) |
|
5973 ); |
|
5974 |
|
5975 $deletion_type = 'all_str'; |
|
5976 |
|
5977 } else if ( $selected_lang != "" && $selected_lang != "all-lang" ) { |
|
5978 |
|
5979 |
|
5980 // only msgstr |
|
5981 $query = array( |
|
5982 'numberposts' => -1, 'offset' => 0, |
|
5983 'category' => 0, 'orderby' => 'ID', |
|
5984 'order' => 'ASC', 'include' => array(), |
|
5985 'exclude' => array(), 'post_type' => XDMSG, |
|
5986 'suppress_filters' => true, |
|
5987 'meta_query' => array( |
|
5988 'relation' => 'AND', |
|
5989 array( |
|
5990 'key' => $xili_dictionary->msgtype_meta, |
|
5991 'value' => 'msgid', |
|
5992 'compare' => '=' |
|
5993 ), |
|
5994 array( |
|
5995 'key' => $xili_dictionary->msglang_meta, |
|
5996 'value' => $selected_lang, |
|
5997 'compare' => 'LIKE' |
|
5998 ) |
|
5999 ) |
|
6000 ); |
|
6001 |
|
6002 if ( $only_local ) { |
|
6003 |
|
6004 $query['meta_query'][] = array( |
|
6005 'key' => $xili_dictionary->msg_extracted_comments, |
|
6006 'value' => $xili_dictionary->local_tag, |
|
6007 'compare' => 'LIKE' |
|
6008 ); |
|
6009 } |
|
6010 |
|
6011 |
|
6012 |
|
6013 $deletion_type = 'str_one_lang'; |
|
6014 } |
|
6015 |
|
6016 if ( $origins != array() ) { |
|
6017 |
|
6018 if ( count ( $origins ) == 1 ) { |
|
6019 |
|
6020 $array_tax = array( |
|
6021 'taxonomy' => 'origin', |
|
6022 'field' => 'slug', |
|
6023 'terms' => $origins[0] |
|
6024 ); |
|
6025 |
|
6026 } else { |
|
6027 |
|
6028 $array_tax = array( |
|
6029 'taxonomy' => 'origin', |
|
6030 'field' => 'slug', |
|
6031 'terms' => $origins, |
|
6032 'operator' => 'IN' |
|
6033 ); |
|
6034 } |
|
6035 $query['tax_query'] = array( $array_tax ) ; |
|
6036 |
|
6037 } |
|
6038 |
|
6039 $listdictiolines = get_posts( $query ); |
|
6040 |
|
6041 if ( $listdictiolines ) { |
|
6042 update_option( '_xd_deletion_type', $deletion_type ); |
|
6043 return $listdictiolines; |
|
6044 } else { |
|
6045 return false; |
|
6046 } |
|
6047 } |
|
6048 |
|
6049 /**** importing new UI *****/ |
|
6050 // since 2.3 |
|
6051 |
|
6052 function xili_dictionary_import() { |
|
6053 ?> |
|
6054 |
|
6055 <div class="wrap"> |
|
6056 |
|
6057 <?php screen_icon( 'tools' ); ?> |
|
6058 |
|
6059 <h2 class="nav-tab-wrapper"><?php _e( 'Importing files (.po, .pot, .mo)', 'xili-dictionary' ); ?></h2> |
|
6060 |
|
6061 <form action="#" method="post" id="xd-looping-settings"> |
|
6062 |
|
6063 <?php settings_fields( 'xd_importing' ); delete_option( '_xd_importing_step'); ?> |
|
6064 |
|
6065 <?php do_settings_sections( 'xd_importing' ); ?> |
|
6066 |
|
6067 <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> |
|
6068 <p class="submit"> |
|
6069 <input type="button" name="submit" class="button-primary" id="xd-looping-start" value="<?php _e( 'Start importing', 'xili-dictionary' ); ?>" onclick="xd_importing_start()" /> |
|
6070 <input type="button" name="submit" class="button-primary" id="xd-looping-stop" value="<?php _e( 'Stop', 'xili-dictionary' ); ?>" onclick="xd_importing_stop()" /> |
|
6071 <img id="xd-looping-progress" src=""> |
|
6072 </p> |
|
6073 |
|
6074 <div class="xd-looping-updated" id="xd-looping-message"></div> |
|
6075 </form> |
|
6076 </div> |
|
6077 <script type="text/javascript"> |
|
6078 //<![CDATA[ |
|
6079 <?php |
|
6080 if ( function_exists('the_theme_domain') ) {// in new xili-language |
|
6081 echo 'var potfile = "'.the_theme_domain().'";'; |
|
6082 } else { |
|
6083 echo 'var potfile = "'.$this->get_theme_name(false).'";'; |
|
6084 } |
|
6085 ?> |
|
6086 jQuery(document).ready( function() { |
|
6087 |
|
6088 function bbtvalue ( pot ) { |
|
6089 var x = jQuery('#_xd_file_extend').val(); |
|
6090 var lo = jQuery('#_xd_local').val(); |
|
6091 var la = jQuery('#_xd_lang').val(); |
|
6092 var t = '<?php echo esc_js(__( 'Start importing', 'xili-dictionary' )); ?>'; |
|
6093 if ( jQuery('#_xd_local').is(':checked') ) { |
|
6094 jQuery("#xd-looping-start").val( t+" : "+lo+"-"+la+'.'+x ); |
|
6095 } else { |
|
6096 jQuery("#xd-looping-start").val( t+' : '+la+'.'+x+pot ); |
|
6097 } |
|
6098 } |
|
6099 |
|
6100 jQuery('#_xd_file_extend').change(function() { |
|
6101 var x = jQuery(this).val(); |
|
6102 if ( x == 'po') { |
|
6103 jQuery('#po-comment-option').show(); |
|
6104 jQuery("#_xd_lang").append( new Option( potfile+'.pot', potfile) ); |
|
6105 } else { |
|
6106 jQuery('#po-comment-option').hide(); |
|
6107 jQuery("#_xd_lang").find("option[value='"+potfile+"']").remove(); |
|
6108 } |
|
6109 bbtvalue (''); |
|
6110 }); |
|
6111 |
|
6112 jQuery('#_xd_local').change(function() { |
|
6113 bbtvalue ( '' ); |
|
6114 }); |
|
6115 |
|
6116 jQuery('#_xd_lang').change(function() { |
|
6117 var x = jQuery(this).val(); |
|
6118 t = ''; |
|
6119 if ( potfile == x ) { |
|
6120 t = 't'; |
|
6121 jQuery('#_xd_local').attr('checked',false); |
|
6122 jQuery('#_xd_local').prop('disabled',true); |
|
6123 } else { |
|
6124 jQuery('#_xd_local').prop('disabled',false); |
|
6125 }; |
|
6126 bbtvalue ( t ); |
|
6127 }); |
|
6128 |
|
6129 |
|
6130 var x = jQuery('#_xd_file_extend').val(); |
|
6131 if ( x == 'po' ) { |
|
6132 jQuery('#po-comment-option').show(); |
|
6133 jQuery("#_xd_lang").append( new Option( potfile+'.pot', potfile ) ); |
|
6134 } else { |
|
6135 jQuery('#po-comment-option').hide(); |
|
6136 jQuery("#_xd_lang").find("option[value='"+potfile+"']").remove(); |
|
6137 } |
|
6138 |
|
6139 bbtvalue (''); |
|
6140 |
|
6141 }); |
|
6142 //]]> |
|
6143 </script> |
|
6144 <?php |
|
6145 } |
|
6146 |
|
6147 function xd_importing_init_settings () { |
|
6148 add_settings_section( 'xd_importing_main', __( 'Importing the files', 'xili-dictionary' ), array(&$this,'xd_importing_setting_callback_main_section'), 'xd_importing' ); |
|
6149 |
|
6150 // |
|
6151 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' ); |
|
6152 register_setting( 'xd_importing_main', '_xd_importing_type', '_xd_importing_type_define' ); |
|
6153 |
|
6154 // ajax section |
|
6155 add_settings_section( 'xd_importing_tech', __( 'Technical settings', 'xili-dictionary' ), array(&$this,'xd_setting_callback_tech_section'), 'xd_importing' ); |
|
6156 |
|
6157 // erasing rows step |
|
6158 add_settings_field( '_xd_looping_rows', __( 'Entries step', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_row'), 'xd_importing', 'xd_importing_tech' ); |
|
6159 register_setting( 'xd_importing_tech', '_xd_looping_rows', 'sanitize_title' ); |
|
6160 |
|
6161 // Delay Time |
|
6162 add_settings_field( '_xd_looping_delay_time', __( 'Delay Time', 'xili-dictionary' ), array(&$this,'xd_erasing_setting_callback_delay_time'), 'xd_importing', 'xd_importing_tech' ); |
|
6163 register_setting ( 'xd_importing_tech', '_xd_looping_delay_time', 'intval' ); |
|
6164 |
|
6165 } |
|
6166 |
|
6167 function xd_setting_callback_tech_section () { |
|
6168 ?> |
|
6169 <p><?php _e( "These settings below are reserved for future uses, leave values 'as is'.", 'xili-dictionary' ); ?></p> |
|
6170 <?php |
|
6171 } |
|
6172 |
|
6173 |
|
6174 /** |
|
6175 * Main settings section description for the settings page |
|
6176 * |
|
6177 * @since |
|
6178 */ |
|
6179 function xd_importing_setting_callback_main_section() { |
|
6180 $extend = ( isset( $_GET['extend'] ) ) ? $_GET['extend'] : 'po'; |
|
6181 ?> |
|
6182 |
|
6183 <p><?php printf(__( "Here it is possible to import the .%s file inside the dictionary.", 'xili-dictionary' ), '<strong>' . $extend . '</strong>' ) ; ?></p> |
|
6184 |
|
6185 <?php |
|
6186 } |
|
6187 |
|
6188 function xd_file_importing_setting_callback_row() { |
|
6189 $extend = ( isset( $_GET['extend'] ) ) ? $_GET['extend'] : 'po'; |
|
6190 // pop up to build |
|
6191 ?> |
|
6192 <div class="sub-field"> |
|
6193 <label for="_xd_file_extend"><?php _e( 'Type', 'xili-dictionary' ); ?>: <strong>.</strong></label> |
|
6194 <select name="_xd_file_extend" id="_xd_file_extend" class='postform'> |
|
6195 <option value="" <?php selected( "", $extend ); ?>> <?php _e('Select type...','xili-dictionary') ?> </option> |
|
6196 <option value="po" <?php selected( "po", $extend ); ?>> <?php _e('PO file','xili-dictionary') ?> </option> |
|
6197 <option value="mo" <?php selected( "mo", $extend ); ?>> <?php _e('MO file','xili-dictionary') ?> </option> |
|
6198 </select> |
|
6199 |
|
6200 <p class="description"><?php _e( 'Type of file: .mo or .po', 'xili-dictionary' ); ?></p> |
|
6201 </div> |
|
6202 <?php // _xd_multi_local |
|
6203 if ( is_multisite() && is_super_admin() && !$this->xililanguage_ms ) { |
|
6204 ?> |
|
6205 <div class="sub-field"> |
|
6206 <label for="_xd_multi_local"><?php _e( 'Folder', 'xili-dictionary' ); ?>: </label> |
|
6207 <select name="_xd_multi_local" id="_xd_multi_local" class='postform'> |
|
6208 <option value="blog-dir"> <?php _e('Site file (blogs.dir)','xili-dictionary') ?> </option> |
|
6209 <option value="theme-dir"> <?php _e('Original theme file','xili-dictionary') ?> </option> |
|
6210 </select> |
|
6211 |
|
6212 <p class="description"><?php _e( 'As superadmin, define origin of file', 'xili-dictionary' ); ?></p> |
|
6213 </div> |
|
6214 <?php |
|
6215 } |
|
6216 // local file |
|
6217 ?> |
|
6218 <div class="sub-field"> |
|
6219 <input id="_xd_local" name="_xd_local" type="checkbox" id="_xd_local" value="local" <?php checked( ( $extend == 'mo' ) ); ?> /> |
|
6220 <label for="_xd_local"><?php _e( 'Locale msgs', 'xili-dictionary' ); ?></label> |
|
6221 <p class="description"><?php _e( 'Import locale file (local-xx_YY)', 'xili-dictionary' ); ?></p> |
|
6222 </div> |
|
6223 <?php |
|
6224 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
|
6225 ?> |
|
6226 <div class="sub-field"> |
|
6227 <label for="_xd_lang"><?php _e( 'Language', 'xili-dictionary' ); ?>: </label> |
|
6228 <select name="_xd_lang" id="_xd_lang" class='postform'> |
|
6229 <option value=""> <?php _e('Select language','xili-dictionary') ?> </option> |
|
6230 |
|
6231 <?php |
|
6232 foreach ($listlanguages as $language) { |
|
6233 $selected = ( isset ( $_GET[QUETAG] ) && $language->name == $_GET[QUETAG] ) ? "selected=selected" : "" ; |
|
6234 echo '<option value="'.$language->name.'" '.$selected.' >'.__($language->description, 'xili-dictionary').'</option>'; |
|
6235 } |
|
6236 |
|
6237 ?> |
|
6238 </select> |
|
6239 <p class="description"><?php _e( 'Language of the file', 'xili-dictionary' ); ?></p> |
|
6240 </div> |
|
6241 <div class="sub-field"> |
|
6242 <label for="_origin_theme"><?php _e( 'Name of current theme', 'xili-dictionary' ); ?> : <?php echo $this->get_theme_name(false); ?></label> |
|
6243 <input id="_origin_theme" name="_origin_theme" type="hidden" id="_origin_theme" value="<?php echo $this->get_theme_name(false); ?>" /> |
|
6244 <p class="description"><?php _e( 'Used to assign origin taxonomy', 'xili-dictionary' ); ?></p> |
|
6245 </div> |
|
6246 <?php |
|
6247 |
|
6248 ?> |
|
6249 |
|
6250 |
|
6251 |
|
6252 <?php |
|
6253 //if ( $extend == 'po' ) { |
|
6254 ?> |
|
6255 <div id="po-comment-option" class="sub-field" style="display:none;" > |
|
6256 <label for="_importing_po_comments"> <?php _e( 'What about comments', 'xili-dictionary' ); ?>: |
|
6257 <select name="_importing_po_comments" id="_importing_po_comments"> |
|
6258 <option value="" ><?php _e('No change','xili-dictionary'); ?></option> |
|
6259 <option value="replace" ><?php _e('Imported comments replace those in list','xili-dictionary'); ?></option> |
|
6260 <option value="append" ><?php _e('Imported comments be appended...','xili-dictionary'); ?></option> |
|
6261 </select> |
|
6262 </label> |
|
6263 </div> |
|
6264 <?php |
|
6265 //} |
|
6266 } |
|
6267 |
|
6268 function _xd_importing_type_define( $input ) { |
|
6269 return $input; |
|
6270 } |
|
6271 |
|
6272 function importing_process_callback () { |
|
6273 check_ajax_referer( 'xd_importing_process' ); |
|
6274 |
|
6275 if ( ! ini_get( 'safe_mode' ) ) { |
|
6276 set_time_limit( 0 ); |
|
6277 ini_set( 'memory_limit', '256M' ); |
|
6278 ini_set( 'implicit_flush', '1' ); |
|
6279 ignore_user_abort( true ); |
|
6280 } |
|
6281 |
|
6282 // Save step and count so that it can be restarted. |
|
6283 if ( ! get_option( '_xd_importing_step' ) ) { |
|
6284 update_option( '_xd_importing_step', 1 ); |
|
6285 update_option( '_xd_importing_start', 0 ); |
|
6286 } |
|
6287 |
|
6288 $step = (int) get_option( '_xd_importing_step', 1 ); |
|
6289 $min = (int) get_option( '_xd_importing_start', 0 ); |
|
6290 $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50; |
|
6291 $max = ( $min + $count ) - 1; |
|
6292 $start = $min; |
|
6293 |
|
6294 |
|
6295 |
|
6296 $pomofile = ""; // future use |
|
6297 $lang = ( ! empty( $_POST['_xd_lang'] ) ) ? $_POST['_xd_lang'] : 'en_US'; |
|
6298 $type = ( ! empty( $_POST['_xd_file_extend'] ) ) ? $_POST['_xd_file_extend'] : 'po'; |
|
6299 $local_file = ( ! empty( $_POST['_xd_local'] ) ) ? $_POST['_xd_local'] : ''; |
|
6300 $local_file2 = ( $local_file == '' ) ? '' : $local_file.'-' ; |
|
6301 $multilocal = ( $_POST['_xd_multi_local'] == 'blog-dir' ) ? true : false; // find in original theme in multisite |
|
6302 |
|
6303 switch ( $step ) { |
|
6304 |
|
6305 // STEP 1. Clean all tables. |
|
6306 case 1 : |
|
6307 $count_entries = $this->caching_file( $type, $lang, $local_file, $pomofile, $multilocal ); |
|
6308 if ( false != $count_entries ) { |
|
6309 update_option( '_xd_importing_step', $step + 1 ); |
|
6310 update_option( '_xd_importing_start', 0 ); |
|
6311 update_option( '_xd_importing_count_entries', $count_entries ); |
|
6312 |
|
6313 $this->looping_output( sprintf( __('File %3$s%2$s.%1$s found ! (%4$s entries)', 'xili-dictionary' ), $type, $lang, $local_file2, $count_entries ) ); |
|
6314 } else { |
|
6315 delete_option( '_xd_importing_step' ); |
|
6316 delete_option( '_xd_importing_start' ); |
|
6317 delete_option( '_xd_cache_pomo_file' ); |
|
6318 delete_option( '_xd_importing_count_entries'); |
|
6319 if ( false === strpos( $lang , '_' ) && $type == 'po' ) { $type = 'pot'; } // special case |
|
6320 $this->looping_output( sprintf( __('Impossible to find file %3$s%2$s.%1$s (%4$s)', 'xili-dictionary' ), $type, $lang, $local_file2, $pomofile ), 'error' ); |
|
6321 } |
|
6322 break; |
|
6323 |
|
6324 // STEP 2. Loop |
|
6325 case 2 : |
|
6326 |
|
6327 if ( $this->importing_msgs( $start, $lang ) ) { |
|
6328 update_option( '_xd_importing_step', $step + 1 ); |
|
6329 update_option( '_xd_importing_start', 0 ); |
|
6330 if ( empty( $start ) ) { |
|
6331 |
|
6332 $this->looping_output( __( 'No msgs to import', 'xili-dictionary' ), 'error' ); |
|
6333 } |
|
6334 |
|
6335 } else { |
|
6336 update_option( '_xd_importing_start', $max + 1 ); |
|
6337 |
|
6338 $count_entries = get_option( '_xd_importing_count_entries', $max + 1 ); |
|
6339 $end = ( $count_entries > $max ) ? $max + 1 : $count_entries ; |
|
6340 $this->looping_output( sprintf( __( 'Importing msgs (%1$s - %2$s)', 'xili-dictionary' ), $min, $end ) ); |
|
6341 |
|
6342 } |
|
6343 break; |
|
6344 |
|
6345 default : |
|
6346 delete_option( '_xd_importing_step' ); |
|
6347 delete_option( '_xd_importing_start' ); |
|
6348 delete_option( '_xd_cache_pomo_file' ); |
|
6349 delete_option( '_xd_importing_count_entries'); |
|
6350 |
|
6351 $this->looping_output( __( 'Importation Complete', 'xili-dictionary' ), 'success' ); |
|
6352 |
|
6353 break; |
|
6354 |
|
6355 } |
|
6356 |
|
6357 } |
|
6358 |
|
6359 private static function caching_file( $type, $lang, $local_file = '', $pomofile = '', $multilocal = true ) { |
|
6360 global $xili_dictionary; // called by ajax |
|
6361 |
|
6362 // search file |
|
6363 $temp_po = $xili_dictionary->import_POMO ( $type, $lang, $local_file, $pomofile, $multilocal ); |
|
6364 if ( false !== $temp_po ) { |
|
6365 // cache file |
|
6366 update_option( '_xd_cache_pomo_file', $temp_po ); |
|
6367 |
|
6368 return count ( $temp_po->entries ) ; |
|
6369 } else { |
|
6370 return false; |
|
6371 } |
|
6372 } |
|
6373 |
|
6374 private static function importing_msgs( $start, $lang ) { |
|
6375 global $xili_dictionary; // called by ajax |
|
6376 |
|
6377 $count = (int) ! empty( $_POST['_xd_looping_rows'] ) ? $_POST['_xd_looping_rows'] : 50; |
|
6378 $importing_po_comments = ( isset ( $_POST['_importing_po_comments'] ) ) ? $_POST['_importing_po_comments'] : '' ; |
|
6379 $origin_theme = $_POST['_origin_theme']; |
|
6380 //$temp_po = $xili_dictionary->pomo_import_PO ( $lang ); |
|
6381 |
|
6382 $temp_po = get_option( '_xd_cache_pomo_file', false ); |
|
6383 $count_entries = count( $temp_po->entries ); |
|
6384 if ( false !== $temp_po && ( $start < $count_entries ) ) { |
|
6385 $i = 0; |
|
6386 foreach ( $temp_po->entries as $pomsgid => $pomsgstr ) { |
|
6387 $i++; |
|
6388 if ( $i < $start ) continue; |
|
6389 if ( $i > ($start + $count) -1 ) break; |
|
6390 if ( $i > $count_entries ) break; |
|
6391 |
|
6392 $lines = $xili_dictionary->pomo_entry_to_xdmsg ( $pomsgid, $pomsgstr, $lang, array( 'importing_po_comments'=>$importing_po_comments, 'origin_theme'=>$origin_theme ) ); |
|
6393 |
|
6394 //error_log ( $i . '------------->' . $pomsgstr->singular .'---ID--'. $lines[0] . '---STR--' . $lines[1] ); |
|
6395 |
|
6396 } |
|
6397 |
|
6398 //error_log ('count='.count( $temp_po->entries ).' start='.$start); |
|
6399 return false; |
|
6400 } |
|
6401 return true; |
|
6402 } |
|
6403 |
|
6404 |
|
6405 |
|
6406 |
|
5032 } /* end of class */ |
6407 } /* end of class */ |
5033 |
6408 |
5034 |
6409 |
5035 /** |
6410 /** |
5036 * filter wp_upload_dir (/wp-includes/functions.php) |
6411 * filter wp_upload_dir (/wp-includes/functions.php) |