1 <?php |
1 <?php |
2 /* |
2 /* |
3 Plugin Name: xili-dictionary |
3 Plugin Name: xili-dictionary |
4 Plugin URI: http://dev.xiligroup.com/xili-dictionary/ |
4 Plugin URI: http://dev.xiligroup.com/xili-dictionary/ |
5 Description: ONLY for >= WP 2.8. This plugin is a tool using wordpress's taxonomy for localized themes or multilingual themes managed by xili-language - a powerful tool to create .mo file(s) on the fly in the theme's folder and more... - |
5 Description: A tool using wordpress's CPT and taxonomy for localized themes or multilingual themes managed by xili-language - a powerful tool to create .mo file(s) on the fly in the theme's folder and more... - ONLY for >= WP 3.2.1 - |
6 Author: MS |
6 Author: dev.xiligroup - MS |
7 Version: 1.0.3 |
7 Version: 2.2.0 |
8 Author URI: http://dev.xiligroup.com |
8 Author URI: http://dev.xiligroup.com |
|
9 License: GPLv2 |
|
10 Text Domain: xili-dictionary |
|
11 Domain Path: /languages/ |
9 */ |
12 */ |
10 |
13 |
11 # beta 1.0.3 - fixes some directories issues in (rare) xamp servers and in theme's terms import. Create .po with empty translations. |
14 # 2.2.0 - 120922 - fixes issues with .mo and .po inserts - better messages and warning |
12 # beta 1.0.2 - JS and vars, create lang list, if xili-language absent, for international themes - lot of fixes |
15 # 2.1.3 - 120728 - fixes |
13 # beta 1.0.1 - add scripts for form with plural msg (id or str) |
16 # 2.1.2 - 120715 - list in msg edit - new query - new metabox - new pointers - ... |
14 # beta 1.0.0 - use pomo libraries and classes - ONLY >= 2.8 |
17 # 2.1.1 - 120710 - fixes - new icons |
15 # beta 0.9.9 - fixes existing msgid terms - better log display when importing theme's terms |
18 # 2.1.0 - 120507 - options to save on new local-xx_XX.mo and more... needs XL 2.6 |
16 # beta 0.9.8.2 - more html tags in msg str or id |
19 # 2.0.0 - 120417 - repository as current |
17 # beta 0.9.8.1 - some fixes for IIS server and PHP 5.2.1 |
20 # beta 2.0.0-rc4 - 120415 - fixes |
18 # beta 0.9.8 - WP 2.8 - fix query error |
21 # beta 2.0.0-rc3 - 120406 - pre-tests WP3.4: fixes metaboxes columns, conditional edit link in list |
19 # beta 0.9.7.3 <- to - see readme.txt - from 0.9.4 |
22 # beta 2.0.0-rc2 - 120402 - latest fixes (writers) |
|
23 # beta 2.0.0-rc1 - 120318 - before svn |
|
24 # beta 2.0.0 - 120219 - new way of saving lines in CPT |
|
25 |
|
26 |
|
27 # |
|
28 # now msg lines full commented as in .po |
|
29 # now translated lines (msgstr) attached to same taxonomy as xili-language |
|
30 # before upgrading from 1.4.4 to 2.0, export all the dictionary in .po files and empty the dictionary. |
|
31 # |
|
32 # beta 1.4.4 - 111221 - fixes |
|
33 # between 0.9.3 and 1.4.4 see version 1.4.4 - 20120219 |
20 # beta 0.9.3 - first published - 090131 MS |
34 # beta 0.9.3 - first published - 090131 MS |
21 |
35 |
22 |
36 |
23 # This plugin is free software; you can redistribute it and/or |
37 define('XILIDICTIONARY_VER','2.2.0'); |
24 # modify it under the terms of the GNU Lesser General Public |
|
25 # License as published by the Free Software Foundation; either |
|
26 # version 2.1 of the License, or (at your option) any later version. |
|
27 # |
|
28 # This plugin is distributed in the hope that it will be useful, |
|
29 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
31 # Lesser General Public License for more details. |
|
32 # |
|
33 # You should have received a copy of the GNU Lesser General Public |
|
34 # License along with this plugin; if not, write to the Free Software |
|
35 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
36 |
|
37 define('XILIDICTIONARY_VER','1.0.3'); |
|
38 |
38 |
39 include_once(ABSPATH . WPINC . '/pomo/po.php'); /* not included in wp-settings */ |
39 include_once(ABSPATH . WPINC . '/pomo/po.php'); /* not included in wp-settings */ |
40 |
40 |
|
41 // the class |
41 class xili_dictionary { |
42 class xili_dictionary { |
42 |
43 |
|
44 var $plugin_url = ''; // Url to this plugin - see construct |
|
45 var $plugin_path = ''; // The path to this plugin - see construct |
|
46 |
43 var $subselect = ''; /* used to subselect by msgid or languages*/ |
47 var $subselect = ''; /* used to subselect by msgid or languages*/ |
|
48 var $searchtranslated = ''; /* used to search untranslated - 2.1.2 */ |
|
49 var $languages_key_slug = array(); // used for slug to other items |
|
50 var $msg_action_message = ''; |
44 var $xililanguage = ''; /* neveractive isactive wasactive */ |
51 var $xililanguage = ''; /* neveractive isactive wasactive */ |
|
52 var $xililanguage_ms = false; // xlms |
45 var $tempoutput = ""; |
53 var $tempoutput = ""; |
46 var $langfolder ='/'; /* where po or mo files */ |
54 var $langfolder =''; /* where po or mo files */ |
47 var $xili_settings; /* saved in options */ |
55 var $xili_settings; /* saved in options */ |
48 var $ossep = "/"; /* for recursive file search in xamp */ |
56 var $ossep = "/"; /* for recursive file search in xamp */ |
49 |
57 |
50 function xili_dictionary($langsfolder = '/') { |
58 // 2.0 new vars |
|
59 var $xdmsg = "xdmsg"; |
|
60 var $xd_settings_page = "edit.php?post_type=xdmsg&page=dictionary_page"; // now in CPT menu |
|
61 |
|
62 // post meta |
|
63 var $ctxt_meta = '_xdmsg_ctxt'; // to change to xdctxt |
|
64 var $msgtype_meta = '_xdmsg_msgtype'; // to hidden |
|
65 var $msgchild_meta = '_xdmsg_msgchild'; |
|
66 var $msglang_meta = '_xdmsg_msglangs'; |
|
67 var $msgidlang_meta = '_xdmsg_msgid_id'; // origin of the msgstr |
|
68 var $msg_extracted_comments = '_xdmsg_extracted_comments'; |
|
69 var $msg_translator_comments = '_xdmsg_translator_comments'; |
|
70 var $msg_flags = '_xdmsg_flags'; |
|
71 |
|
72 var $origin_theme = ""; // used when importing |
|
73 var $local_tag = '[local]'; |
|
74 var $exists_style_ext = false; // wp_enqueue_style( 'xili_dictionary_stylesheet' ); |
|
75 var $style_message = ''; |
|
76 var $xilidev_folder = '/xilidev-libraries'; //must be in plugins |
|
77 |
|
78 var $theme_mos = array(); // $this->get_pomo_from_theme(); |
|
79 var $local_mos = array() ; // $this->get_pomo_from_theme( true ); // 2.1 |
|
80 // is_multisite |
|
81 var $file_site_mos = array() ; // $this->get_pomo_from_site(); // since 1.2.0 - mo of site |
|
82 var $file_site_local_mos = array() ; // $this->get_pomo_from_site( true ); |
|
83 |
|
84 var $default_langs_array = array(); // default languages |
|
85 var $internal_list = false; // created by xl or xd |
|
86 |
|
87 var $importing_mode = false ; // for new action by hand ( action save when new ) |
|
88 var $msg_str_labels = array ( |
|
89 'msgid' => 'msgid', 'msgid_plural' => 'msgid_plural', |
|
90 'msgstr' => 'msgstr', 'msgstr_0' => 'msgstr[0]', |
|
91 'msgstr_1' => 'msgstr[1]', 'msgstr_2' => 'msgstr[2]', |
|
92 'msgstr_3' => 'msgstr[3]', 'msgstr_4' => 'msgstr[4]' |
|
93 ) ; |
|
94 var $importing_po_comments = '' ; // mode replace or append 2.0-rc2 |
|
95 var $create_line_lang = ''; // line between box |
|
96 |
|
97 var $langs_group_id; /* group ID and Term Taxo ID */ |
|
98 var $langs_group_tt_id; |
|
99 |
|
100 |
|
101 |
|
102 public function xili_dictionary( $langsfolder = '/' ) { // ?? php4 |
|
103 $this->__construct( $langsfolder ); |
|
104 } |
|
105 |
|
106 public function __construct( $langsfolder = '/' ) { |
|
107 global $wp_version; |
51 /* activated when first activation of plug */ |
108 /* activated when first activation of plug */ |
52 register_activation_hook(__FILE__,array(&$this,'xili_dictionary_activation')); |
109 // 2.0 |
|
110 define ( 'XDMSG', $this->xdmsg ); // CPT to change from msg to xdmsg (less generic) 20120217 |
|
111 |
|
112 $this->plugin_path = plugin_dir_path(__FILE__) ; |
|
113 $this->plugin_url = plugins_url('', __FILE__) ; |
|
114 |
|
115 register_activation_hook( __FILE__, array( &$this,'xili_dictionary_activation') ); |
|
116 |
53 $this->ossep = strtoupper(substr(PHP_OS,0,3)=='WIN')?'\\':'/'; /* for rare xamp servers*/ |
117 $this->ossep = strtoupper(substr(PHP_OS,0,3)=='WIN')?'\\':'/'; /* for rare xamp servers*/ |
|
118 |
54 /* get current settings - name of taxonomy - name of query-tag */ |
119 /* get current settings - name of taxonomy - name of query-tag */ |
55 $this->xililanguage_state(); |
120 $this->xililanguage_state(); |
56 $this->xili_settings = get_option('xili_dictionary_settings'); |
121 $this->xili_settings = get_option('xili_dictionary_settings'); |
57 if(empty($this->xili_settings)) { |
122 if(empty($this->xili_settings) || $this->xili_settings['taxonomy'] != 'dictionary') { // to fix |
58 $this->xili_dictionary_activation(); |
123 $this->xili_dictionary_activation(); |
59 $this->xili_settings = get_option('xili_dictionary_settings'); |
124 $this->xili_settings = get_option('xili_dictionary_settings'); |
60 } |
125 } |
61 define('DTAXONAME',$this->xili_settings['taxonomy']); |
|
62 define('XDDICTLANGS','xl-'.DTAXONAME.'-langs'); |
|
63 /** * @since 1.0 */ |
|
64 define('XPLURAL','[XPLURAL]'); /* to separate singular and plural entries */ |
|
65 |
|
66 |
|
67 /* add new taxonomy in available taxonomies here dictionary terms */ |
|
68 register_taxonomy( DTAXONAME, 'post',array('hierarchical' => true, 'update_count_callback' => '')); |
|
69 /* groups of terms by langs */ |
|
70 register_taxonomy( XDDICTLANGS, 'term',array('hierarchical' => false, 'update_count_callback' => '')); |
|
71 |
126 |
72 /* test if version changed */ |
127 /* test if version changed */ |
73 $version = $this->xili_settings['version']; |
128 $version = $this->xili_settings['version']; |
74 if ($version <= '0.2') { |
129 if ( $version <= '0.2' ) { |
75 /* update relationships for grouping existing dictionary terms */ |
130 /* update relationships for grouping existing dictionary terms */ |
76 $this->update_terms_langs_grouping(); |
131 $this->update_terms_langs_grouping(); |
77 $this->xili_settings['version'] = '1.0'; |
132 $this->xili_settings['version'] = '1.0'; |
78 update_option('xili_dictionary_settings', $this->xili_settings); |
133 update_option('xili_dictionary_settings', $this->xili_settings); |
79 } |
134 } |
|
135 if ( $version == '1.0' ) { |
|
136 $this->xili_settings['external_xd_style'] = "off"; |
|
137 $this->xili_settings['version'] = '2.0'; |
|
138 update_option('xili_dictionary_settings', $this->xili_settings); |
|
139 } |
|
140 if ( $version == '2.0' ) { |
|
141 $this->update_postmeta_msgid(); |
|
142 $this->xili_settings['version'] = '2.1'; |
|
143 update_option('xili_dictionary_settings', $this->xili_settings); |
|
144 } |
|
145 |
80 $this->fill_default_languages_list(); |
146 $this->fill_default_languages_list(); |
81 /* Actions */ |
147 /* Actions */ |
82 add_action('admin_menu', array(&$this,'xili_add_dict_pages')); |
148 /* admin */ |
83 add_action('init', array(&$this, 'init_textdomain')); |
149 add_action( 'admin_init', array(&$this,'admin_init') ); // 1.3.0 |
84 add_filter('plugin_action_links', array(&$this,'xilidict_filter_plugin_actions'), 10, 2); |
150 add_action( 'admin_init', array(&$this,'ext_style_init') ); // 2.1 |
85 } |
151 add_action( 'admin_menu', array(&$this,'xili_add_dict_pages') ); |
|
152 |
|
153 add_action( 'add_meta_boxes', array(&$this, 'add_custom_box_in_post_msg') ); // 2.1.2 |
|
154 |
|
155 add_action( 'init', array(&$this, 'xili_dictionary_register_taxonomies')); // and init |
|
156 |
|
157 add_action( 'init', array(&$this, 'post_type_msg') ); |
|
158 |
|
159 if ( is_admin() ) { |
|
160 add_filter( 'manage_posts_columns', array(&$this,'xili_manage_column_name') ,9 , 1); |
|
161 add_filter( "manage_pages_custom_column", array(&$this,'xili_manage_column_row'), 9, 2); // hierarchic |
|
162 add_filter( 'manage_edit-'.XDMSG.'_sortable_columns', array(&$this,'msgcontent_column_register_sortable') ); |
|
163 add_filter( 'request', array(&$this,'msgcontent_column_orderby' ) ); |
|
164 |
|
165 if ( !class_exists ('xili_language' ) ) |
|
166 add_action( 'restrict_manage_posts', array(&$this,'restrict_manage_languages_posts') ); |
|
167 |
|
168 add_action( 'restrict_manage_posts', array(&$this,'restrict_manage_writer_posts'), 11 ); |
|
169 add_action( 'restrict_manage_posts', array(&$this,'restrict_manage_origin_posts'), 10 ); |
|
170 add_action( 'pre_get_posts', array(&$this,'wpse6066_pre_get_posts' ) ); |
|
171 |
|
172 |
|
173 add_action( 'wp_print_scripts', array(&$this,'auto_save_unsetting' ), 2 ); // before other |
|
174 |
|
175 add_filter( 'user_can_richedit', array(&$this, 'disable_richedit_for_cpt') ); |
|
176 |
|
177 if ( defined ('WP_DEBUG') && WP_DEBUG != true ) { |
|
178 add_filter( 'page_row_actions', array(&$this, 'remove_quick_edit'), 10, 1); // before to solve metas column |
|
179 } |
|
180 add_action( 'save_post', array(&$this, 'custom_post_type_title'),11 ,2); // |
|
181 add_action( 'save_post', array(&$this, 'msgid_post_new_create'),12 ,2 ); |
|
182 add_action( 'save_post', array(&$this, 'update_msg_comments'),13, 2 ); // comments and contexts |
|
183 add_filter( 'post_updated_messages', array(&$this, 'msg_post_messages')); |
|
184 |
|
185 add_action( 'before_delete_post', array(&$this, 'msgid_post_links_delete') ); |
|
186 add_action( 'admin_print_styles-post.php', array(&$this, 'print_styles_xdmsg_edit') ); |
|
187 add_action( 'admin_print_styles-post-new.php', array(&$this, 'print_styles_xdmsg_edit') ); |
|
188 |
|
189 add_action( 'admin_print_styles-post.php', array(&$this,'admin_enqueue_styles') ); |
|
190 add_action( 'admin_print_scripts-post.php', array(&$this,'admin_enqueue_scripts') ); |
|
191 |
|
192 add_action( 'admin_print_styles-edit.php', array(&$this, 'print_styles_xdmsg_list') ); // list of msgs |
|
193 |
|
194 add_action( 'admin_print_styles-xdmsg_page_dictionary_page', array(&$this, 'print_styles_xdmsg_tool') ); |
|
195 |
|
196 |
|
197 add_action( 'add_meta_boxes_' . XDMSG, array(&$this, 'msg_update_action')); // to locally update files from editing... |
|
198 } |
|
199 |
|
200 add_filter( 'plugin_action_links', array(&$this,'xilidict_filter_plugin_actions'), 10, 2); |
|
201 |
|
202 /* special to detect theme changing since 1.1.9 */ |
|
203 add_action( 'switch_theme', array(&$this,'xd_theme_switched') ); |
|
204 |
|
205 add_action( 'contextual_help', array(&$this,'add_help_text'), 10, 3 ); /* 1.2.2 */ |
|
206 |
|
207 |
|
208 if ( class_exists('xili_language_ms') ) $this->xililanguage_ms = true; // 1.3.4 |
|
209 |
|
210 } |
|
211 |
|
212 |
|
213 /* wp 3.0 WP-net */ |
|
214 function xili_dictionary_register_taxonomies () { |
|
215 |
|
216 if ( is_admin() ) { |
|
217 global $wp_roles; |
|
218 |
|
219 if ( current_user_can ('activate_plugins') ) { |
|
220 $wp_roles->add_cap ('administrator', 'xili_dictionary_set'); |
|
221 } |
|
222 } |
|
223 if (function_exists('is_child_theme') && is_child_theme() ) { // move here from init 1.4.1 |
|
224 if ( isset( $this->xili_settings['langs_in_root_theme'] ) && $this->xili_settings['langs_in_root_theme'] == 'root' ) { // for future uses |
|
225 $this->get_template_directory = get_template_directory(); |
|
226 } else { |
|
227 $this->get_template_directory = get_stylesheet_directory(); |
|
228 } |
|
229 } else { |
|
230 $this->get_template_directory = get_template_directory(); |
|
231 } |
|
232 $this->init_textdomain(); |
|
233 |
|
234 // new method for languages 2.0 |
|
235 $this->internal_list = $this->default_language_taxonomy (); |
|
236 |
|
237 if ( $this->internal_list ) { // test if empty |
|
238 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
|
239 if ( $listlanguages == array() ) { |
|
240 $this->create_default_languages(); |
|
241 } |
|
242 } |
|
243 $thegroup = get_terms( TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group')); |
|
244 if ( $thegroup != array() ) { // notice on first start |
|
245 $this->langs_group_id = $thegroup[0]->term_id; |
|
246 $this->langs_group_tt_id = $thegroup[0]->term_taxonomy_id; |
|
247 } |
|
248 } |
86 |
249 |
87 function xili_dictionary_activation() { |
250 function xili_dictionary_activation() { |
88 $this->xili_settings = get_option('xili_dictionary_settings'); |
251 $this->xili_settings = get_option('xili_dictionary_settings'); |
89 if(empty($this->xili_settings)) { |
252 if ( empty($this->xili_settings) || $this->xili_settings['taxonomy'] != 'dictionary') { // to fix |
90 $submitted_settings = array( |
253 $submitted_settings = array( |
91 'taxonomy' => 'dictionary', |
254 'taxonomy' => 'dictionary', |
92 'langs_folder' => '', |
255 'langs_folder' => '', |
93 'version' => '1.0' |
256 'external_xd_style' => 'off', |
|
257 'version' => '2.1' |
94 ); |
258 ); |
95 update_option('xili_dictionary_settings', $submitted_settings); |
259 update_option('xili_dictionary_settings', $submitted_settings); |
96 } |
260 } |
97 } |
261 } |
98 |
262 |
99 /** * add js in admin * @updated 1.0.2 */ |
263 function post_type_msg() { |
100 function xili_add_js() { |
264 |
101 wp_enqueue_script( 'xd-plural', '/'.PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/plural.php?var='.XPLURAL, array('jquery'), XILIDICTIONARY_VER); |
265 $labels = array( |
102 } |
266 'name' => _x('xili-dictionary©', 'post type general name', 'xili-dictionary'), |
103 |
267 'singular_name' => _x('Msg', 'post type singular name', 'xili-dictionary'), |
104 /** *add admin menu and associated page */ |
268 'add_new' => __('New msgid', 'xili-dictionary'), |
|
269 'add_new_item' => __('Add New Msgid', 'xili-dictionary'), |
|
270 'edit_item' => __('Edit Msg', 'xili-dictionary'), |
|
271 'new_item' => __('New Msg', 'xili-dictionary'), |
|
272 'view_item' => __('View Msg', 'xili-dictionary'), |
|
273 'search_items' => __('Search Msg', 'xili-dictionary'), |
|
274 'not_found' => __('No Msg found', 'xili-dictionary'), |
|
275 'not_found_in_trash' => __('No Msg found in Trash', 'xili-dictionary'), |
|
276 'parent_item_colon' => '' |
|
277 ); |
|
278 |
|
279 // impossible to see in front-end (no display in edit list) |
|
280 $args = array( |
|
281 'labels' => $labels, |
|
282 'public' => false, |
|
283 'publicly_queryable' => false, |
|
284 '_edit_link' => 'post.php?post=%d', |
|
285 '_builtin' => false, |
|
286 'show_ui' => true, |
|
287 'query_var' => true, |
|
288 'rewrite' => false, |
|
289 'capability_type' => 'post', |
|
290 'show_in_menu' => current_user_can ('xili_dictionary_set'), // ?? if not admin |
|
291 'hierarchical' => true, |
|
292 'menu_position' => null, |
|
293 'supports' => array('author','editor', 'excerpt','custom-fields','page-attributes'), |
|
294 'taxonomies' => array ('appearance', 'writer', 'origin' ), |
|
295 'rewrite' => array( 'slug' => XDMSG, 'with_front' => FALSE, ), |
|
296 'menu_icon' => plugins_url( 'images/xilidico-logo-16.jpg', __FILE__ ) // 16px16 |
|
297 ); |
|
298 register_post_type(XDMSG,$args); |
|
299 |
|
300 register_taxonomy( 'writer', array(XDMSG), |
|
301 array( 'hierarchical' => true, |
|
302 'label' => __('Writer','xili-dictionary'), |
|
303 'rewrite' => true, |
|
304 'query_var' => 'writer_name', |
|
305 'public' => false, |
|
306 'show_ui' => true, |
|
307 ) |
|
308 ); |
|
309 /* |
|
310 register_taxonomy( 'appearance', array(XDMSG), |
|
311 array( 'hierarchical' => true, // theme and child |
|
312 'label' => __('Theme','xili-dictionary'), |
|
313 'rewrite' => true, |
|
314 'query_var' => 'theme_slug', |
|
315 'public' => false, |
|
316 'show_ui' => true, |
|
317 ) |
|
318 ); |
|
319 */ |
|
320 register_taxonomy( 'origin', array(XDMSG), |
|
321 array('hierarchical' => false, |
|
322 'label' => __('Origin','xili-dictionary'), |
|
323 'query_var' => 'origin', |
|
324 'rewrite' => array('slug' => 'origin' ) |
|
325 ) |
|
326 ); |
|
327 } |
|
328 |
|
329 /** |
|
330 * register language taxonomy if no xili_language - 'update_count_callback' => array(&$this, '_update_post_lang_count'), |
|
331 * |
|
332 * |
|
333 */ |
|
334 function default_language_taxonomy () { |
|
335 if ( ! defined ( 'TAXONAME' ) ) { |
|
336 if ( ! defined ( 'QUETAG' ) ) define ('QUETAG', 'lang'); |
|
337 define ('TAXONAME', 'language'); |
|
338 register_taxonomy( TAXONAME, 'post', array('hierarchical' => false, 'label' => false, 'rewrite' => false , 'show_ui' => false, '_builtin' => false, 'query_var' => QUETAG )); |
|
339 define('TAXOLANGSGROUP', 'languages_group'); |
|
340 register_taxonomy( TAXOLANGSGROUP, 'term', array('hierarchical' => false, 'update_count_callback' => '', 'show_ui' => false, 'label'=>false, 'rewrite' => false, '_builtin' => false )); |
|
341 $thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group')); |
|
342 if ( array() == $thegroup ) { |
|
343 $args = array( 'alias_of' => '', 'description' => 'the group of languages', 'parent' => 0, 'slug' =>'the-langs-group'); |
|
344 wp_insert_term( 'the-langs-group', TAXOLANGSGROUP, $args); /* create and link to existing langs */ |
|
345 } |
|
346 return true; |
|
347 } else { |
|
348 return false; |
|
349 } |
|
350 } |
|
351 |
|
352 /** |
|
353 * add styles in edit msg screenstyle="clear:both; border-top:1px solid #666;" |
|
354 * |
|
355 */ |
|
356 function print_styles_xdmsg_edit ( ) { |
|
357 global $post; |
|
358 if ( get_post_type( $post->ID ) == XDMSG ) { |
|
359 echo '<!---- xd css ----->'."\n"; |
|
360 echo '<style type="text/css" media="screen">'."\n"; |
|
361 |
|
362 echo '#msg-states { width:69%; float:left; border:0px solid red; padding-bottom: 10px}'."\n"; |
|
363 echo '#msg-states-comments { width:27%; margin-left: 70%; border-left:0px #666 solid; padding:10px 10px 0; }'."\n"; |
|
364 echo '#msg-states-actions { background:#ffffff; clear:left; padding: 8px 5px; margin-top:5px; }'."\n"; |
|
365 echo '.xdversion { font-size:80%; text-align:right; }'."\n"; |
|
366 echo '.msg-states-actions-left { float:left; padding: 8px 0px; overflow:hidden; width:50% }'."\n"; |
|
367 echo '.msg-states-actions-right { float:left; padding: 8px 0px; width:50% }'."\n"; |
|
368 echo '.alert { color:red;}'."\n"; |
|
369 echo '.editing { color:blue; background:yellow;}'."\n"; |
|
370 echo '.msgidstyle { line-height:200% !important; font-size:120%; padding:4px 10px 6px;}'."\n"; |
|
371 echo '.msgstrstyle { line-height:180% !important; font-size:110%; }'."\n"; |
|
372 echo '.msg-saved { background:#ffffff !important; border:1px dotted #999; padding:5px; margin-bottom:5px;}'."\n"; |
|
373 echo '.column-msgtrans {width: 20%;}'."\n"; |
|
374 |
|
375 // buttons |
|
376 echo '.action-button {text-decoration:none; text-align:center; display:block; width:70%; margin:0px 1px 1px 30px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;}'."\n"; |
|
377 echo '.blue-button {border:1px #33f solid;}'."\n"; |
|
378 echo '.grey-button {border:1px #ccc solid;}'."\n"; |
|
379 |
|
380 echo '</style>'."\n"; |
|
381 if ( $this->exists_style_ext && $this->xili_settings['external_xd_style'] == "on" ) wp_enqueue_style( 'xili_dictionary_stylesheet' ); |
|
382 } |
|
383 } |
|
384 |
|
385 /** |
|
386 * add styles in list of msgs screen icon32-posts-xdmsg |
|
387 * |
|
388 */ |
|
389 function print_styles_xdmsg_list ( ) { |
|
390 |
|
391 if ( isset( $_GET['post_type']) && $_GET['post_type'] == XDMSG ) { |
|
392 |
|
393 echo '<!---- xd css ----->'."\n"; |
|
394 echo '<style type="text/css" media="screen">'."\n"; |
|
395 |
|
396 echo '.alert { color:red;}'."\n"; |
|
397 echo '.column-language { width: 80px; }'."\n"; |
|
398 echo '.column-msgcontent { width: 40%; }'."\n"; |
|
399 echo '.column-msgpostmeta { width: 150px; }'."\n"; |
|
400 echo '.column-author { width: 80px !important; }'."\n"; |
|
401 echo '.column-title { width: 160px !important; }'."\n"; |
|
402 |
|
403 echo '#icon-edit.icon32-posts-xdmsg { background:transparent url('.plugins_url( 'images/xilidico-logo-32.jpg', __FILE__ ) . ') no-repeat !important ; }'."\n"; |
|
404 echo '</style>'."\n"; |
|
405 if ( $this->exists_style_ext && $this->xili_settings['external_xd_style'] == "on" ) wp_enqueue_style( 'xili_dictionary_stylesheet' ); |
|
406 |
|
407 } |
|
408 } |
|
409 |
|
410 /** |
|
411 * add styles in tool screen |
|
412 * |
|
413 */ |
|
414 function print_styles_xdmsg_tool ( ) { |
|
415 echo '<!---- xd css ----->'."\n"; |
|
416 echo '<style type="text/css" media="screen">'."\n"; |
|
417 |
|
418 echo '.dialoglang { float:left; width:25%; border:0px solid grey; margin: 5px; }'."\n"; |
|
419 echo '.dialogfile { float:left; width:37%; min-height:80px; border:0px solid grey; padding: 10px 5px 10px 20px; } '."\n"; |
|
420 echo '.dialogorigin { float:left; width:32%; min-height:80px; border:0px solid grey; padding: 10px 5px 10px 10px; } '."\n"; |
|
421 echo '.dialogbbt {clear:left; text-align:right; }'."\n"; |
|
422 echo 'table.checktheme { width:95%; margin-left:10px;}'."\n"; |
|
423 echo 'table.checktheme>tr>td { width:45% }'."\n"; |
|
424 |
|
425 |
|
426 // buttons |
|
427 echo '.action-button {text-decoration:none; text-align:center; display:block; width:70%; margin:0px 1px 1px 30px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;}'."\n"; |
|
428 echo '.small-action-button {text-decoration:none; text-align:center; display:inline-block; width:16%; margin:0px 1px 1px 10px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; border:1px #ccc solid;}'."\n"; |
|
429 echo '.blue-button {border:1px #33f solid;}'."\n"; |
|
430 echo '.grey-button {border:1px #ccc solid;}'."\n"; |
|
431 |
|
432 echo '</style>'."\n"; |
|
433 if ( $this->exists_style_ext && $this->xili_settings['external_xd_style'] == "on" ) wp_enqueue_style( 'xili_dictionary_stylesheet' ); |
|
434 } |
|
435 |
|
436 |
|
437 /** |
|
438 * style for new dashboard |
|
439 * @since 2.1 |
|
440 * |
|
441 */ |
|
442 function ext_style_init () { |
|
443 // test successively style file in theme, plugins, current plugin subfolder |
|
444 if ( file_exists ( get_stylesheet_directory().'/xili-css/xd-style.css' ) ) { // in child theme |
|
445 $this->exists_style_ext = true; |
|
446 $this->style_folder = get_stylesheet_directory_uri(); |
|
447 $this->style_flag_folder_path = get_stylesheet_directory () . '/images/flags/'; |
|
448 $this->style_message = __( 'xd-style.css is in sub-folder xili-css of current theme folder', 'xili-dictionary' ); |
|
449 } elseif ( file_exists( WP_PLUGIN_DIR . $this->xilidev_folder . '/xili-css/xd-style.css' ) ) { // in plugin xilidev-libraries |
|
450 $this->exists_style_ext = true; |
|
451 $this->style_folder = plugins_url() . $this->xilidev_folder; |
|
452 $this->style_flag_folder_path = WP_PLUGIN_DIR . $this->xilidev_folder . '/xili-css/flags/' ; |
|
453 $this->style_message = sprintf( __( 'xd-style.css is in sub-folder xili-css of %s folder', 'xili-dictionary' ), $this->style_folder ); |
|
454 } elseif ( file_exists ( $this->plugin_path.'/xili-css/xd-style.css' ) ) { // in current plugin |
|
455 $this->exists_style_ext = true; |
|
456 $this->style_folder = $this->plugin_url ; |
|
457 $this->style_flag_folder_path = $this->plugin_path . '/xili-css/flags/' ; |
|
458 $this->style_message = __( 'xd-style.css is in sub-folder xili-css of xili-dictionary plugin folder (example)', 'xili-dictionary' ); |
|
459 } else { |
|
460 $this->style_message = __( 'no xd-style.css', 'xili-dictionary' ); |
|
461 } |
|
462 if ( $this->exists_style_ext ) wp_register_style( 'xili_dictionary_stylesheet', $this->style_folder . '/xili-css/xd-style.css' ); |
|
463 } |
|
464 |
|
465 |
|
466 /** |
|
467 * create default languages if no xili_language |
|
468 * |
|
469 * |
|
470 */ |
|
471 function create_default_languages () { |
|
472 |
|
473 $this->default_langs_array = array( |
|
474 'en_us' => array('en_US', 'english'), |
|
475 'fr_fr' => array('fr_FR', 'french'), |
|
476 'de_de' => array('de_DE', 'german'), |
|
477 'es_es' => array('es_ES', 'spanish'), |
|
478 'it_it' => array('it_IT', 'italian'), |
|
479 'pt_pt' => array('pt_PT', 'portuguese'), |
|
480 'ru_ru' => array('ru_RU', 'russian'), |
|
481 'zh_cn' => array('zh_CN', 'chinese'), |
|
482 'ja' => array('ja', 'japanese'), |
|
483 'ar_ar' => array('ar_AR', 'arabic') |
|
484 ); |
|
485 |
|
486 $term = 'en_US'; |
|
487 $args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'en_us'); |
|
488 $theids = $this->safe_lang_term_creation ( $term, $args ); |
|
489 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
|
490 |
|
491 /* default values */ |
|
492 if ( ''!= WPLANG && ( strlen( WPLANG )==5 || strlen( WPLANG ) == 2 ) ) : // for japanese |
|
493 $this->default_lang = WPLANG; |
|
494 else: |
|
495 $this->default_lang = 'en_US'; |
|
496 endif; |
|
497 |
|
498 $term = $this->default_lang; |
|
499 $desc = $this->default_lang; |
|
500 $slug = strtolower( $this->default_lang ) ; // 2.3.1 |
|
501 if (!defined('WPLANG') || $this->default_lang == 'en_US' || $this->default_lang == '' ) { |
|
502 $term = 'fr_FR'; $desc = 'French'; $slug = 'fr_fr' ; |
|
503 } |
|
504 $args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug); |
|
505 |
|
506 $theids = $this->safe_lang_term_creation ( $term, $args ) ; |
|
507 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
|
508 |
|
509 } |
|
510 |
|
511 /** |
|
512 * Safe language term creation (if XL inactive) |
|
513 * |
|
514 * @since 2.0 (from XL 2.4.1) |
|
515 */ |
|
516 function safe_lang_term_creation ( $term, $args ) { |
|
517 global $wpdb ; |
|
518 // test if exists with other slug or name |
|
519 if ( $term_id = term_exists( $term ) ) { |
|
520 $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name, slug FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); |
|
521 if ( $existing_term['slug'] != $args['slug'] ) { |
|
522 $res = wp_insert_term( $term.'xl', TAXONAME, $args); // temp insert with temp other name |
|
523 $args['name'] = $term ; |
|
524 $res = wp_update_term( $res['term_id'], TAXONAME, $args); |
|
525 } else { |
|
526 return new WP_Error('term_exists', __('A term with the name provided already exists.'), $term_id ); |
|
527 } |
|
528 } else { |
|
529 $res = wp_insert_term( $term, TAXONAME, $args); |
|
530 } |
|
531 if (is_wp_error($res)) { |
|
532 return $res ; |
|
533 } else { |
|
534 $theids = $res; |
|
535 } |
|
536 return $theids ; |
|
537 } |
|
538 |
|
539 /** |
|
540 * call from filter disable_richedit |
|
541 * |
|
542 * disable rich editor in msg cpt |
|
543 * |
|
544 * @since 2.0 |
|
545 * |
|
546 */ |
|
547 function disable_richedit_for_cpt ( $default ) { |
|
548 global $post; |
|
549 if ( XDMSG == get_post_type( $post ) ) |
|
550 return false; |
|
551 return $default; |
|
552 } |
|
553 function remove_quick_edit( $actions ) { |
|
554 if ( isset ( $_GET['post_type'] ) && $_GET['post_type'] == XDMSG ) |
|
555 unset($actions['inline hide-if-no-js']); |
|
556 |
|
557 return $actions; |
|
558 } |
|
559 |
|
560 |
|
561 /** |
|
562 * call from filter save_post |
|
563 * |
|
564 * save content in title - fixes empty msgid |
|
565 * |
|
566 * @since 2.0 |
|
567 * |
|
568 */ |
|
569 function custom_post_type_title ( $post_id, $post ) { |
|
570 global $wpdb; |
|
571 if ( get_post_type( $post_id ) == XDMSG ) { |
|
572 $where = array( 'ID' => $post_id ); |
|
573 $what = array (); |
|
574 |
|
575 if ( false === strpos( $post->post_title, 'MSG:' ) ) { |
|
576 $title = 'MSG:'.$post_id; |
|
577 $what['post_title'] = $title ; |
|
578 } |
|
579 |
|
580 if ( $post->post_content == '' ) { |
|
581 $what['post_content'] = "XD say: do not save empty ".$post_id; |
|
582 } |
|
583 if ( $what != array() ) |
|
584 $wpdb->update( $wpdb->posts, $what, $where ); |
|
585 } |
|
586 } |
|
587 |
|
588 /** |
|
589 * clean msgid postmeta before deleting |
|
590 */ |
|
591 function msgid_post_links_delete ( $post_id ) { |
|
592 // type of msg |
|
593 if ( get_post_type( $post_id ) == XDMSG ) { |
|
594 $type = get_post_meta ( $post_id, $this->msgtype_meta, true); |
|
595 |
|
596 if ( $type == 'msgid_plural' ) { |
|
597 |
|
598 $parent = get_post($post_id)->post_parent; |
|
599 $res = get_post_meta ( $parent, $this->msgchild_meta, false ); |
|
600 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
601 if ( $res != '' ) { |
|
602 unset ( $thechilds['msgid']['plural'] ) ; |
|
603 update_post_meta ( $parent, $this->msgchild_meta, $thechilds ); |
|
604 } |
|
605 |
|
606 } elseif ( $type != 'msgid' ) { |
|
607 $langs = get_the_terms( $post_id, TAXONAME ); |
|
608 $target_lang = $langs[0]->name ; |
|
609 // id of msg id or parent |
|
610 if ( $type == 'msgstr' && $target_lang != '' ) { |
|
611 $msgid_ID = get_post_meta ( $post_id, $this->msgidlang_meta , true); |
|
612 $res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); |
|
613 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
614 if ( $res != '' && is_array ( $thelangs ) ) { |
|
615 |
|
616 unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr'] ) ; |
|
617 update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta |
|
618 } |
|
619 } elseif ( false !== strpos( $type, 'msgstr_' ) && $target_lang != '' ) { |
|
620 $indices = explode ('_', $type); |
|
621 $msgid_ID = get_post_meta ( $post_id, $this->msgidlang_meta , true); |
|
622 if ( $indices[1] == 0 ) { |
|
623 $res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); |
|
624 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
625 if ( $res != '' && is_array ( $thelangs ) ) { |
|
626 unset ( $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] ) ; |
|
627 // delete childs or trash ?? |
|
628 // ?? recursive |
|
629 update_post_meta ( $msgid_ID, $this->msglang_meta, $thelangs ); // update id post_meta |
|
630 } |
|
631 } else { |
|
632 $res = get_post_meta ( $msgid_ID, $this->msglang_meta, false ); |
|
633 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
634 if ( $res != '' && is_array ( $thelangs ) ) { |
|
635 if ( isset ( $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] ) ) { |
|
636 $parent = $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] ; |
|
637 $res = get_post_meta ( $parent, $this->msgchild_meta, false ); |
|
638 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
639 if ( $res != '' ) { |
|
640 unset ( $thechilds['msgstr']['plural'][$indices[1]] ) ; |
|
641 update_post_meta ( $parent, $this->msgchild_meta, $thechilds ); |
|
642 } |
|
643 } |
|
644 } |
|
645 } // indice > 0 |
|
646 } // str plural |
|
647 } // msgstr |
|
648 } // XDMSG |
|
649 } |
|
650 |
|
651 /** |
|
652 * a new msgid is created manually |
|
653 */ |
|
654 function msgid_post_new_create ( $post_id, $post ) { |
|
655 global $wpdb; |
|
656 if ( isset($_POST['_inline_edit']) ) return; |
|
657 if ( isset( $_GET['bulk_edit']) ) return; |
|
658 if ( get_post_type( $post_id ) == XDMSG ) { |
|
659 if ( !wp_is_post_revision( $post_id ) && $this->importing_mode != true ) { |
|
660 |
|
661 //$temp_post = $this->temp_get_post ( $post_id ); |
|
662 $type = get_post_meta ( $post_id, $this->msgtype_meta, true ) ; |
|
663 if ( $type == "" ) { |
|
664 update_post_meta ( $post_id, $this->msgtype_meta, 'msgid' ); |
|
665 update_post_meta ( $post_id, $this->msglang_meta, array() ); |
|
666 update_post_meta ( $post_id, $this->msg_extracted_comments, $this->local_tag . ' '); // 2.2.0 local by default if hand created |
|
667 } |
|
668 $result = $this->msgid_exists ( $post->post_content ); |
|
669 if ( $result === false || $result[0] == $post_id ) { |
|
670 return ; |
|
671 } else { |
|
672 if ( $type == get_post_meta ( $result[0], $this->msgtype_meta, true ) && $type == 'msgid') { |
|
673 $newcontent = sprintf( __('msgid exists as %d with content: %s','xili-dictionary'), $result[0], $post->post_content ) ; |
|
674 $where = array( 'ID' => $post_id ); |
|
675 $wpdb->update( $wpdb->posts, array( 'post_content' => $newcontent ), $where ); |
|
676 } |
|
677 } |
|
678 } |
|
679 } |
|
680 } |
|
681 |
|
682 /** |
|
683 * Main "dashboard" box in msg edit to display and link the series of msg |
|
684 * |
|
685 * @since 2.0 |
|
686 * @updated 2.1.2 - called by action add_meta_boxes |
|
687 * |
|
688 */ |
|
689 function add_custom_box_in_post_msg () { |
|
690 $singular_name = __('series','xili-dictionary'); |
|
691 |
|
692 add_meta_box('msg_state', sprintf(__("msg %s",'xili-dictionary'), $singular_name), array(&$this,'msg_state_box'), XDMSG , 'normal','high'); |
|
693 if ( get_current_screen()->action != 'add' ) { // only for edit not new |
|
694 add_meta_box('msg_untranslated_list', sprintf(__("List of MSG %s to translate",'xili-dictionary'), $singular_name), array(&$this,'msg_untranslated_list_box'), XDMSG , 'normal','high'); |
|
695 add_meta_box('msg_tools_shortcuts', __("Shortcuts to update mo files",'xili-dictionary'), array(&$this,'msg_tools_shortcuts_box'), XDMSG , 'side','high'); |
|
696 } |
|
697 } |
|
698 |
|
699 function mo_files_array () { |
|
700 $this->theme_mos = $this->get_pomo_from_theme(); |
|
701 $this->local_mos = $this->get_pomo_from_theme( true ); // 2.1 |
|
702 if ( is_multisite() ) { |
|
703 $this->file_site_mos = $this->get_pomo_from_site(); // since 1.2.0 - mo of site |
|
704 $this->file_site_local_mos = $this->get_pomo_from_site( true ); |
|
705 } |
|
706 } |
|
707 |
|
708 function get_list_languages () { |
|
709 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); |
|
710 $this->languages_key_slug = array(); |
|
711 foreach ( $listlanguages as $language ) { |
|
712 $this->languages_key_slug[$language->slug] = array ('name'=>$language->name, 'description'=>$language->description ); |
|
713 } |
|
714 return $listlanguages; |
|
715 } |
|
716 |
|
717 |
|
718 /** |
|
719 * display shortcut links to update mo |
|
720 * |
|
721 * called add_meta_box('msg_tools_shortcuts' |
|
722 * |
|
723 * |
|
724 */ |
|
725 function msg_tools_shortcuts_box ( $post ) { |
|
726 $post_ID = $post->ID; |
|
727 $lang = $this->cur_lang ( $post_ID ); |
|
728 |
|
729 if ( $lang ) { |
|
730 $link_theme_mo = wp_nonce_url (admin_url().'post.php?post='.$post_ID.'&action=edit&msgupdate=updatetheme&langstr='.$lang->name.'&message=33', 'xd-updatemo'); |
|
731 $link_local_mo = wp_nonce_url (admin_url().'post.php?post='.$post_ID.'&action=edit&msgupdate=updatelocal&langstr='.$lang->name.'&message=34', 'xd-updatemo'); |
|
732 if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0 |
|
733 $theme_name = get_option("stylesheet"); |
|
734 } else { |
|
735 $theme_name = get_option("template"); |
|
736 } |
|
737 echo '<p>' . sprintf(__('This msg translation is in %1$s (%2$s)','xili-dictionary'),$lang->description, $lang->name).'</p>'; |
|
738 echo '<h4>'. __('Updating shortcuts', 'xili-dictionary').'</h4>'; |
|
739 |
|
740 if ( $this->count_msgids ( $lang->name, true ) > 0 ) { |
|
741 echo '<p>' . sprintf('<a class="action-button blue-button" onClick="verifybefore(1)" href="%2$s" >'.__('Update','xili-dictionary').' local-%3$s.mo</a>','#', '#', $lang->name).'</p>'; |
|
742 } else { |
|
743 echo '<p class="action-button grey-button">' . sprintf( __('No local translated msgid to be saved in %s','xili-dictionary'), ' local-'.$lang->name.'.mo' ) . '</p>'; |
|
744 } |
|
745 |
|
746 echo '<p>' . sprintf(__('It is possible to update the .mo files of current theme %s','xili-dictionary'), '<strong>'.$theme_name.'</strong>' ).'</p>'; |
|
747 echo '<p><em>' . __('Before to use this button, it is very important that you verify that your term list is quite achieved inside the dictionary. It is because the original .mo delivered with theme is updated (erased) !!!', 'xili-dictionary') .'</em></p>'; |
|
748 |
|
749 if ( $this->count_msgids ( $lang->name, false, $theme_name ) > 0 ) { |
|
750 echo '<p>' . sprintf('<a class="action-button grey-button" onClick="verifybefore(0)" href="%1$s" >'.__('Update','xili-dictionary').' %3$s.mo</a>','#', '#', $lang->name).'</p>'; |
|
751 } else { |
|
752 echo '<p class="action-button grey-button">' . sprintf( __('No translated msgid to be saved in %s','xili-dictionary'), $lang->name.'.mo' ) . '</p>'; |
|
753 } |
|
754 |
|
755 //echo '<p>- ' . sprintf('<a href="%1$s" >%3$s.mo</a><br />- <a href="%2$s" >'.__('local','xili-dictionary').'-%3$s.mo</a>',$link_theme_mo, $link_local_mo, $lang->name).'</p>'; |
|
756 echo '<small>'.$this->msg_action_message.'</small>'; |
|
757 } else { |
|
758 |
|
759 echo '<p>' . __('Links are available if a translation (msgstr) is edited.','xili-dictionary').'</p>'; |
|
760 } |
|
761 |
|
762 if ( $lang ) { |
|
763 ?> |
|
764 |
|
765 <p class="xdversion">XD v. <?php echo XILIDICTIONARY_VER; ?></p> |
|
766 <script type="text/javascript"> |
|
767 function verifybefore(id) { |
|
768 var link = new Array(); |
|
769 |
|
770 link[0] = "<?php echo str_replace('amp;','', $link_theme_mo); ?>"; |
|
771 link[1] = "<?php echo str_replace('amp;','', $link_local_mo); ?>"; |
|
772 var confirmmessage = "<?php _e('Are you sure you want to update mo ? ', 'xili-dictionary'); ?>"; |
|
773 var message = "Action Was Cancelled By User " ; |
|
774 |
|
775 if (confirm(confirmmessage)) { |
|
776 |
|
777 window.location = link[id]; |
|
778 |
|
779 } else { |
|
780 |
|
781 // alert(message); |
|
782 |
|
783 } |
|
784 |
|
785 } |
|
786 </script> |
|
787 <?php |
|
788 } |
|
789 } |
|
790 |
|
791 // add messages called by add_filter( 'post_updated_messages' @since 2.1.2 |
|
792 function msg_post_messages ( $messages ) { |
|
793 $messages['post'][33] = __('MO file updating started: see result in meta-box named - Shortcuts... - below buttons', 'xili-dictionary'); |
|
794 $messages['post'][34] = __('Local MO updating started: see result in meta-box named - Shortcuts... - below buttons', 'xili-dictionary'); |
|
795 return $messages; |
|
796 } |
|
797 |
|
798 /** |
|
799 * update current .mo |
|
800 * |
|
801 * called add_action( 'add_meta_boxes_' . XDMSG |
|
802 * |
|
803 * to have values before metaboxes built |
|
804 */ |
|
805 function msg_update_action ( $post ) { |
|
806 $extract_array = array(); |
|
807 $langfolderset = $this->xili_settings['langs_folder']; |
|
808 $this->langfolder = ( $langfolderset !='' ) ? $langfolderset.'/' : '/'; |
|
809 // doublon |
|
810 $this->langfolder = str_replace ("//","/", $this->langfolder ); // upgrading... 2.0 and sub folder sub |
|
811 if ( isset ($_GET['msgupdate'] ) && isset ($_GET['langstr']) ) { // shortcut to update .mo - 2.1.2 |
|
812 check_admin_referer( 'xd-updatemo' ); |
|
813 $filetype = $_GET['msgupdate']; |
|
814 $selectlang = $_GET['langstr']; |
|
815 |
|
816 if ( is_multisite() ) { |
|
817 if (($uploads = xili_upload_dir()) && false === $uploads['error'] ) { |
|
818 |
|
819 if ( $filetype == 'updatelocal' ) { // only current site - need tools for other superadmin place |
|
820 $local = 'local-'; |
|
821 $extract_array [ $this->msg_extracted_comments ] = $this->local_tag; |
|
822 $extract_array [ 'like-'.$this->msg_extracted_comments ] = true; |
|
823 $file = $uploads['path']."/local-".$selectlang.".mo" ; |
|
824 |
|
825 } else { |
|
826 if ( is_child_theme() ) { |
|
827 $theme_name = get_option("stylesheet"); |
|
828 } else { |
|
829 $theme_name = get_option("template"); |
|
830 } |
|
831 $extract_array [ 'origin' ] = array( $theme_name ); // only if assigned to current theme domain |
|
832 |
|
833 $local = ''; |
|
834 $file = $uploads['path']."/".$selectlang.".mo" ; |
|
835 |
|
836 } |
|
837 $mo = $this->from_cpt_to_POMO_wpmu ( $selectlang, 'mo', true, $extract_array ); // do diff if not superadmin |
|
838 } |
|
839 |
|
840 |
|
841 } else { // standalone |
|
842 |
|
843 if ( $filetype == 'updatelocal' ) { |
|
844 $local = 'local-'; |
|
845 $extract_array [ $this->msg_extracted_comments ] = $this->local_tag; |
|
846 $extract_array [ 'like-'.$this->msg_extracted_comments ] = true; |
|
847 $file = $this->get_template_directory.$this->langfolder.'local-'.$selectlang.'.mo' ; |
|
848 |
|
849 } else { |
|
850 if ( is_child_theme() ) { |
|
851 $theme_name = get_option("stylesheet"); |
|
852 } else { |
|
853 $theme_name = get_option("template"); |
|
854 } |
|
855 $extract_array [ 'origin' ] = array( $theme_name ); |
|
856 $local = ''; |
|
857 $file = ''; |
|
858 } |
|
859 $mo = $this->from_cpt_to_POMO ( $selectlang, 'mo', $extract_array ); |
|
860 } |
|
861 |
|
862 if ( count ($mo->entries) > 0 ){ |
|
863 |
|
864 if ( false === $this->Save_MO_to_file ( $selectlang , $mo, $file ) ) { |
|
865 $this->msg_action_message = sprintf('<span class="alert">'.__('Error with File %s !', 'xili-dictionary').'</span> ('.$file.')', $local.$selectlang.'.mo'); |
|
866 } else { |
|
867 $this->msg_action_message = sprintf(__('File %1s updated with %2s msgids', 'xili-dictionary'), $local.$selectlang.'.mo', count ($mo->entries) ); |
|
868 } |
|
869 |
|
870 } else { |
|
871 $this->msg_action_message = sprintf('<span class="alert">'.__('Nothing modified in %s, file not updated', 'xili-dictionary').'</span>', $local.$selectlang.'.mo'); |
|
872 } |
|
873 } |
|
874 } |
|
875 |
|
876 |
|
877 // the first lang of msgstr or false for msgid |
|
878 function cur_lang ( $post_ID ) { |
|
879 $langs = wp_get_object_terms( $post_ID, TAXONAME); |
|
880 if ( ! is_wp_error( $langs ) && ! empty( $langs ) ) { |
|
881 return $langs[0]; |
|
882 } |
|
883 return false; |
|
884 } |
|
885 |
|
886 /** |
|
887 * Normal metabox : List to display untranslated msgid in target lang like msgstr currently displayed |
|
888 * |
|
889 * @since 2.1.2 |
|
890 */ |
|
891 function msg_untranslated_list_box ( $post ) { |
|
892 $post_ID = $post->ID; |
|
893 $type = get_post_meta ( $post_ID, $this->msgtype_meta, true); |
|
894 $msglang = ''; |
|
895 $message = ''; |
|
896 $arraylink = array(); |
|
897 $sortparent = (($this->subselect == '') ? '' : '&tagsgroup_parent_select='.$this->subselect ); |
|
898 $listlanguages = $this->get_list_languages(); |
|
899 foreach ( $listlanguages as $language ) { |
|
900 $arraylink[] = sprintf( '<a href="%s" >'.$language->name.'</a>', 'post.php?post='.$post_ID.'&action=edit&workinglang='.$language->slug ); |
|
901 } |
|
902 $listlink = implode (' ', $arraylink ); |
|
903 $working_lang = ( isset ($_GET['workinglang']) ) ? $_GET['workinglang'] : '' ; |
|
904 |
|
905 if ( $type == 'msgstr' ) { |
|
906 |
|
907 $lang = $this->cur_lang ( $post_ID ); |
|
908 |
|
909 if ( $lang ) $msglang = $lang->slug ; |
|
910 |
|
911 $this->subselect = ( $working_lang == '' ) ? $msglang : $working_lang ; |
|
912 $this->searchtranslated = 'not'; |
|
913 $message = sprintf(__('MSGs not translated in %1$s. <em>Sub-select in %2$s</em>', 'xili-dictionary' ), $this->languages_key_slug[$this->subselect]['name'], $listlink ) ; |
|
914 |
|
915 } else { // msgid |
|
916 |
|
917 $this->subselect = $working_lang; |
|
918 |
|
919 $message = ( $working_lang == '' ) ? sprintf( __('No selection: Sub-select in %s', 'xili-dictionary' ), $listlink ) : sprintf(__('MSGs not translated in %1$s. <em>Sub-select in %2$s</em>', 'xili-dictionary' ), $_GET['workinglang'], $listlink ); |
|
920 $this->searchtranslated = ( $working_lang == '' ) ? '' : 'not' ; |
|
921 } |
|
922 |
|
923 ?> |
|
924 <p><?php echo $message ; ?></p> |
|
925 <div id="topbanner"> |
|
926 </div> |
|
927 <div id="tableupdating"> |
|
928 </div> |
|
929 |
|
930 <table class="display" id="linestable"> |
|
931 <thead> |
|
932 <tr> |
|
933 <th scope="col" class="center colid"><a href="<?php echo $this->xd_settings_page; ?>" ><?php _e('ID') ?></a></th> |
|
934 <th scope="col" class="coltexte"><a href="<?php echo $this->xd_settings_page.'&orderby=name'.$sortparent; ?>"><?php _e('Text') ?></a> |
|
935 </th> |
|
936 <th scope="col" class="colslug"><?php _e('Metas','xili-dictionary') ?></th> |
|
937 <th scope="col" class="colgroup center"><?php _e('Save status','xili-dictionary') ?></th> |
|
938 <th colspan="2"><?php _e('Action') ?></th> |
|
939 </tr> |
|
940 </thead> |
|
941 <tbody id="the-list"> |
|
942 <?php |
|
943 |
|
944 $this->xili_dict_cpt_row(); /* the lines */ |
|
945 ?> |
|
946 </tbody> |
|
947 </table> |
|
948 <div id="bottombanner"> |
|
949 </div> |
|
950 <?php |
|
951 $this->insert_js_for_datatable( array('swidth2'=>'50%') ); |
|
952 } |
|
953 |
|
954 /** |
|
955 * insert js for datatable - used in post and in tools |
|
956 * |
|
957 * @since 2.1.2 |
|
958 * |
|
959 */ |
|
960 |
|
961 function insert_js_for_datatable( $args ) { |
|
962 ?> |
|
963 <script type="text/javascript"> |
|
964 |
|
965 //<![CDATA[ |
|
966 jQuery(document).ready( function($) { |
|
967 |
|
968 var termsTable = $('#linestable').dataTable( { |
|
969 "iDisplayLength": 20, |
|
970 "bStateSave": true, |
|
971 "bAutoWidth": false, |
|
972 "sDom": '<"topbanner"ipf>rt<"bottombanner"lp><"clear">', |
|
973 "sPaginationType": "full_numbers", |
|
974 "aLengthMenu": [[20, 30, 60, -1], [20, 30, 60, "<?php _e('All lines','xili-dictionary') ?>"]], |
|
975 "oLanguage": { |
|
976 "oPaginate": { |
|
977 "sFirst": "<?php _e('First','xili-dictionary') ?>", |
|
978 "sLast": "<?php _e('Last page','xili-dictionary') ?>", |
|
979 "sNext": "<?php _e('Next','xili-dictionary') ?>", |
|
980 "sPrevious": "<?php _e('Previous','xili-dictionary') ?>" |
|
981 }, |
|
982 "sInfo": "<?php _e('Showing (_START_ to _END_) of _TOTAL_ entries','xili-dictionary') ?>", |
|
983 "sInfoFiltered": "<?php _e('(filtered from _MAX_ total entries)','xili-dictionary') ?>", |
|
984 "sLengthMenu": "<?php _e('Show _MENU_ entries','xili-dictionary') ?>", |
|
985 "sSearch": "<?php _e('Filter terms:','xili-dictionary') ?>" |
|
986 |
|
987 }, |
|
988 "aaSorting": [[1,'asc']], |
|
989 "aoColumns": [ |
|
990 { "bSearchable": false, "sWidth" : "30px" }, |
|
991 { "sWidth" : "<?php echo $args['swidth2']; ?>" }, |
|
992 { "bSortable": false, "bSearchable": false }, |
|
993 { "bSortable": false, "bSearchable": false, "sWidth" : "105px" }, |
|
994 { "bSortable": false, "bSearchable": false, "sWidth" : "70px" } ] |
|
995 } ); |
|
996 |
|
997 // close postboxes that should be closed |
|
998 $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); |
|
999 // postboxes setup |
|
1000 postboxes.add_postbox_toggles('<?php echo $this->thehook; ?>'); |
|
1001 // for text_area list |
|
1002 }); |
|
1003 //]]> |
|
1004 </script> |
|
1005 |
|
1006 <?php |
|
1007 |
|
1008 } |
|
1009 |
|
1010 |
|
1011 function msg_state_box () { |
|
1012 global $post_ID, $post ; |
|
1013 |
|
1014 $type = get_post_meta ( $post_ID, $this->msgtype_meta, true); |
|
1015 //error_log ( '----'.$this->langfolder); |
|
1016 //$langfolderset = $this->xili_settings['langs_folder']; |
|
1017 //$this->langfolder = ( $langfolderset !='' ) ? $langfolderset.'/' : '/'; |
|
1018 // doublon |
|
1019 //$this->langfolder = str_replace ("//","/", $this->langfolder ); // upgrading... 2.0 and sub folder sub |
|
1020 $this->mo_files_array (); //error_log( serialize( $this->theme_mos )); |
|
1021 |
|
1022 ?> |
|
1023 <div id="msg-states"> |
|
1024 <?php |
|
1025 |
|
1026 $this->msg_status_display ( $post_ID ); |
|
1027 |
|
1028 ?> |
|
1029 </div> |
|
1030 <div id="msg-states-comments"> |
|
1031 <?php |
|
1032 $for_bottom_box = $this->msg_status_comments ( $post_ID ); |
|
1033 ?> |
|
1034 </div> |
|
1035 <div id="msg-states-actions" > |
|
1036 <strong><?php _e( 'Informations and actions about files .po / mo', 'xili-dictionary' ); echo ':</strong><br />'; ?> |
|
1037 <div class="msg-states-actions-left" > |
|
1038 <?php echo $for_bottom_box['link'] .'<br />'; ?> |
|
1039 <?php $origins = get_the_terms( $post_ID, 'origin' ); |
|
1040 $names = array(); |
|
1041 if ( $origins ) { |
|
1042 foreach ( $origins as $origin ) { |
|
1043 $names[] = $origin->name; |
|
1044 } |
|
1045 echo __( 'Come from theme(s):', 'xili-dictionary') .' '. implode (' ', $names).'<br />';; |
|
1046 } else { |
|
1047 if ( !$for_bottom_box['state'] ) { |
|
1048 if ( $type == 'msgid' ) _e ( 'Not yet assigned', 'xili-dictionary') ; |
|
1049 } |
|
1050 } ?> |
|
1051 </div> |
|
1052 <div class="msg-states-actions-right" > |
|
1053 <?php |
|
1054 $context = get_post_meta ( $post_ID, $this->ctxt_meta, true); |
|
1055 $res = $this->is_saved_cpt_in_theme( htmlspecialchars_decode ($post->post_content), $type, $context ); |
|
1056 $save_state = '<br />'. ( ( false === strpos ( $res[0], '**</span>' ) ) ? sprintf( __('theme folder %s','xili-dictionary') ,$res[0]) : '' ) . ( ( false == strpos ( $res[2], '?</span>' ) ) ? ' (local: '.$res[2].')' : '' ); |
|
1057 if ( is_multisite() ) $save_state .= '<br />'. __('this site','xili-dictionary') . ( ( false === strpos ( $res[1], '**</span>' ) ) ? sprintf( __('folder %s','xili-dictionary') ,$res[1]) : ' ' ) . ( ( false == strpos ( $res[3], '?</span>' ) ) ? ' (local: '.$res[3].')' : '' ); |
|
1058 |
|
1059 echo $type.' <em>' . $post->post_content . '</em> ' . __('saved in ','xili-dictionary') . $save_state; |
|
1060 |
|
1061 ?> |
|
1062 </div> |
|
1063 <p class="xdversion">XD v. <?php echo XILIDICTIONARY_VER; ?></p> |
|
1064 </div> |
|
1065 <?php |
|
1066 } |
|
1067 |
|
1068 /** |
|
1069 * test unique content for msgid + context |
|
1070 * |
|
1071 * @since 2.0 |
|
1072 * @return ID is true |
|
1073 */ |
|
1074 function msgid_exists ( $content = "", $ctxt = null ) { |
|
1075 global $wpdb; |
|
1076 if ( $content != "" ) { |
|
1077 if ( null == $ctxt) { |
|
1078 $posts_query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_content = %s AND post_type = %s", $content, XDMSG ); |
|
1079 |
|
1080 } else { |
|
1081 $posts_query = $wpdb->prepare("SELECT ID FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) INNER JOIN $wpdb->postmeta as mt1 ON ($wpdb->posts.ID = mt1.post_id) WHERE post_content = %s AND post_type = %s AND $wpdb->postmeta.meta_key= '{$this->ctxt_meta}' AND mt1.meta_key= '{$this->ctxt_meta}' AND mt1.meta_value = %s ", $content, XDMSG, $ctxt); |
|
1082 } |
|
1083 // 2.2.0 |
|
1084 $found_posts = $wpdb->get_col($posts_query); |
|
1085 if ( empty($found_posts) ) { |
|
1086 return false; |
|
1087 } else { |
|
1088 return $found_posts; |
|
1089 } |
|
1090 } |
|
1091 |
|
1092 } |
|
1093 /** |
|
1094 * test unique content for msgstr + msgid + language |
|
1095 * |
|
1096 * @since 2.0 |
|
1097 * @return ID is true |
|
1098 */ |
|
1099 function msgstr_exists ( $content = "", $msgid, $curlang ) { |
|
1100 global $wpdb; |
|
1101 if ( "" != $content) { |
|
1102 $posts_query = $wpdb->prepare("SELECT ID FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) INNER JOIN $wpdb->postmeta as mt1 ON ($wpdb->posts.ID = mt1.post_id) WHERE post_content = %s AND post_type = %s AND $wpdb->postmeta.meta_key='{$this->msgidlang_meta}' AND mt1.meta_key='{$this->msgidlang_meta}' AND mt1.meta_value = %s ", $content, XDMSG, $msgid); |
|
1103 |
|
1104 |
|
1105 $found_posts = $wpdb->get_col($posts_query); |
|
1106 if ( empty($found_posts) ) { |
|
1107 return false; |
|
1108 } else { |
|
1109 |
|
1110 if ( in_array ( $curlang , wp_get_object_terms( $found_posts, TAXONAME, array ( 'fields' => 'names' ) ) ) ) { |
|
1111 // select only this with $curlang |
|
1112 return $found_posts ; |
|
1113 |
|
1114 } else { |
|
1115 return false; |
|
1116 } |
|
1117 |
|
1118 } |
|
1119 } |
|
1120 return false; |
|
1121 } |
|
1122 |
|
1123 /** |
|
1124 * import po and mo in cpts series |
|
1125 * |
|
1126 * @since 2.0 |
|
1127 * @return |
|
1128 */ |
|
1129 function from_pomo_to_cpts ( $po, $curlang = 'en_US' ) { |
|
1130 $nblines = array( 0, 0); // id, str count |
|
1131 $this->importing_mode = true ; |
|
1132 foreach ( $po->entries as $pomsgid => $pomsgstr ) { |
|
1133 // test if msgid exists |
|
1134 $result = $this->msgid_exists ( $pomsgstr->singular, $pomsgstr->context ) ; |
|
1135 |
|
1136 if ( $result === false ) { |
|
1137 // create the msgid |
|
1138 $type = 'msgid'; |
|
1139 $msgid_post_ID = $this->insert_one_cpt_and_meta( $pomsgstr->singular, $pomsgstr->context, $type, 0, $pomsgstr ) ; |
|
1140 $nblines[0]++ ; |
|
1141 } else { |
|
1142 $msgid_post_ID = $result[0]; |
|
1143 if ( $this->importing_po_comments != '' ) { |
|
1144 $this->insert_comments( $msgid_post_ID, $pomsgstr, $this->importing_po_comments ); |
|
1145 } |
|
1146 |
|
1147 } |
|
1148 |
|
1149 // add origin taxonomy |
|
1150 if ( ''!= $this->origin_theme ) |
|
1151 wp_set_object_terms( $msgid_post_ID, $this->origin_theme, 'origin', true ); // true to append to existing |
|
1152 |
|
1153 if ( $pomsgstr->is_plural != null ) { |
|
1154 // create msgid plural (child of msgid) |
|
1155 // $pomsgstr->plural, $msgid_post_ID |
|
1156 $result = $this->msgid_exists ( $pomsgstr->plural ) ; |
|
1157 if ( $result === false ) |
|
1158 $msgid_post_ID_plural = $this->insert_one_cpt_and_meta( $pomsgstr->plural, null, 'msgid_plural' , $msgid_post_ID, $pomsgstr ); |
|
1159 |
|
1160 } |
|
1161 |
|
1162 // create msgstr - taxonomy |
|
1163 |
|
1164 if ( $pomsgstr->is_plural == null ) { |
|
1165 |
|
1166 $msgstr_content = ( isset( $pomsgstr->translations[0]) ) ? $pomsgstr->translations[0] : "" ; |
|
1167 if ( $msgstr_content != "" ) { |
|
1168 // test exists with taxo before |
|
1169 $result = $this->msgstr_exists ( $msgstr_content, $msgid_post_ID, $curlang ) ; |
|
1170 if ( $result === false ) { |
|
1171 $msgstr_post_ID = $this->insert_one_cpt_and_meta( $msgstr_content, null, 'msgstr', 0, $pomsgstr ); |
|
1172 wp_set_object_terms( $msgstr_post_ID, $curlang, TAXONAME ); |
|
1173 $nblines[1]++ ; |
|
1174 } else { |
|
1175 $msgstr_post_ID = $result[0]; |
|
1176 } |
|
1177 |
|
1178 // create link according lang |
|
1179 |
|
1180 $res = get_post_meta ( $msgid_post_ID, $this->msglang_meta, false ); |
|
1181 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1182 $thelangs['msgstrlangs'][$curlang]['msgstr'] = $msgstr_post_ID; |
|
1183 update_post_meta ( $msgid_post_ID, $this->msglang_meta, $thelangs ); |
|
1184 update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $msgid_post_ID ); |
|
1185 } |
|
1186 |
|
1187 |
|
1188 } else { |
|
1189 // $pomsgstr->translations |
|
1190 $i=0; $parentplural = 0; |
|
1191 foreach ( $pomsgstr->translations as $onetranslation ) { |
|
1192 $msgstr_plural = 'msgstr_' . $i ; |
|
1193 $parent = ( $i == 0 ) ? 0 : $parentplural ; |
|
1194 if ( $onetranslation != "" ) { |
|
1195 // test exists with taxo before |
|
1196 $result = $this->msgstr_exists ( $onetranslation, $msgid_post_ID, $curlang ) ; |
|
1197 if ( $result === false ) { |
|
1198 $msgstr_post_ID_plural = $this->insert_one_cpt_and_meta( $onetranslation, null, $msgstr_plural , $parent, $pomsgstr ); |
|
1199 wp_set_object_terms( $msgstr_post_ID_plural, $curlang, TAXONAME ); |
|
1200 $nblines[1]++ ; |
|
1201 } else { |
|
1202 $msgstr_post_ID_plural = $result[0]; |
|
1203 } |
|
1204 update_post_meta ( $msgstr_post_ID_plural, $this->msgidlang_meta, $msgid_post_ID ); |
|
1205 } |
|
1206 |
|
1207 if ( $i == 0 ) { |
|
1208 $parentplural = $msgstr_post_ID_plural; |
|
1209 |
|
1210 // create link according lang in msgid |
|
1211 $res = get_post_meta ( $msgid_post_ID, $this->msglang_meta, false ); |
|
1212 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1213 $thelangs['msgstrlangs'][$curlang][$msgstr_plural] = $msgstr_post_ID_plural; |
|
1214 update_post_meta ( $msgid_post_ID, $this->msglang_meta, $thelangs ); |
|
1215 |
|
1216 } // only first str |
|
1217 |
|
1218 $i++; |
|
1219 } |
|
1220 } |
|
1221 |
|
1222 } |
|
1223 $this->importing_mode = false ; |
|
1224 return $nblines; |
|
1225 } |
|
1226 |
|
1227 /** |
|
1228 * import a msg line |
|
1229 * |
|
1230 * @since 2.0 |
|
1231 * |
|
1232 * @updated 2.1.2 |
|
1233 * |
|
1234 * @return ID |
|
1235 */ |
|
1236 function insert_one_cpt_and_meta ( $content, $context = null, $type , $parent = 0, $entry = null ) { |
|
1237 global $user_ID; |
|
1238 /* if (!empty($entry->translator_comments)) $po[] = PO::comment_block($entry->translator_comments); |
|
1239 if (!empty($entry->extracted_comments)) $po[] = PO::comment_block($entry->extracted_comments, '.'); |
|
1240 if (!empty($entry->references)) $po[] = PO::comment_block(implode(' ', $entry->references), ':'); |
|
1241 if (!empty($entry->flags)) $po[] = PO::comment_block(implode(", ", $entry->flags), ','); |
|
1242 */ |
|
1243 if ( null != $entry ) { |
|
1244 $references = (!empty($entry->references)) ? implode ( ' #: ' , $entry->references ) : '' ; |
|
1245 $flags = (!empty($entry->flags)) ? implode ( ', ' , $entry->flags ) : '' ; |
|
1246 $extracted_comments = (!empty($entry->extracted_comments)) ? $entry->extracted_comments : '' ; |
|
1247 $translator_comments = (!empty($entry->translator_comments)) ? $entry->translator_comments : '' ; |
|
1248 } else { |
|
1249 $references = ""; |
|
1250 $flags = ""; |
|
1251 $extracted_comments = ""; |
|
1252 $translator_comments = ""; |
|
1253 |
|
1254 } |
|
1255 |
|
1256 $params = array('post_status' => 'publish', 'post_type' => XDMSG, 'post_author' => $user_ID, |
|
1257 'ping_status' => get_option('default_ping_status'), 'post_parent' => $parent, |
|
1258 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', |
|
1259 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => $references, 'import_id' => 0, |
|
1260 'post_content' => $content, 'post_title' => ''); |
|
1261 |
|
1262 $post_id = wp_insert_post( $params ) ; |
|
1263 |
|
1264 if ( $post_id != 0 ) { |
|
1265 if ( $context != null ) // postmeta |
|
1266 update_post_meta ( $post_id, $this->ctxt_meta, $context ); |
|
1267 |
|
1268 // type postmeta |
|
1269 |
|
1270 update_post_meta ( $post_id, $this->msgtype_meta, $type ); |
|
1271 |
|
1272 if ( $type == 'msgid' ) { |
|
1273 if ( $extracted_comments != "" ) update_post_meta ( $post_id, $this->msg_extracted_comments, $extracted_comments ); |
|
1274 if ( $translator_comments != "") update_post_meta ( $post_id, $this->msg_translator_comments, $translator_comments ); |
|
1275 if ( $flags != "") |
|
1276 update_post_meta ( $post_id, $this->msg_flags, $flags ); |
|
1277 update_post_meta ( $post_id, $this->msglang_meta, array() ); // 2.1.2 |
|
1278 } |
|
1279 |
|
1280 if ( $type == 'msgstr' || $type == 'msgstr_0' ) { |
|
1281 if ( $translator_comments != "") update_post_meta ( $post_id, $this->msg_translator_comments, $translator_comments ); |
|
1282 } |
|
1283 // update postmeta children |
|
1284 // create array |
|
1285 if ( $parent != 0 ) { |
|
1286 |
|
1287 $res = get_post_meta ( $parent, $this->msgchild_meta, false ); |
|
1288 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1289 if ( $type == 'msgid_plural' ) { |
|
1290 $thechilds['msgid']['plural'] = $post_id; |
|
1291 |
|
1292 } elseif ( $type != 'msgstr' ){ |
|
1293 $indices = explode ('_', $type); |
|
1294 $thechilds['msgstr']['plural'][$indices[1]] = $post_id; |
|
1295 } |
|
1296 |
|
1297 update_post_meta ( $parent, $this->msgchild_meta, $thechilds ); |
|
1298 |
|
1299 } |
|
1300 } |
|
1301 return $post_id; |
|
1302 } |
|
1303 |
|
1304 /** |
|
1305 * insert comments of msgid / msgstr |
|
1306 * |
|
1307 * called by from_pomo_to_cpts |
|
1308 * |
|
1309 */ |
|
1310 function insert_comments( $post_id, $entry, $import_comment_mode = 'replace' ) { |
|
1311 |
|
1312 $references = (!empty($entry->references)) ? implode ( ' #: ' , $entry->references ) : '' ; |
|
1313 $flags = (!empty($entry->flags)) ? implode ( ', ' , $entry->flags ) : '' ; |
|
1314 $extracted_comments = (!empty($entry->extracted_comments)) ? $entry->extracted_comments : '' ; |
|
1315 $translator_comments = (!empty($entry->translator_comments)) ? $entry->translator_comments : '' ; |
|
1316 |
|
1317 if ( $import_comment_mode == 'replace' ) { |
|
1318 // update references in excerpt |
|
1319 $postarr = wp_get_single_post( $post_id, ARRAY_A ) ; |
|
1320 |
|
1321 $postarr['post_excerpt'] = $references; |
|
1322 |
|
1323 wp_insert_post( $postarr ); |
|
1324 |
|
1325 // update comments in meta |
|
1326 if ( $extracted_comments != "" ) update_post_meta ( $post_id, $this->msg_extracted_comments, $extracted_comments ); |
|
1327 if ( $translator_comments != "") update_post_meta ( $post_id, $this->msg_translator_comments, $translator_comments ); |
|
1328 if ( $flags != "") update_post_meta ( $post_id, $this->msg_flags, $flags ); |
|
1329 |
|
1330 } elseif ( $import_comment_mode == 'append' ) { // don't erase existing comments - can be risked |
|
1331 |
|
1332 |
|
1333 } |
|
1334 |
|
1335 } |
|
1336 |
|
1337 /** |
|
1338 * new columns in cpt list |
|
1339 * |
|
1340 */ |
|
1341 function xili_manage_column_name( $columns ) { // must be verified |
|
1342 |
|
1343 if ( isset ( $_GET['post_type'] ) && $_GET['post_type'] == XDMSG ) { |
|
1344 $ends = array('author', 'date', 'rel', 'visible'); |
|
1345 $end = array(); |
|
1346 foreach( $columns AS $k=>$v ) { |
|
1347 if ( in_array($k, $ends) ) { |
|
1348 $end[$k] = $v; |
|
1349 unset($columns[$k]); |
|
1350 } |
|
1351 } |
|
1352 $columns['msgcontent'] = __('Content','xili-dictionary'); // ? sortable ? |
|
1353 $columns['msgpostmeta'] = __('Metas','xili-dictionary'); |
|
1354 if ( !class_exists ( 'xili_language' ) ) { |
|
1355 $columns[TAXONAME] = __('Language','xili-dictionary'); |
|
1356 } |
|
1357 $columns = array_merge($columns, $end); |
|
1358 } |
|
1359 return $columns; |
|
1360 |
|
1361 } |
|
1362 |
|
1363 function xili_manage_column_row ( $column , $id ) { |
|
1364 global $post; |
|
1365 |
|
1366 if ($column == 'msgcontent' && $post->post_type == XDMSG ) |
|
1367 echo htmlspecialchars( $post->post_content ); |
|
1368 if ($column == 'msgpostmeta' && $post->post_type == XDMSG ) { |
|
1369 |
|
1370 $this->msg_link_display ( $id ); |
|
1371 } |
|
1372 if ($column == 'language' && $post->post_type == XDMSG ) { |
|
1373 if ( !class_exists ( 'xili_language' ) ) { |
|
1374 |
|
1375 $lang = $this->cur_lang( $id ); |
|
1376 echo $lang->name; |
|
1377 |
|
1378 } |
|
1379 } |
|
1380 |
|
1381 return; |
|
1382 |
|
1383 } |
|
1384 |
|
1385 // Register the column as sortable |
|
1386 function msgcontent_column_register_sortable( $columns ) { |
|
1387 $columns['msgcontent'] = 'msgcontent'; |
|
1388 $columns['msgpostmeta'] = 'msgpostmeta'; |
|
1389 return $columns; |
|
1390 } |
|
1391 |
|
1392 function msgcontent_column_orderby( $vars ) { |
|
1393 if ( isset( $vars['orderby'] ) && 'msgpostmeta' == $vars['orderby'] ) { |
|
1394 $vars = array_merge( $vars, array( |
|
1395 'meta_key' => $this->msgtype_meta, |
|
1396 'orderby' => 'meta_value' |
|
1397 ) ); |
|
1398 } |
|
1399 |
|
1400 return $vars; |
|
1401 } |
|
1402 |
|
1403 /** |
|
1404 * Add Languages selector in edit.php edit after Category Selector (hook: restrict_manage_posts) only if no XL |
|
1405 * |
|
1406 * @since 2.0 |
|
1407 * |
|
1408 */ |
|
1409 function restrict_manage_languages_posts () { |
|
1410 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
|
1411 ?> |
|
1412 <select name="lang" id="lang" class='postform'> |
|
1413 <option value=""> <?php _e('View all languages','xili-dictionary') ?> </option> |
|
1414 |
|
1415 <?php foreach ($listlanguages as $language) { |
|
1416 $selected = ( isset ( $_GET[QUETAG] ) && $language->slug == $_GET[QUETAG] ) ? "selected=selected" : "" ; |
|
1417 echo '<option value="'.$language->slug.'" '.$selected.' >'.__($language->description, 'xili-dictionary').'</option>'; |
|
1418 } |
|
1419 ?> |
|
1420 </select> |
|
1421 <?php |
|
1422 } |
|
1423 |
|
1424 /** |
|
1425 * Add Origin selector in edit.php edit |
|
1426 * |
|
1427 * @since 2.0 |
|
1428 * |
|
1429 */ |
|
1430 function restrict_manage_origin_posts () { |
|
1431 if ( isset ( $_GET['post_type'] ) && $_GET['post_type'] == XDMSG ) { |
|
1432 $listorigins = get_terms('origin', array('hide_empty' => false)); |
|
1433 if ( $listorigins != array() ) { |
|
1434 $selected = ""; |
|
1435 if ( isset ( $_GET['origin'] ) ) { |
|
1436 $selected = $_GET['origin']; |
|
1437 } |
|
1438 $dropdown_options = array( |
|
1439 'taxonomy' => 'origin', |
|
1440 'show_option_all' => __( 'View all origins', 'xili-dictionary' ), |
|
1441 'hide_empty' => 0, |
|
1442 'hierarchical' => 1, |
|
1443 'show_count' => 0, |
|
1444 'orderby' => 'name', |
|
1445 'name' => 'origin', |
|
1446 'selected' => $selected |
|
1447 ); |
|
1448 wp_dropdown_categories( $dropdown_options ); |
|
1449 } |
|
1450 } |
|
1451 } |
|
1452 |
|
1453 /** |
|
1454 * Add writer selector in edit.php edit |
|
1455 * |
|
1456 * @since 2.0 |
|
1457 * |
|
1458 */ |
|
1459 function restrict_manage_writer_posts () { |
|
1460 if ( isset ( $_GET['post_type'] ) && $_GET['post_type'] == XDMSG ) { |
|
1461 $listwriters = get_terms('writer', array('hide_empty' => false)); |
|
1462 if ( $listwriters != array() ) { |
|
1463 $selected = ""; |
|
1464 if ( isset ( $_GET['writer_name'] ) ) { |
|
1465 $selected = $_GET['writer_name']; |
|
1466 } |
|
1467 $dropdown_options = array( |
|
1468 'taxonomy' => 'writer', |
|
1469 'show_option_all' => __( 'View all writers', 'xili-dictionary' ), |
|
1470 'hide_empty' => 0, |
|
1471 'hierarchical' => 1, |
|
1472 'show_count' => 0, |
|
1473 'orderby' => 'name', |
|
1474 'name' => 'writer_name', |
|
1475 'selected' => $selected |
|
1476 ); |
|
1477 wp_dropdown_categories( $dropdown_options ); |
|
1478 } |
|
1479 } |
|
1480 } |
|
1481 |
|
1482 /** |
|
1483 * to fixes wp_dropdown_categories id value in option |
|
1484 * thanks to http://wordpress.stackexchange.com/questions/6066/query-custom-taxonomy-by-term-id |
|
1485 */ |
|
1486 function wpse6066_pre_get_posts( &$wp_query ) { |
|
1487 |
|
1488 if ( $wp_query->is_tax ) { ; |
|
1489 if ( is_numeric( $wp_query->get( 'writer_name' ) ) ) { |
|
1490 // Convert numberic terms to term slugs for dropdown |
|
1491 |
|
1492 $term = get_term_by( 'term_id', $wp_query->get( 'writer_name' ), 'writer' ); |
|
1493 |
|
1494 if ( $term ) { |
|
1495 $wp_query->set( 'writer_name', $term->slug ); |
|
1496 } |
|
1497 } |
|
1498 |
|
1499 if ( is_numeric( $wp_query->get( 'origin' ) ) ) { |
|
1500 |
|
1501 // Convert numberic terms to term slugs for dropdown |
|
1502 |
|
1503 $term = get_term_by( 'term_id', $wp_query->get( 'origin' ), 'origin' ); |
|
1504 |
|
1505 if ( $term ) { |
|
1506 $wp_query->set( 'origin', $term->slug ); |
|
1507 } |
|
1508 } |
|
1509 } |
|
1510 } |
|
1511 |
|
1512 |
|
1513 /** |
|
1514 * display msg comments |
|
1515 * |
|
1516 * @param post ID |
|
1517 * |
|
1518 */ |
|
1519 function msg_status_comments ( $id ) { |
|
1520 |
|
1521 $type = get_post_meta ( $id, $this->msgtype_meta, true); |
|
1522 // search msgid |
|
1523 if ( $type == 'msgid' ) { |
|
1524 $target_id = $id; |
|
1525 } elseif ( $type == 'msgid_plural' ) { |
|
1526 $temp_post = $this->temp_get_post ( $id ); |
|
1527 $target_id = $temp_post->post_parent; |
|
1528 } else { |
|
1529 $target_id = get_post_meta ( $id, $this->msgidlang_meta, true); |
|
1530 } |
|
1531 $for_bottom_box = array('link'=> '','state' => false ); |
|
1532 if ( $temp_post = $this->temp_get_post ( $target_id ) ) { |
|
1533 |
|
1534 $ctxt = get_post_meta ( $target_id, $this->ctxt_meta, true ); |
|
1535 if ( $ctxt != "" && $type != 'msgid' ) printf ( '<strong>ctxt:</strong> %s <br /><br />' , $ctxt ); |
|
1536 if ( $type == 'msgid' ) { |
|
1537 if ( isset ($_GET['msgaction'] ) && $_GET['msgaction'] == 'addctxt' ) { |
|
1538 ?> |
|
1539 <label for="add_ctxt"><?php _e('Context','xili-dictionary') ; ?></label> |
|
1540 <input id="add_ctxt" name="add_ctxt" value="<?php echo $ctxt; ?>" style="width:80%" /> |
|
1541 <?php |
|
1542 |
|
1543 } else { |
|
1544 if ( $ctxt != "" ) { |
|
1545 printf ( '<strong>ctxt:</strong> %s <br /><br />' , $ctxt ); |
|
1546 printf( __(' <a href="%s" >Edit context</a>', 'xili-dictionary'), 'post.php?post='.$id.'&action=edit&msgaction=addctxt' ); |
|
1547 } else { |
|
1548 // link to add ctxt |
|
1549 printf( __(' <a href="%s" >Create context</a>', 'xili-dictionary'), 'post.php?post='.$id.'&action=edit&msgaction=addctxt' ); |
|
1550 |
|
1551 } |
|
1552 } |
|
1553 } |
|
1554 // local or not |
|
1555 $linktotax =''; |
|
1556 $extracted_comments = get_post_meta ( $target_id, $this->msg_extracted_comments, true ); |
|
1557 if ( $extracted_comments != "" ) { |
|
1558 |
|
1559 $pattern = '/([^local\]].*?)from\s(.*?)\swith/'; |
|
1560 $matches = array(); |
|
1561 if ( 1 == preg_match($pattern, $extracted_comments, $matches) ) { |
|
1562 |
|
1563 $search = ''; |
|
1564 if ( $type == 'msgid' && false !== strpos( $extracted_comments, 'name from' ) ) |
|
1565 $search = '&s='.str_replace(' ', '+', $temp_post->post_content ); |
|
1566 |
|
1567 $linktotax = sprintf('<a href="%1s" >%2s</a>', 'edit-tags.php?taxonomy='.$matches[2].'&post_type=post'.$search, sprintf(__('Return to %s list', 'xili-dictionary'), $matches[2] )); |
|
1568 |
|
1569 } |
|
1570 } |
|
1571 |
|
1572 echo '<p>'; |
|
1573 |
|
1574 if ( $extracted_comments != "" ) |
|
1575 printf ( __('Extracted comments: %s', 'xili-dictionary').'<br />', $extracted_comments ); |
|
1576 |
|
1577 $translator_comments = get_post_meta ( $target_id, $this->msg_translator_comments, true ); |
|
1578 if ( $translator_comments != "") printf ( __('Translator comments: %s', 'xili-dictionary').'<br />', $translator_comments ); |
|
1579 $flags = get_post_meta ( $target_id, $this->msg_flags, true ); |
|
1580 if ( $flags != "") printf ( __('Flags: %s', 'xili-dictionary').'<br />', $flags ); |
|
1581 |
|
1582 echo '</p>'; |
|
1583 if ( $type == 'msgstr' || $type == 'msgstr_0' ) { |
|
1584 $translator_comments = get_post_meta ( $id, $this->msg_translator_comments, true ); |
|
1585 //if ( $translator_comments != "") printf ( __('Msgstr Translator comments: %s', 'xili-dictionary').'<br />', $translator_comments ); |
|
1586 |
|
1587 ?> |
|
1588 <label for="add_translator_comments"><?php _e('msgstr Translator comments','xili-dictionary') ; ?></label> |
|
1589 <input id="add_translator_comments" name="add_translator_comments" value="<?php echo $translator_comments; ?>" style="width:80%" /> |
|
1590 <?php |
|
1591 } |
|
1592 |
|
1593 |
|
1594 $lines = $temp_post->post_excerpt; |
|
1595 if ( $lines != "") { |
|
1596 echo '<p>'; |
|
1597 printf ( __('Lines: %s', 'xili-dictionary').'<br />', $lines ); |
|
1598 echo '</p>'; |
|
1599 } |
|
1600 echo '<p><strong>'.sprintf(__('Return to <a href="%s" title="Go to msg list">msg list</a>','xili-dictionary'), $this->xd_settings_page).'</strong> '.$linktotax.'</p>'; |
|
1601 echo ( $this->create_line_lang != "" ) ? '<p><strong>'.$this->create_line_lang.'</strong></p>' : "-"; |
|
1602 |
|
1603 |
|
1604 if ( $type == 'msgid' ) { |
|
1605 if ( ( $extracted_comments == "" ) || ( $extracted_comments != "" && false === strpos( $extracted_comments, $this->local_tag .' ' ) ) ) { |
|
1606 |
|
1607 $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=setlocal', 'xd-setlocal' ) ; |
|
1608 |
|
1609 $for_bottom_box['link'] = sprintf( __('Set in theme (<a href="%s" >set local</a>)', 'xili-dictionary'), $nonce_url ); |
|
1610 |
|
1611 } else { |
|
1612 $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=unsetlocal', 'xd-setlocal' ) ; |
|
1613 |
|
1614 $for_bottom_box['link'] = sprintf( __('Set in local (<a href="%s" >unset</a>)', 'xili-dictionary'), $nonce_url ); |
|
1615 $for_bottom_box['state'] = true; // false by default |
|
1616 } |
|
1617 } |
|
1618 |
|
1619 |
|
1620 } else { |
|
1621 printf ( __('The msgid (%d) was deleted. The msg series must be recreated and commented.','xili-dictionary' ), $target_id ); |
|
1622 echo '<p><strong>'.sprintf(__('Return to <a href="%s" title="Go to msg list">msg list</a>','xili-dictionary'), $this->xd_settings_page).'</strong></p>'; |
|
1623 } |
|
1624 return $for_bottom_box ; |
|
1625 } |
|
1626 |
|
1627 function update_msg_comments ( $post_id ) { |
|
1628 if ( get_post_type( $post_id ) == XDMSG ) { |
|
1629 // only visible if msgstr |
|
1630 $translator_comments = ( isset ( $_POST['add_translator_comments'] )) ? $_POST['add_translator_comments'] : "" ; |
|
1631 if ( '' != $translator_comments ) { |
|
1632 update_post_meta ( $post_id, $this->msg_translator_comments, $translator_comments ); |
|
1633 } |
|
1634 // add_ctxt |
|
1635 |
|
1636 if ( isset ( $_POST['add_ctxt'] ) ) { |
|
1637 $ctxt = $_POST['add_ctxt'] ; |
|
1638 if ( '' != $ctxt ) { |
|
1639 update_post_meta ( $post_id, $this->ctxt_meta, $ctxt ); |
|
1640 } else { |
|
1641 delete_post_meta ( $post_id, $this->ctxt_meta); |
|
1642 } |
|
1643 } |
|
1644 } |
|
1645 } |
|
1646 |
|
1647 /** |
|
1648 * msg dashboard left |
|
1649 * |
|
1650 * @since 2.0 |
|
1651 * |
|
1652 */ |
|
1653 function msg_status_display ( $id ) { |
|
1654 global $post; |
|
1655 $spanred = '<span class="alert">'; |
|
1656 $spanend = '</span>'; |
|
1657 |
|
1658 $type = get_post_meta ( $id, $this->msgtype_meta, true); |
|
1659 // search msgid |
|
1660 if ( $type == 'msgid' ) { |
|
1661 $msgid_id = $id; |
|
1662 } elseif ( $type == 'msgid_plural' ) { |
|
1663 $temp_post_msg_id_plural = $this->temp_get_post ( $id ); |
|
1664 $msgid_id = $temp_post_msg_id_plural->post_parent; |
|
1665 $temp_post_msg_id = $this->temp_get_post ( $msgid_id ); |
|
1666 } else { |
|
1667 $msgid_id = get_post_meta ( $id, $this->msgidlang_meta, true); |
|
1668 } |
|
1669 |
|
1670 if ( $temp_post_msg_id = $this->temp_get_post ( $msgid_id ) ) { |
|
1671 if ( defined ('WP_DEBUG') && WP_DEBUG == true ) { |
|
1672 //echo '<div class="msg-saved" >'; |
|
1673 //printf( __('%s saved as: <em>%s</em>', 'xili-dictionary'), $this->msg_str_labels[$type], $post->post_content ); |
|
1674 //echo '</div>'; |
|
1675 } |
|
1676 $res = get_post_meta ( $msgid_id, $this->msgchild_meta, false ); |
|
1677 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1678 |
|
1679 $res = get_post_meta ( $msgid_id, $this->msglang_meta, false ); |
|
1680 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1681 |
|
1682 if ( isset ($_GET['msgaction'] ) && isset ($_GET['langstr']) ) { // action to create child and default line - single or plural... |
|
1683 check_admin_referer( 'xd-langstr' ); |
|
1684 $target_lang = $_GET['langstr']; |
|
1685 if ( $_GET['msgaction'] == 'msgstr' && !isset( $thelangs['msgstrlangs'][$target_lang] ) ) { |
|
1686 // create post |
|
1687 if ( !isset ( $thechilds['msgid']['plural'] ) ) { |
|
1688 |
|
1689 $msgstr_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate:', 'xili-dictionary').$temp_post_msg_id->post_content , null, 'msgstr' , 0 ); |
|
1690 wp_set_object_terms( $msgstr_post_ID, $target_lang, TAXONAME ); |
|
1691 $thelangs['msgstrlangs'][$target_lang]['msgstr'] = $msgstr_post_ID; |
|
1692 update_post_meta ( $msgid_id, $this->msglang_meta, $thelangs ); |
|
1693 update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $msgid_id ); |
|
1694 |
|
1695 $translated_post_ID = $msgstr_post_ID; |
|
1696 //printf( 'msgstr created in %s <br/>', $target_lang ) ; |
|
1697 |
|
1698 } else { |
|
1699 // create msgstr_0 |
|
1700 $msgstr_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate (msgstr[0]): ', 'xili-dictionary').$temp_post_msg_id->post_content , null, 'msgstr_0' , 0 ); |
|
1701 wp_set_object_terms( $msgstr_post_ID, $target_lang, TAXONAME ); |
|
1702 $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] = $msgstr_post_ID; |
|
1703 update_post_meta ( $msgid_id, $this->msglang_meta, $thelangs ); |
|
1704 update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $msgid_id ); |
|
1705 |
|
1706 $translated_post_ID = $msgstr_post_ID; |
|
1707 //printf( 'msgstr[0] created in %s <br/>', $target_lang ) ; |
|
1708 |
|
1709 // create msgstr_1 |
|
1710 $temp_post_msg_id_plural = $this->temp_get_post ( $thechilds['msgid']['plural'] ); |
|
1711 $content_plural = htmlspecialchars( $temp_post_msg_id_plural->post_content ); |
|
1712 $msgstr_1_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate (msgstr[1]): ', 'xili-dictionary'). $content_plural , null, 'msgstr_1' , $msgstr_post_ID ); |
|
1713 wp_set_object_terms( $msgstr_1_post_ID, $target_lang, TAXONAME ); |
|
1714 $thelangs['msgstrlangs'][$target_lang]['plural'][1] = $msgstr_1_post_ID; |
|
1715 update_post_meta ( $msgid_id, $this->msglang_meta, $thelangs ); |
|
1716 update_post_meta ( $msgstr_1_post_ID, $this->msgidlang_meta, $msgid_id ); |
|
1717 |
|
1718 //printf( 'msgstr[1] created in %s <br/>', $target_lang ) ; |
|
1719 } |
|
1720 // redirect |
|
1721 |
|
1722 //if ( $translated_post_ID > 0 && $this->xili_settings['creation_redirect'] == 'redirect') { |
|
1723 $url_redir = admin_url().'post.php?post='.$translated_post_ID.'&action=edit'; |
|
1724 |
|
1725 ?> |
|
1726 <script type="text/javascript"> |
|
1727 <!-- |
|
1728 window.location= <?php echo "'" . $url_redir . "'"; ?>; |
|
1729 //--> |
|
1730 </script> |
|
1731 <?php |
|
1732 //} |
|
1733 } |
|
1734 } elseif ( isset ($_GET['msgaction']) && $_GET['msgaction'] == 'msgid_plural' && !isset( $thelangs['msgstrlangs'] ) ) { |
|
1735 check_admin_referer( 'xd-plural' ); |
|
1736 $msgid_plural_post_ID = $this->insert_one_cpt_and_meta ( __('XD say id to plural: ', 'xili-dictionary').$temp_post_msg_id->post_content , null, 'msgid_plural' , $msgid_id ); |
|
1737 $res = get_post_meta ( $msgid_id, $this->msgchild_meta, false ); |
|
1738 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1739 |
|
1740 } elseif ( $type == 'msgid' && isset ($_GET['msgaction']) && $_GET['msgaction'] == 'setlocal' ) { |
|
1741 check_admin_referer( 'xd-setlocal' ); |
|
1742 $extracted_comments = get_post_meta ( $msgid_id, $this->msg_extracted_comments, true ); |
|
1743 $extracted_comments = $this->local_tag .' '. $extracted_comments; |
|
1744 update_post_meta ( $msgid_id, $this->msg_extracted_comments, $extracted_comments ); |
|
1745 |
|
1746 } elseif ( $type == 'msgid' && isset ($_GET['msgaction']) && $_GET['msgaction'] == 'unsetlocal' ) { |
|
1747 check_admin_referer( 'xd-setlocal' ); |
|
1748 $extracted_comments = get_post_meta ( $msgid_id, $this->msg_extracted_comments, true ); |
|
1749 $extracted_comments = str_replace ( $this->local_tag .' ', '', $extracted_comments); |
|
1750 update_post_meta ( $msgid_id, $this->msg_extracted_comments, $extracted_comments ); |
|
1751 } |
|
1752 |
|
1753 |
|
1754 // display current saved content |
|
1755 |
|
1756 //if ( $type != "msgid" ) { |
|
1757 $line = __('msgid:', 'xili-dictionary'); |
|
1758 $line .= ' <strong>'. htmlspecialchars($temp_post_msg_id->post_content ) . '</strong>' ; |
|
1759 if ( $post->ID != $msgid_id ) { |
|
1760 $line .= sprintf( __('( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'),'post.php?post='.$msgid_id.'&action=edit', $msgid_id, __('Edit') ) ; |
|
1761 } else { |
|
1762 $line .= '<br />'; |
|
1763 } |
|
1764 $this->hightlight_line ( $line, $type, 'msgid' ); |
|
1765 //} |
|
1766 if ( isset ( $thechilds['msgid']['plural'] ) ) { |
|
1767 $post_status = get_post_status ( $thechilds['msgid']['plural'] ) ; |
|
1768 $line = ""; |
|
1769 if ( $post_status == "trash" || $post_status === false ) $line .= $spanred; |
|
1770 $line .= '<span class="msgid_plural">'. __('msgid_plural:', 'xili-dictionary') . '</span> '; |
|
1771 if ( $post_status == "trash" || $post_status === false ) $line .= $spanend; |
|
1772 $temp_post_msg_id_plural = $this->temp_get_post ( $thechilds['msgid']['plural'] ); |
|
1773 $content_plural = htmlspecialchars( $temp_post_msg_id_plural->post_content ); |
|
1774 $line .= '<strong>'. $content_plural . '</strong> ' ; |
|
1775 if ( $post->ID != $thechilds['msgid']['plural'] ) |
|
1776 $line .= sprintf( __('( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'),'post.php?post='.$thechilds['msgid']['plural'].'&action=edit', $thechilds['msgid']['plural'], __('Edit') ) ; |
|
1777 $this->hightlight_line ( $line, $type, 'msgid_plural' ); |
|
1778 |
|
1779 |
|
1780 } else { |
|
1781 if ( !isset ( $thelangs['msgstrlangs'] ) && !isset ( $thechilds['msgid']['plural'] ) ) { // not yet translated |
|
1782 |
|
1783 $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgid_plural', 'xd-plural' ) ; |
|
1784 printf( __(' <a href="%s" >Create msgid_plural</a>', 'xili-dictionary'), $nonce_url ); |
|
1785 echo '<br />'; |
|
1786 } |
|
1787 } |
|
1788 |
|
1789 // display series |
|
1790 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
|
1791 if (isset ( $thelangs['msgstrlangs'] ) ) { |
|
1792 $translated_langs = array (); |
|
1793 echo '<br /><table class="widefat"><thead><tr><th class="column-msgtrans">'; |
|
1794 _e( 'translated in', 'xili-dictionary'); |
|
1795 echo '</th><th>‟msgstr”</th></tr></thead><tbody>'; |
|
1796 foreach ( $thelangs['msgstrlangs'] as $curlang => $msgtr ) { |
|
1797 |
|
1798 $strid = 0; |
|
1799 if ( isset ( $msgtr['msgstr'] ) ) { |
|
1800 $strid = $msgtr['msgstr'] ; |
|
1801 $str_plural = false ; |
|
1802 $translated_langs[] = $curlang; |
|
1803 $typeref = 'msgstr'; |
|
1804 } elseif ( isset ( $msgtr['msgstr_0'] ) ) { |
|
1805 $strid = $msgtr['msgstr_0'] ; |
|
1806 $str_plural = true ; |
|
1807 $translated_langs[] = $curlang; // detect content empty |
|
1808 $typeref = 'msgstr_0'; |
|
1809 } |
|
1810 |
|
1811 if ( $strid != 0 ) { |
|
1812 $target_lang = implode ( ' ', wp_get_object_terms( $id, TAXONAME, $args = array( 'fields' => 'names')) ); |
|
1813 echo '<tr class="lang-'.strtolower($curlang).'" ><th><span>'; |
|
1814 printf( '%s : ', $curlang ); |
|
1815 echo '</span></th><td>'; |
|
1816 $temp_post = $this->temp_get_post ( $strid ); |
|
1817 $content = htmlspecialchars( $temp_post->post_content ); |
|
1818 $line = ""; |
|
1819 if ( $str_plural ) $line .= "[0] "; |
|
1820 |
|
1821 $line .= '‟<strong>'. $content . '</strong>”' ; |
|
1822 $post_status = get_post_status ( $strid ); |
|
1823 if ( $post_status == "trash" || $post_status === false ) $line .= $spanred; |
|
1824 if ( $post->ID != $strid ) { |
|
1825 $line .= sprintf( ' ( <a href="%s" title="link to:%d">%s</a> )<br />', 'post.php?post='.$strid.'&action=edit', $strid, __('Edit') ) ; |
|
1826 } else { |
|
1827 $line .= '<br />'; |
|
1828 } |
|
1829 if ( $post_status == "trash" || $post_status === false ) $line .= $spanend; |
|
1830 |
|
1831 $this->hightlight_line_str ( $line, $type, $typeref, $curlang, $target_lang ); |
|
1832 |
|
1833 if ( $str_plural ) { |
|
1834 $res = get_post_meta ( $strid, $this->msgchild_meta, false ); |
|
1835 $strthechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1836 foreach ( $strthechilds['msgstr']['plural'] as $key => $strchildid ) { |
|
1837 $temp_post = $this->temp_get_post ( $strchildid ); |
|
1838 $content = htmlspecialchars( $temp_post->post_content ); |
|
1839 $line = ""; |
|
1840 $post_status = get_post_status ( $strchildid ); // fixed 2.1 |
|
1841 if ( $post_status == "trash" || $post_status === false ) $line .= $spanred; |
|
1842 $line .= sprintf ( '[%s] ', $key ); |
|
1843 if ( $post_status == "trash" || $post_status === false ) $line .= $spanend; |
|
1844 if ( $post->ID != $strchildid ) { |
|
1845 $line .= sprintf ( '‟<strong>%s</strong>” ( %s )', $content, '<a href="post.php?post='.$strchildid.'&action=edit" title="link to:'.$strchildid.'">'.__('Edit').'</a>' ) ; |
|
1846 } else { |
|
1847 $line .= sprintf ( '‟<strong>%s</strong>”', $content ); |
|
1848 } |
|
1849 $this->hightlight_line_str ( $line, $type, 'msgstr_'.$key, $curlang, $target_lang ); |
|
1850 echo '<br />'; |
|
1851 } |
|
1852 // if possible against current lang add links - compare to count of $strthechilds['msgstr']['plural'] |
|
1853 |
|
1854 } |
|
1855 echo '</td></tr>'; |
|
1856 } |
|
1857 |
|
1858 } |
|
1859 echo '</tbody></table>'; |
|
1860 $this->create_line_lang = ""; |
|
1861 if ( count ($translated_langs) != count ($listlanguages) ) { |
|
1862 //echo '<br />'; |
|
1863 $this->create_line_lang = __('Create msgstr in: ', 'xili-dictionary'); |
|
1864 foreach ( $listlanguages as $tolang ) { |
|
1865 if ( !in_array ( $tolang->name , $translated_langs ) ) { |
|
1866 $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgstr&langstr='.$tolang->name, 'xd-langstr' ) ; |
|
1867 $this->create_line_lang .= sprintf( ' <a class="lang-'. strtolower($tolang->name).'" href="%s" >'.$tolang->name.'</a>', $nonce_url ); } |
|
1868 } |
|
1869 } |
|
1870 } else { |
|
1871 $this->create_line_lang = ""; |
|
1872 if ( !isset ($_POST['msgaction'] ) || ( isset ($_GET['msgaction'] ) && $_GET['msgaction'] == 'msgid_plural' ) ) { |
|
1873 _e( 'not yet translated.', 'xili-dictionary'); |
|
1874 |
|
1875 $this->create_line_lang = __('Create msgstr in: ', 'xili-dictionary'); |
|
1876 foreach ( $listlanguages as $tolang ) { |
|
1877 $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgstr&langstr='.$tolang->name, 'xd-langstr' ) ; |
|
1878 $this->create_line_lang .= sprintf( ' <a class="lang-'. strtolower( $tolang->name).'" href="%s" >'.$tolang->name.'</a>', $nonce_url ); } |
|
1879 } |
|
1880 } |
|
1881 } else { |
|
1882 |
|
1883 printf ( __('The msgid (%d) was deleted. The msg series must be recreated.','xili-dictionary' ), $msgid_id ); |
|
1884 } |
|
1885 } |
|
1886 |
|
1887 function hightlight_line ( $line, $cur_type, $type ) { |
|
1888 if ( $cur_type == $type) { |
|
1889 echo '<span class="editing msgidstyle">'. $line .'</span>'; |
|
1890 } else { |
|
1891 echo '<span class="msgidstyle">'. $line .'</span>'; |
|
1892 } |
|
1893 } |
|
1894 |
|
1895 function hightlight_line_str ( $line, $cur_type, $type, $cur_lang, $lang ) { |
|
1896 if ( $cur_type == $type && $cur_lang == $lang ) { |
|
1897 echo '<span class="editing msgstrstyle">'.$line.'</span>'; |
|
1898 } else { |
|
1899 echo '<span class="msgstrstyle">'. $line .'</span>'; |
|
1900 } |
|
1901 } |
|
1902 |
|
1903 |
|
1904 /** |
|
1905 * display msg series linked together |
|
1906 * |
|
1907 * @param post ID, display (true for single edit) |
|
1908 * |
|
1909 */ |
|
1910 function msg_link_display ( $id , $display = false, $thepost = null ) { |
|
1911 |
|
1912 if ( $thepost != null ) { |
|
1913 $post = $thepost ; |
|
1914 } else { |
|
1915 global $post ; |
|
1916 } |
|
1917 |
|
1918 $spanred = '<span class="alert">'; |
|
1919 $spanend = '</span>'; |
|
1920 // type |
|
1921 $type = get_post_meta ( $id, $this->msgtype_meta, true); |
|
1922 |
|
1923 $res = get_post_meta ( $id, $this->msgchild_meta, false ); |
|
1924 $thechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1925 |
|
1926 $res = get_post_meta ( $id, $this->msglang_meta, false ); |
|
1927 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1928 |
|
1929 if ( $type == 'msgid' ) { |
|
1930 $ctxt = get_post_meta ( $id, $this->ctxt_meta, true ); |
|
1931 if ( $post->post_status == "trash" ) echo $spanred; |
|
1932 if ( $display ) { |
|
1933 echo '<div class="msg-saved" >'; |
|
1934 printf( __('msgid saved as: <em>%s</em>', 'xili-dictionary'), ( $post->post_content ) ); |
|
1935 echo '</div>'; |
|
1936 } else { |
|
1937 echo 'msgid'; |
|
1938 } |
|
1939 if ( $post->post_status == "trash" ) echo $spanend; |
|
1940 echo '<br />'; |
|
1941 if ( $ctxt != "" && !$display ) printf ( 'ctxt: %s <br />' , $ctxt ); |
|
1942 |
|
1943 if ( isset ( $thechilds['msgid']['plural'] ) ) { |
|
1944 $post_status = get_post_status ( $thechilds['msgid']['plural'] ) ; |
|
1945 if ( !$display ) { |
|
1946 if ( $post_status == "trash" || $post_status === false ) echo $spanred; |
|
1947 printf( __('has plural: <a href="%s" >%d</a><br />', 'xili-dictionary'),'post.php?post='.$thechilds['msgid']['plural'].'&action=edit', $thechilds['msgid']['plural'] ) ; |
|
1948 if ( $post_status == "trash" || $post_status === false ) echo $spanend; |
|
1949 } else { |
|
1950 if ( $post_status == "trash" || $post_status === false ) echo $spanred; |
|
1951 _e('has plural:', 'xili-dictionary'); echo ' '; |
|
1952 if ( $post_status == "trash" || $post_status === false ) echo $spanend; |
|
1953 $temp_post = $this->temp_get_post ( $thechilds['msgid']['plural'] ); |
|
1954 $content_plural = htmlspecialchars( $temp_post->post_content ); |
|
1955 echo '<strong>'. $content_plural . '</strong> ' ; |
|
1956 printf( __('( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'),'post.php?post='.$thechilds['msgid']['plural'].'&action=edit', $thechilds['msgid']['plural'], __('Edit') ) ; |
|
1957 } |
|
1958 } else { |
|
1959 if ( $display && !isset ( $thelangs['msgstrlangs'] ) && !isset ( $thechilds['msgid']['plural'] ) ) { // not yet translated |
|
1960 |
|
1961 printf( __(' <a href="%s" >Create msgid_plural</a>', 'xili-dictionary'), 'post.php?post='.$id.'&action=edit&msgaction=msgid_plural' ); |
|
1962 echo '<br />'; |
|
1963 } |
|
1964 } |
|
1965 $res = get_post_meta ( $id, $this->msglang_meta, false ); |
|
1966 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
1967 // action to create child and default line - single or plural... |
|
1968 if ( isset ($_GET['msgaction'] ) && isset ($_GET['langstr']) && $display) { |
|
1969 $target_lang = $_GET['langstr']; |
|
1970 if ( $_GET['msgaction'] == 'msgstr' && !isset( $thelangs['msgstrlangs'][$target_lang] ) ) { |
|
1971 // create post |
|
1972 if ( !isset ( $thechilds['msgid']['plural'] ) ) { |
|
1973 |
|
1974 $msgstr_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate: ', 'xili-dictionary').$post->post_content , null, 'msgstr' , 0 ); |
|
1975 wp_set_object_terms( $msgstr_post_ID, $target_lang, TAXONAME ); |
|
1976 $thelangs['msgstrlangs'][$target_lang]['msgstr'] = $msgstr_post_ID; |
|
1977 update_post_meta ( $id, $this->msglang_meta, $thelangs ); |
|
1978 update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $id ); |
|
1979 |
|
1980 sprintf( 'msgstr created in %s <br/>', $target_lang ) ; |
|
1981 |
|
1982 } else { |
|
1983 // create msgstr_0 |
|
1984 $msgstr_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate (msgstr[0]): ', 'xili-dictionary').$post->post_content , null, 'msgstr_0' , 0 ); |
|
1985 wp_set_object_terms( $msgstr_post_ID, $target_lang, TAXONAME ); |
|
1986 $thelangs['msgstrlangs'][$target_lang]['msgstr_0'] = $msgstr_post_ID; |
|
1987 update_post_meta ( $id, $this->msglang_meta, $thelangs ); |
|
1988 update_post_meta ( $msgstr_post_ID, $this->msgidlang_meta, $id ); |
|
1989 |
|
1990 sprintf( 'msgstr[0] created in %s <br/>', $target_lang ) ; |
|
1991 |
|
1992 // create msgstr_1 |
|
1993 $msgstr_1_post_ID = $this->insert_one_cpt_and_meta ( __('XD say to translate (msgstr[1]): ', 'xili-dictionary'). $content_plural , null, 'msgstr_1' , $msgstr_post_ID ); |
|
1994 wp_set_object_terms( $msgstr_1_post_ID, $target_lang, TAXONAME ); |
|
1995 $thelangs['msgstrlangs'][$target_lang]['plural'][1] = $msgstr_1_post_ID; |
|
1996 update_post_meta ( $id, $this->msglang_meta, $thelangs ); |
|
1997 update_post_meta ( $msgstr_1_post_ID, $this->msgidlang_meta, $msgid_id ); |
|
1998 |
|
1999 sprintf( 'msgstr[1] created in %s <br/>', $target_lang ) ; |
|
2000 } |
|
2001 } elseif ( $_GET['msgaction'] == 'msgid_plural' && !isset( $thelangs['msgstrlangs'][$target_lang] ) ) { |
|
2002 |
|
2003 $msgid_plural_post_ID = $this->insert_one_cpt_and_meta ( __('XD say id to plural: ', 'xili-dictionary').$post->post_content , null, 'msgid_plural' , $id ); |
|
2004 |
|
2005 } |
|
2006 } |
|
2007 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
|
2008 if (isset ( $thelangs['msgstrlangs'] ) ) { |
|
2009 //$thelangs['msgstrlangs'][$curlang]['msgstr'] = $msgstr_post_ID; |
|
2010 |
|
2011 $translated_langs = array (); |
|
2012 if ( $display ) { |
|
2013 echo '<br /><table class="widefat"><thead><tr><th class="column-msgtrans">'; |
|
2014 _e( 'translated in', 'xili-dictionary'); |
|
2015 echo '</th><th>msgstr</th></tr></thead><tbody>'; |
|
2016 } else { |
|
2017 echo ( __( 'translated in', 'xili-dictionary').':<br />'); |
|
2018 } |
|
2019 foreach ( $thelangs['msgstrlangs'] as $curlang => $msgtr ) { |
|
2020 |
|
2021 $strid = 0; |
|
2022 if ( isset ( $msgtr['msgstr'] ) ) { |
|
2023 $strid = $msgtr['msgstr'] ; |
|
2024 $str_plural = false ; |
|
2025 $translated_langs[] = $curlang; |
|
2026 } elseif ( isset ( $msgtr['msgstr_0'] ) ) { |
|
2027 $strid = $msgtr['msgstr_0'] ; |
|
2028 $str_plural = true ; |
|
2029 $translated_langs[] = $curlang; // detect content empty |
|
2030 } |
|
2031 |
|
2032 if ( $strid != 0 ) { |
|
2033 if ( !$display ) { |
|
2034 // get strid status |
|
2035 $post_status = get_post_status ( $strid ); |
|
2036 if ( $post_status == "trash" || $post_status === false ) echo $spanred; |
|
2037 printf( '- %s : <a href="%s" >%d</a><br />', $curlang, 'post.php?post='.$strid.'&action=edit', $strid ) ; |
|
2038 if ( $post_status == "trash" || $post_status === false ) echo $spanend; |
|
2039 } else { |
|
2040 echo '<tr><th>'; |
|
2041 printf( '%s : ', $curlang ); |
|
2042 echo '</th><td>'; |
|
2043 $temp_post = $this->temp_get_post ( $strid ); |
|
2044 $content = htmlspecialchars( $temp_post->post_content ); |
|
2045 |
|
2046 if ( $str_plural ) echo "[0] "; |
|
2047 |
|
2048 echo '<strong>'. $content . '</strong>' ; |
|
2049 $post_status = get_post_status ( $strid ); |
|
2050 if ( $post_status == "trash" || $post_status === false ) echo $spanred; |
|
2051 printf( ' ( <a href="%s" title="link to:%d">%s</a> )<br />', 'post.php?post='.$strid.'&action=edit', $strid, __('Edit') ) ; |
|
2052 if ( $post_status == "trash" || $post_status === false ) echo $spanend; |
|
2053 |
|
2054 if ( $str_plural ) { |
|
2055 $res = get_post_meta ( $strid, $this->msgchild_meta, false ); |
|
2056 $strthechilds = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
2057 foreach ( $strthechilds['msgstr']['plural'] as $key => $strchildid ) { |
|
2058 $temp_post = $this->temp_get_post ( $strchildid ); |
|
2059 $content = htmlspecialchars( $temp_post->post_content ); |
|
2060 $post_status = get_post_status ( $strchildid ); |
|
2061 if ( $post_status == "trash" || $post_status === false ) echo $spanred; |
|
2062 printf ( '[%s] ', $key ); |
|
2063 if ( $post_status == "trash" || $post_status === false ) echo $spanend; |
|
2064 printf ( '<strong>%s</strong> ( %s )<br />', $content, '<a href="post.php?post='.$strchildid.'&action=edit" title="link to:'.$strchildid.'">'.__('Edit').'</a>' ) ; |
|
2065 |
|
2066 } |
|
2067 // if possible against current lang add links - compare to count of $strthechilds['msgstr']['plural'] |
|
2068 |
|
2069 } |
|
2070 echo '</td></tr>'; |
|
2071 } |
|
2072 } |
|
2073 |
|
2074 } |
|
2075 if ( $display ) echo '</tbody></table>'; |
|
2076 $this->create_line_lang = ""; |
|
2077 if ( $display && ( count ($translated_langs) != count ($listlanguages) ) ) { |
|
2078 //echo '<br />'; |
|
2079 $this->create_line_lang = __('Create msgstr in: ', 'xili-dictionary'); |
|
2080 foreach ( $listlanguages as $tolang ) { |
|
2081 if ( !in_array ( $tolang->name , $translated_langs ) ) { |
|
2082 $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgstr&langstr='.$tolang->name, 'xd-langstr' ) ; |
|
2083 $this->create_line_lang .= sprintf( ' <a href="%s" >'.$tolang->name.'</a>', $nonce_url ); |
|
2084 } |
|
2085 } |
|
2086 } |
|
2087 |
|
2088 } else { // no translation |
|
2089 if ( !isset ($_POST['msgaction'] ) || ( isset ($_GET['msgaction'] ) && $_GET['msgaction'] == 'msgid_plural' ) ) { |
|
2090 _e( 'not yet translated.', 'xili-dictionary'); |
|
2091 echo ' '; |
|
2092 if ( $display ) { |
|
2093 _e('Create msgstr in: ', 'xili-dictionary'); |
|
2094 |
|
2095 foreach ( $listlanguages as $tolang ) { |
|
2096 $nonce_url = wp_nonce_url ('post.php?post='.$id.'&action=edit&msgaction=msgstr&langstr='.$tolang->name, 'xd-langstr' ) ; |
|
2097 printf( ' <a href="%s" >'.$tolang->name.'</a>', $nonce_url ); |
|
2098 } |
|
2099 } |
|
2100 } |
|
2101 } |
|
2102 |
|
2103 |
|
2104 } elseif ( $type != '' ) { |
|
2105 |
|
2106 $msgid_ID = get_post_meta ( $id, $this->msgidlang_meta , true); |
|
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 if ( $display && ( $type == 'msgid_plural' || ( false !== strpos( $type, 'msgstr_' ) && substr( $type, -1 ) !='0') ) ) { |
|
2112 $temp_post = $this->temp_get_post ( $post->post_parent ); |
|
2113 $content = htmlspecialchars( $temp_post->post_content ) ; |
|
2114 $target_lang = implode ( ' ', wp_get_object_terms( $id, TAXONAME, $args = array( 'fields' => 'names')) ); |
|
2115 $is_plural = true; |
|
2116 } elseif ( $display ) { |
|
2117 $temp_post = $this->temp_get_post ( $msgid_ID ); |
|
2118 $content = htmlspecialchars( $temp_post->post_content ) ; |
|
2119 $target_lang = implode ( ' ', wp_get_object_terms( $id, TAXONAME, $args = array( 'fields' => 'names')) ); |
|
2120 $is_plural = false; |
|
2121 } |
|
2122 |
|
2123 $span_msgid = ( get_post_status ( $msgid_ID ) == "trash" || get_post_status ( $msgid_ID ) === false ) ; |
|
2124 $span_parent = ( get_post_status ( $post->post_parent ) == "trash" || get_post_status ( $post->post_parent ) === false ) ; |
|
2125 |
|
2126 if ( $display ) { |
|
2127 echo '<div class="msg-saved" >'; |
|
2128 printf( __('%s saved as: <em>%s</em>', 'xili-dictionary'), $this->msg_str_labels[$type], $post->post_content ); |
|
2129 echo '</div>'; |
|
2130 } |
|
2131 |
|
2132 switch ( $type ) { |
|
2133 case 'msgid_plural': |
|
2134 |
|
2135 if ( $span_parent ) echo $spanred ; |
|
2136 if ( $display ) { |
|
2137 printf( __('msgid plural of: <strong>%s</strong> ( <a href="%s" title="link to:%d" >%s</a> )<br />', 'xili-dictionary'), $content,'post.php?post='.$post->post_parent.'&action=edit', $post->post_parent, __('Edit') ); |
|
2138 } else { |
|
2139 printf( __('msgid plural of: <a href="%s" >%d</a><br />', 'xili-dictionary'),'post.php?post='.$post->post_parent.'&action=edit',$post->post_parent ) ; |
|
2140 } |
|
2141 if ( $span_parent ) echo $spanend ; |
|
2142 |
|
2143 |
|
2144 break; |
|
2145 case 'msgstr': |
|
2146 if ( $display ) echo '<strong>'.$target_lang."</strong> translation of: <strong>" . $content . '</strong> '; |
|
2147 if ( $span_msgid ) echo $spanred ; |
|
2148 if ( $display ) { |
|
2149 printf( __('( <a href="%s" title = "link of:%d">%s</a> )<br />', 'xili-dictionary'), 'post.php?post='.$msgid_ID.'&action=edit', $msgid_ID, __('Edit') ); |
|
2150 } else { |
|
2151 |
|
2152 printf( __('msgstr of: <a href="%s" >%d</a><br />', 'xili-dictionary'), 'post.php?post='.$msgid_ID.'&action=edit', $msgid_ID ); |
|
2153 } |
|
2154 if ( $span_msgid ) echo $spanend ; |
|
2155 //if ( $display ) echo '<strong>'.$content .'</strong>'; |
|
2156 break; |
|
2157 |
|
2158 default: |
|
2159 if ( false !== strpos( $type, 'msgstr_' ) ) { |
|
2160 $indices = explode ('_', $type); |
|
2161 $indice = $indices[1]; |
|
2162 $edit_id = ( $indice == 0 ) ? $msgid_ID : $post->post_parent ; |
|
2163 |
|
2164 if ( $display ) { |
|
2165 if ( $is_plural ) { |
|
2166 printf(__( '<strong>%s</strong> plural of: <strong>%s</strong>( <a href="%s" title="link to:%d">%s</a> )<br />', ''),$target_lang, $content, 'post.php?post='.$edit_id.'&action=edit' , $edit_id, __('Edit') ); |
|
2167 } else { |
|
2168 printf(__( '<strong>%s</strong> translation of: <strong>%s</strong>( <a href="%s" title="link to:%d">%s</a> )<br />', ''),$target_lang, $content, 'post.php?post='.$edit_id.'&action=edit' , $edit_id, __('Edit') ); |
|
2169 } |
|
2170 } else { |
|
2171 if ( $indice == 0 ) { |
|
2172 if ( $span_msgid ) echo $spanred ; |
|
2173 printf( __('msgstr of: <a href="%s" >%d</a><br />', 'xili-dictionary'), 'post.php?post='.$msgid_ID.'&action=edit', $msgid_ID ); |
|
2174 if ( $span_msgid ) echo $spanend ; |
|
2175 } else { |
|
2176 if ( $span_parent ) echo $spanred ; |
|
2177 printf( __('msgstr[%d] plural of: <a href="%s" >%d</a><br />', 'xili-dictionary'), $indice, 'post.php?post='.$post->post_parent.'&action=edit', $post->post_parent ) ; |
|
2178 if ( $span_parent ) echo $spanend ; |
|
2179 } |
|
2180 } |
|
2181 if ( $display && $indice > 0) { |
|
2182 printf(__('go to <a href="%s" title="link to:%d">msgid</a>', 'xili-dictionary'), 'post.php?post='.$msgid_ID.'&action=edit', $msgid_ID ) ; |
|
2183 } |
|
2184 } |
|
2185 } |
|
2186 |
|
2187 } |
|
2188 return $type; |
|
2189 } |
|
2190 |
|
2191 function temp_get_post ( $post_id ) { |
|
2192 global $wpdb ; |
|
2193 $res = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id)); |
|
2194 if ( $res && !is_wp_error($res) ) |
|
2195 return $res; |
|
2196 else |
|
2197 return false; |
|
2198 } |
|
2199 |
|
2200 /** |
|
2201 * unset autosave for msg |
|
2202 * @since 2.0 |
|
2203 */ |
|
2204 function auto_save_unsetting() { |
|
2205 global $hook_suffix, $post ; |
|
2206 $type = ''; |
|
2207 if ( isset($_GET['post_type']) ) |
|
2208 $type = $_GET['post_type']; |
|
2209 |
|
2210 if ( ( $hook_suffix == 'post-new.php' && $type == XDMSG ) || ( $hook_suffix == 'post.php' && $post->post_type == XDMSG )) { |
|
2211 |
|
2212 wp_dequeue_script('autosave'); |
|
2213 //wp_deregister_script('autosave'); |
|
2214 //$wp_scripts->queue = array_diff( $wp_scripts->queue , array('autosave') ); |
|
2215 } |
|
2216 } |
|
2217 |
|
2218 |
|
2219 /** |
|
2220 * Reset values when theme was changed... updated by previous function |
|
2221 * @since 1.0.5 |
|
2222 */ |
|
2223 function xd_theme_switched ($theme) { |
|
2224 $this->xili_settings['langs_folder'] ="unknown"; |
|
2225 /* to force future search in new theme */ |
|
2226 update_option('xili_dictionary_settings', $this->xili_settings); |
|
2227 } |
|
2228 |
|
2229 /** |
|
2230 * @since 1.3.0 for js in tools list |
|
2231 */ |
|
2232 function admin_enqueue_scripts() { |
|
2233 wp_enqueue_script( 'datatables', plugins_url('js/jquery.dataTables.min.js', __FILE__ ) , array( 'jquery' ), '1.7.4', true ); |
|
2234 } |
|
2235 |
|
2236 function admin_enqueue_styles() { |
|
2237 wp_enqueue_style('table_xdstyle'); // style of js table |
|
2238 } |
|
2239 |
|
2240 function admin_init() { |
|
2241 /* Register our script. */ |
|
2242 wp_register_script( 'datatables', plugins_url('js/jquery.dataTables.min.js', __FILE__ ) ); |
|
2243 wp_register_style( 'table_xdstyle', plugins_url('/css/xd_table.css', __FILE__ ), array(), XILIDICTIONARY_VER, 'screen' ); |
|
2244 } |
|
2245 |
|
2246 /** |
|
2247 *add admin menu and associated page |
|
2248 */ |
105 function xili_add_dict_pages() { |
2249 function xili_add_dict_pages() { |
106 $this->thehook = add_management_page(__('Dictionary','xili-dictionary'), __('Dictionary','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings')); |
2250 |
107 add_action('load-'.$this->thehook, array(&$this,'on_load_page')); |
2251 //$this->thehook = add_management_page(__('Xili Dictionary','xili-dictionary'), __('xili Dictionary','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings')); |
108 add_action( "admin_print_scripts-".$this->thehook, array(&$this,'xili_add_js')); |
2252 |
|
2253 $this->thehook = add_submenu_page( 'edit.php?post_type='.XDMSG, __('Xili Dictionary','xili-dictionary'), __('Tools, Files po mo','xili-dictionary'), 'import', 'dictionary_page', array(&$this,'xili_dictionary_settings') ); |
|
2254 |
|
2255 add_action('load-'.$this->thehook, array(&$this,'on_load_page')); |
|
2256 |
|
2257 add_action( 'admin_print_scripts-'.$this->thehook, array(&$this,'admin_enqueue_scripts') ); |
|
2258 add_action( 'admin_print_styles-'.$this->thehook, array(&$this,'admin_enqueue_styles') ); |
|
2259 |
|
2260 // Add to end of admin_menu action function |
|
2261 global $submenu; |
|
2262 $submenu['edit.php?post_type='.XDMSG][5][0] = __('Msg list','xili-dictionary'); // sub menu |
|
2263 $post_type_object = get_post_type_object(XDMSG); |
|
2264 $post_type_object->labels->name = __('XD Msg list','xili-dictionary'); // title list screen |
|
2265 |
|
2266 $this->insert_news_pointer ( 'xd_new_version' ); // pointer in menu for updated version |
|
2267 add_action( 'admin_print_footer_scripts', array(&$this, 'print_the_pointers_js') ); |
109 } |
2268 } |
110 |
2269 |
111 function on_load_page() { |
2270 function on_load_page() { |
112 wp_enqueue_script('common'); |
2271 wp_enqueue_script('common'); |
113 wp_enqueue_script('wp-lists'); |
2272 wp_enqueue_script('wp-lists'); |
114 wp_enqueue_script('postbox'); |
2273 wp_enqueue_script('postbox'); |
115 |
2274 |
116 add_meta_box('xili-dictionary-sidebox-1', __('Message','xili-dictionary'), array(&$this,'on_sidebox_1_content'), $this->thehook , 'side', 'core'); |
2275 add_meta_box('xili-dictionary-sidebox-message', __('Message','xili-dictionary'), array(&$this,'on_sidebox_message_content'), $this->thehook , 'side', 'core'); |
117 add_meta_box('xili-dictionary-sidebox-2', __('Info','xili-dictionary'), array(&$this,'on_sidebox_2_content'), $this->thehook , 'side', 'core'); |
2276 add_meta_box('xili-dictionary-sidebox-info', __('Info','xili-dictionary'), array(&$this,'on_sidebox_info_content'), $this->thehook , 'side', 'core'); |
118 |
2277 add_meta_box('xili-dictionary-sidebox-style', __('XD style settings','xili-dictionary'), array(&$this,'on_sidebox_style_content'), $this->thehook , 'side', 'core'); |
119 |
|
120 } |
2278 } |
121 |
2279 |
122 /** |
2280 /** |
123 * Add action link(s) to plugins page |
2281 * Add action link(s) to plugins page |
124 * |
2282 * |
130 static $this_plugin; |
2288 static $this_plugin; |
131 |
2289 |
132 if (!$this_plugin ) $this_plugin = plugin_basename(__FILE__); |
2290 if (!$this_plugin ) $this_plugin = plugin_basename(__FILE__); |
133 |
2291 |
134 if ($file == $this_plugin ) { |
2292 if ($file == $this_plugin ) { |
135 $settings_link = '<a href="tools.php?&page=dictionary_page">' . __('Settings') . '</a>'; |
2293 $settings_link = '<a href="'.$this->xd_settings_page.'">' . __('Settings') . '</a>'; |
136 $links = array_merge( array($settings_link), $links); // before other links |
2294 $links = array_merge( array($settings_link), $links); // before other links |
137 } |
2295 } |
138 return $links; |
2296 return $links; |
139 } |
2297 } |
140 |
2298 |
141 function init_textdomain() { |
2299 function init_textdomain() { |
142 /*multilingual for admin pages and menu*/ |
2300 /*multilingual for admin pages and menu*/ |
143 load_plugin_textdomain('xili-dictionary',PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__))); |
2301 |
144 |
2302 load_plugin_textdomain('xili-dictionary', false, 'xili-dictionary/languages' ); |
145 if (!defined('THEME_LANGS_FOLDER')) { /* set or detect at least a .mo or .po */ |
2303 |
146 if ($this->xili_settings['langs_folder'] == "") { |
2304 if ( class_exists('xili_language') ) { |
147 $this->find_files(get_template_directory(), '/.[mp]o$/', array(&$this,'searchpath')); |
2305 global $xili_language ; |
148 update_option('xili_dictionary_settings', $this->xili_settings); |
2306 $langs_folder = $xili_language->xili_settings['langs_folder']; // set by override_load_textdomain filter |
149 } |
2307 if ( $this->xili_settings['langs_folder'] != $langs_folder ) { |
150 define('THEME_LANGS_FOLDER',$this->xili_settings['langs_folder']); // for bkwd compatibility with xili-dictionary |
2308 $this->xili_settings['langs_folder'] = $langs_folder ; |
151 } |
2309 update_option('xili_dictionary_settings', $this->xili_settings); |
152 } |
2310 } |
|
2311 } else { |
|
2312 if ( file_exists( $this->get_template_directory ) ) // when theme was unavailable |
|
2313 $this->find_files($this->get_template_directory, '/^.*\.(mo|po|pot)$/', array(&$this,'searchpath')); |
|
2314 } |
|
2315 } |
|
2316 |
|
2317 /* call by findfiles */ |
153 function searchpath($path, $filename) { |
2318 function searchpath($path, $filename) { |
154 $this->xili_settings['langs_folder'] = str_replace(get_template_directory(),'',$path); |
2319 $langs_folder = str_replace($this->get_template_directory,'',$path); // updated 1.2.0 |
155 } |
2320 if ( $this->xili_settings['langs_folder'] != $langs_folder ) { |
156 |
2321 $this->xili_settings['langs_folder'] = $langs_folder ; |
|
2322 update_option('xili_dictionary_settings', $this->xili_settings); |
|
2323 } |
|
2324 } |
|
2325 |
157 function xililanguage_state() { |
2326 function xililanguage_state() { |
158 /* test if xili-language is present or was present */ |
2327 /* test if xili-language is present or was present */ |
159 if (class_exists('xili_language')) { |
2328 if (class_exists('xili_language')) { |
|
2329 |
160 $this->xililanguage = 'isactive'; |
2330 $this->xililanguage = 'isactive'; |
|
2331 |
161 } else { |
2332 } else { |
162 /* test if language taxonomy relationships are present */ |
2333 /* test if language taxonomy relationships are present */ |
163 $xl_settings = get_option('xili_language_settings'); |
2334 $xl_settings = get_option('xili_language_settings'); |
164 if (empty($xl_settings)) { |
2335 if ( empty($xl_settings) ) { |
165 $this->xililanguage = 'neveractive'; |
2336 $this->xililanguage = 'neveractive'; |
166 } else { |
2337 } else { |
167 $this->xililanguage = 'wasactive'; |
2338 $this->xililanguage = 'wasactive'; |
168 } |
2339 } |
169 } |
2340 } |
170 } |
2341 } |
171 /** * @since 1.02 */ |
2342 /** * @since 1.02 */ |
172 function fill_default_languages_list() { |
2343 function fill_default_languages_list() { |
173 if ($this->xililanguage == 'neveractive' || $this->xililanguage == 'wasactive') { |
2344 if ( $this->xililanguage == 'neveractive' || $this->xililanguage == 'wasactive' ) { |
174 |
2345 |
175 if (!$this->xili_settings[XDDICTLANGS]) { |
2346 if ( !isset( $this->xili_settings['xl-dictionary-langs'] ) ) { |
|
2347 |
176 $default_langs_array = array( |
2348 $default_langs_array = array( |
177 'en_us' => array('en_US', 'english'), |
2349 'en_us' => array('en_US', 'english'), |
178 'fr_fr' => array('fr_FR', 'french'), |
2350 'fr_fr' => array('fr_FR', 'french'), |
179 'de_de' => array('de_DE', 'german'), |
2351 'de_de' => array('de_DE', 'german'), |
180 'es_es' => array('es_ES', 'spanish'), |
2352 'es_es' => array('es_ES', 'spanish'), |
181 'it_it' => array('it_IT', 'italian') |
2353 'it_it' => array('it_IT', 'italian'), |
|
2354 'pt_pt' => array('pt_PT', 'portuguese'), |
|
2355 'ru_ru' => array('ru_RU', 'russian'), |
|
2356 'zh_cn' => array('zh_CN', 'chinese'), |
|
2357 'ja' => array('ja', 'japanese'), |
|
2358 'ar_ar' => array('ar_AR', 'arabic') |
182 ); |
2359 ); |
183 /* add wp admin lang */ |
2360 /* add wp admin lang */ |
184 if (defined ('WPLANG')) { |
2361 if ( defined ('WPLANG') ) { |
185 $lkey = strtolower(WPLANG); |
2362 $lkey = strtolower(WPLANG); |
186 if (!array_key_exists($lkey, $default_langs_array)) $default_langs_array[$lkey] = array (WPLANG, WPLANG); |
2363 if (!array_key_exists($lkey, $default_langs_array)) $default_langs_array[$lkey] = array (WPLANG, WPLANG); |
187 } |
2364 } |
188 $this->xili_settings[XDDICTLANGS] = $default_langs_array; |
2365 $this->xili_settings['xl-dictionary-langs'] = $default_langs_array; |
189 update_option('xili_dictionary_settings', $this->xili_settings); |
2366 update_option('xili_dictionary_settings', $this->xili_settings); |
190 } |
2367 } |
191 } |
2368 } |
192 } |
2369 } |
193 |
2370 |
194 /** |
2371 /** |
195 * private function to update grouping of terms if xili-language is active |
2372 * for slug with 5 (_fr_fr) or 2 letters (as japanese) |
196 * |
2373 * |
197 * |
2374 */ |
198 * |
2375 function extract_extend ( $line_slug ) { |
199 */ |
2376 $end = substr($line_slug, -6 ) ; |
200 function update_terms_langs_grouping() { |
2377 if ( substr($end, 0, 1) == '_' && substr($end, 3, 1) == '_' ) { |
201 if ($this->xililanguage == 'isactive') { |
2378 return substr($line_slug, -5 ); |
202 |
2379 } else { |
203 $listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false,'get'=>'all')); |
2380 return substr($line_slug, -2 ); // as ja |
204 if (!empty($listdictiolines)) { |
2381 } |
205 foreach ($listdictiolines as $dictioline) { |
2382 } |
206 /* check slug before creating relationship if parent = O select msgid */ |
2383 |
207 if ($dictioline->parent != 0) { |
2384 function popupmenu_language_list ( $action = "" ) { ?> |
208 $extend = substr($dictioline->slug,-5); |
2385 <select name="target_lang" ><?php |
209 $lang = get_term_by('slug',$extend,TAXONAME,OBJECT); |
2386 $extend = WPLANG; |
210 if ($lang) { |
2387 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
211 $term = $lang->name; |
2388 if ( $listlanguages ) { |
212 } else { |
2389 foreach ($listlanguages as $reflanguage) { |
213 $term = $extend; |
2390 echo '<option value="'.$reflanguage->name.'"'; |
214 } |
2391 if ($extend == $reflanguage->name) { |
215 $args = array( 'alias_of' => '', 'description' => 'Dictionary Group in '.$term, 'parent' => 0, 'slug' =>$extend); |
2392 echo ' selected="selected"'; |
216 $theids = wp_insert_term( $term, XDDICTLANGS, $args); |
2393 } |
217 wp_set_object_terms((int) $dictioline->term_id, $extend, XDDICTLANGS,false); |
2394 echo ">".__($reflanguage->description,'xili-dictionary').'</option>'; |
218 } |
2395 |
219 } |
2396 } |
220 } |
2397 } |
221 } |
2398 if ( $action=='import' ) { // to import .pot of current domain 1.0.5 |
222 } |
2399 if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0 |
|
2400 $theme_name = get_option("stylesheet"); |
|
2401 } else { |
|
2402 $theme_name = get_option("template"); |
|
2403 } |
|
2404 if (function_exists('the_theme_domain')) {// in new xili-language |
|
2405 echo '<option value="'.the_theme_domain().'" >'.the_theme_domain().'.pot</option>'; |
|
2406 } else { |
|
2407 |
|
2408 echo '<option value="'.$theme_name.'" >'.$theme_name.'.pot</option>'; |
|
2409 } |
|
2410 } |
|
2411 ?> |
|
2412 </select> |
|
2413 <?php |
|
2414 } |
223 |
2415 |
224 /** |
2416 /** |
225 * private functions for dictionary_settings |
2417 * private functions for dictionary_settings |
226 * @since 0.9.3 |
2418 * @since 0.9.3 |
227 * |
2419 * |
228 * fill the content of the boxes (right side and normal) |
2420 * fill the content of the boxes (right side and normal) |
229 * |
2421 * |
230 */ |
2422 */ |
231 |
2423 |
232 function on_sidebox_1_content($data) { |
2424 function on_sidebox_message_content($data) { |
233 extract($data); |
2425 extract($data); |
234 ?> |
2426 ?> |
235 <h4><?php _e('Note:','xili-dictionary') ?></h4> |
2427 <h4><?php _e('Note:','xili-dictionary') ?></h4> |
236 <p><?php echo $message;?></p> |
2428 <p><?php echo $message; ?></p> |
237 <?php |
2429 <?php |
238 } |
2430 } |
239 |
2431 |
240 function on_sidebox_2_content() { ?> |
2432 function get_theme_name () { |
241 |
2433 if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0 |
242 <p><?php _e('xili-dictionary is a plugin (compatible with xili-language) to build a multilingual dictionary saved in the taxonomy tables of WordPress. With this dictionary, it is possible to create and update .mo file in the current theme folder. And more...','xili-dictionary') ?></p> |
2434 $theme_name = get_option("stylesheet").' '.__('child of','xili-dictionary').' '.get_option("template"); |
243 <fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"><legend><?php echo __("Theme's informations:",'xili-dictionary').' ('.get_option("template").')'; ?></legend> |
2435 } else { |
244 <p> |
2436 $theme_name = get_option("template"); |
245 <?php $langfolder = (defined('THEME_LANGS_FOLDER')) ? THEME_LANGS_FOLDER : $this->xili_settings['langs_folder']; |
2437 } |
|
2438 return $theme_name; |
|
2439 } |
|
2440 |
|
2441 function on_sidebox_info_content() { |
|
2442 $template_directory = $this->get_template_directory; |
|
2443 |
|
2444 $theme_name = $this->get_theme_name (); |
|
2445 if ( $this->xililanguage_ms ) { |
|
2446 echo '<p><em>'.__('xili-language-ms is active !','xili-dictionary').'</em></p>'; |
|
2447 |
|
2448 } else { |
|
2449 switch ( $this->xililanguage ) { |
|
2450 case 'neveractive'; |
|
2451 echo '<p>'.__('xili-language plugin is not present !','xili-dictionary').'</p>'; |
|
2452 break; |
|
2453 case 'wasactive'; |
|
2454 echo '<p>'.__('xili-language plugin is not activated !','xili-dictionary').'</p><br />'; |
|
2455 break; |
|
2456 } |
|
2457 } |
|
2458 ?> |
|
2459 <p><?php _e('xili-dictionary is a plugin (compatible with xili-language) to build a multilingual dictionary saved in the taxonomy tables of WordPress. With this dictionary, it is possible to create and update .mo file in the current theme folder. And more...','xili-dictionary') ?> |
|
2460 </p> |
|
2461 <fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"> |
|
2462 <legend><?php echo __("Theme's informations:",'xili-dictionary').' ('. $theme_name .')'; ?></legend> |
|
2463 <p> |
|
2464 <?php $langfolder = $this->xili_settings['langs_folder']; |
246 echo __("Languages sub-folder:",'xili-dictionary').' '. $langfolder; ?><br /> |
2465 echo __("Languages sub-folder:",'xili-dictionary').' '. $langfolder; ?><br /> |
247 <?php _e('Available MO files:','xili-dictionary'); echo '<br />'; |
2466 <?php |
248 $this->find_files(get_template_directory(), '/.mo$/', array(&$this,'available_mo_files')) ;?> |
2467 if ( $langfolder == 'unknown' ) { ?><span style='color:red'><?php |
249 </p> |
2468 _e("No languages files are present in theme's folder or theme's sub-folder: <strong>add at least a .po or a .mo inside.</strong><br /> Errors will occur if you try to import or export!",'xili-dictionary'); echo '<br />'; ?></span> <?php |
250 </fieldset> |
2469 } else { |
|
2470 _e('Available MO files:','xili-dictionary'); echo '<br />'; |
|
2471 if ( file_exists( $this->get_template_directory ) ) // when theme was unavailable |
|
2472 $this->find_files($this->get_template_directory, '/.mo$/', array(&$this,'available_mo_files')) ; |
|
2473 } |
|
2474 |
|
2475 ?> |
|
2476 </p> |
|
2477 </fieldset> |
|
2478 |
251 |
2479 |
252 <?php |
2480 <?php |
253 } |
2481 } |
254 |
2482 |
255 function on_normal_1_content($data) { |
2483 function on_sidebox_style_content() { |
|
2484 ?> |
|
2485 <p> <?php _e( 'External file xd-style.css for dashboard (flags, customization)','xili-dictionary' ); ?></p> |
|
2486 <?php |
|
2487 if ( ! $this->exists_style_ext ) { |
|
2488 |
|
2489 echo '<p>'. __( 'There is no style for dashboard','xili-dictionary' ) .' ('.$this->style_message . ' )</p>'; |
|
2490 |
|
2491 } else { |
|
2492 |
|
2493 echo '<p>'. $this->style_message . '</p>'; |
|
2494 } |
|
2495 |
|
2496 if ( $this->xili_settings['external_xd_style'] == "on" ) { |
|
2497 |
|
2498 $style_action = __( 'No style for dashboard','xili-dictionary' ); |
|
2499 $what = 'off'; |
|
2500 |
|
2501 } else { |
|
2502 |
|
2503 $style_action = __( 'Activate style for dashboard','xili-dictionary' ); |
|
2504 $what = 'on'; |
|
2505 } |
|
2506 ?> |
|
2507 |
|
2508 <fieldset style="margin:2px; padding:6px 6px; "><strong><?php _e('Dictionary Styles','xili-dictionary') ;?></strong><br /><br /> |
|
2509 <?php |
|
2510 $url = "?post_type=xdmsg&action=setstyle&what=".$what."&page=dictionary_page"; |
|
2511 $nonce_url = wp_nonce_url( $url, 'xdsetstyle' ); |
|
2512 ?> |
|
2513 <a class="action-button grey-button" href="<?php echo $nonce_url ?>" title="<?php _e( 'Change style mode', 'xili-dictionary') ?>"><?php _e( $style_action ) ?></a> |
|
2514 |
|
2515 </fieldset> <?php |
|
2516 } |
|
2517 |
|
2518 /** |
|
2519 * @since 2.0 with datatables js (ex widefat) |
|
2520 * |
|
2521 */ |
|
2522 function on_normal_cpt_content_list( $data ) { |
256 extract($data); |
2523 extract($data); |
257 $sortparent = (($this->subselect == '') ? '' : '&tagsgroup_parent_select='.$this->subselect ); |
2524 $sortparent = (($this->subselect == '') ? '' : '&tagsgroup_parent_select='.$this->subselect ); |
258 ?> |
2525 ?> |
259 <table class="widefat"> |
2526 <div id="topbanner"> |
260 <thead> |
2527 </div> |
261 <tr> |
2528 <div id="tableupdating"> |
262 <th scope="col"><a href="?page=dictionary_page"><?php _e('ID') ?></a></th> |
2529 </div> |
263 <th scope="col"><a href="?page=dictionary_page&orderby=name<?php echo $sortparent; ?>"><?php _e('Text') ?></a></th> |
2530 <table class="display" id="linestable"> |
264 |
2531 <thead> |
265 <th scope="col"><a href="?page=dictionary_page&orderby=slug<?php echo $sortparent; ?>"><?php _e('Slug','xili-dictionary') ?></a></th> |
2532 <tr> |
266 <th scope="col" ><?php _e('Group','xili-dictionary') ?></th> |
2533 <th scope="col" class="center colid"><a href="<?php echo $this->xd_settings_page; ?>" ><?php _e('ID') ?></a></th> |
267 |
2534 <th scope="col" class="coltexte"><a href="<?php echo $this->xd_settings_page.'&orderby=name'.$sortparent; ?>"><?php _e('Text') ?></a> |
268 <th colspan="2"><?php _e('Action') ?></th> |
2535 </th> |
269 </tr> |
2536 <th scope="col" class="colslug"><?php _e('Metas','xili-dictionary') ?></th> |
270 </thead> |
2537 <th scope="col" class="colgroup center"><?php _e('Save status','xili-dictionary') ?></th> |
271 <tbody id="the-list"> |
2538 <th colspan="2"><?php _e('Action') ?></th> |
272 <?php $this->xili_dict_row($orderby,$tagsnamelike,$tagsnamesearch); /* the lines */ |
2539 </tr> |
|
2540 </thead> |
|
2541 <tbody id="the-list"> |
|
2542 <?php $this->xili_dict_cpt_row( $orderby, $tagsnamelike, $tagsnamesearch ); /* the lines */ |
273 ?> |
2543 ?> |
274 </tbody> |
2544 </tbody> |
275 </table> |
2545 </table> |
276 <?php if ($action=='edit' || $action=='delete') :?> |
2546 <div id="bottombanner"> |
277 <p>(<a href="?action=add&page=dictionary_page"><?php _e('Add a term','xili-dictionary') ?></a>)</p> |
2547 </div> |
278 <?php endif; |
2548 <?php |
279 } |
2549 } |
280 |
2550 |
281 function on_normal_2_content($data) { |
2551 /** |
282 extract($data); |
2552 * metabox shared by dialogs before actions with XD list |
283 |
2553 * |
284 /* the create - edit - delete form */ ?> |
2554 */ |
285 <div style="background:#f5f5fe;"> |
2555 function on_normal_2_files_dialog ( $data ) { |
286 <p id="add_edit"><?php _e($formhow,'xili-dictionary') ?></p> |
2556 extract( $data ); |
|
2557 ?> |
|
2558 <div style="background:#f5f5fe;"> |
|
2559 <div class="dialogcontainer" > |
|
2560 |
|
2561 <p id="add_edit"><?php _e( $formhow, 'xili-dictionary') ?></p> |
287 <?php |
2562 <?php |
288 if ($action=='export' || $action=='importmo' || $action=='import' || $action=='exportpo' ) { ?> |
2563 if ( $action=='export' || $action=='importmo' || $action=='import' || $action=='exportpo' ) { |
289 |
2564 |
290 <label for="language_file"> |
2565 $theme_name = $this->get_theme_name(); |
291 <select name="language_file" ><?php |
2566 |
|
2567 // left column ?> |
|
2568 <div class="dialoglang"> |
|
2569 <label for="language_file"> |
|
2570 <select name="language_file" ><?php |
292 $extend = WPLANG; |
2571 $extend = WPLANG; |
293 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
2572 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' );//get_terms(TAXONAME, array('hide_empty' => false)); |
294 if (is_wp_error($listlanguages) || empty($listlanguages)) { |
2573 if ( $listlanguages ) { |
295 $langs_array = $this->xili_settings[XDDICTLANGS]; |
|
296 echo '<option value="" >...</option>'; |
|
297 foreach ($langs_array as $lkey => $reflanguage) { |
|
298 echo '<option value="'.$reflanguage[0].'"'; |
|
299 if ($extend == $reflanguage[0]) { |
|
300 echo ' selected="selected"'; |
|
301 } |
|
302 echo ">".__($reflanguage[1],'xili-dictionary').'</option>'; |
|
303 } |
|
304 } else { |
|
305 |
|
306 foreach ($listlanguages as $reflanguage) { |
2574 foreach ($listlanguages as $reflanguage) { |
307 echo '<option value="'.$reflanguage->name.'"'; |
2575 echo '<option value="'.$reflanguage->name.'"'; |
308 if ($extend == $reflanguage->name) { |
2576 if ($extend == $reflanguage->name) { |
309 echo ' selected="selected"'; |
2577 echo ' selected="selected"'; |
310 } |
2578 } |
311 echo ">".__($reflanguage->description,'xili-dictionary').'</option>'; |
2579 echo ">".__($reflanguage->description,'xili-dictionary').'</option>'; |
312 |
2580 |
313 } |
2581 } |
314 } ?> |
2582 } |
315 </select></label> |
2583 if ( $action=='import' ) { // to import .pot of current domain 1.0.5 |
316 <br /> <br /> |
2584 if ( function_exists('the_theme_domain') ) {// in new xili-language |
317 <input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" /> <input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /><br /></div> |
2585 echo '<option value="'.the_theme_domain().'" >'.the_theme_domain().'.pot</option>'; |
|
2586 } else { |
|
2587 |
|
2588 echo '<option value="'.$theme_name.'" >'.$theme_name.'.pot</option>'; |
|
2589 } |
|
2590 } |
|
2591 ?> |
|
2592 </select> |
|
2593 </label> |
|
2594 </div> |
|
2595 <div class="dialogfile"> |
|
2596 <?php // middle column |
|
2597 |
|
2598 if ( $action == 'import' ) { // import po comment option 2.0-rc2 |
|
2599 |
|
2600 ?> |
|
2601 |
|
2602 <label for="importing_po_comments"> <?php _e( 'What about comments', 'xili-dictionary' ); ?>: |
|
2603 <select name="importing_po_comments" id="importing_po_comments"> |
|
2604 <option value="" ><?php _e('No change','xili-dictionary'); ?></option> |
|
2605 <option value="replace" ><?php _e('Imported comments replace those in list','xili-dictionary'); ?></option> |
|
2606 <option value="append" ><?php _e('Imported comments be appended...','xili-dictionary'); ?></option> |
|
2607 </select> |
|
2608 </label> |
|
2609 <?php |
|
2610 } |
|
2611 |
|
2612 if ( ($action=='export' || $action=='exportpo' ) && is_multisite() && is_super_admin() && $this->xililanguage_ms ) { ?> |
|
2613 <p><?php printf (__('Verify before that you are authorized to write in languages folder in theme named: %s','xili-dictionary'), $theme_name ) ?> |
|
2614 </p> |
|
2615 <?php } |
|
2616 if ( ( $action=='export' || $action=='exportpo' ) && is_multisite() && is_super_admin() && !$this->xililanguage_ms ) { ?> |
|
2617 <label for="only-theme"> |
|
2618 <?php |
|
2619 if ( $action == 'export' ) { |
|
2620 printf ( __('SuperAdmin: %sonly as theme .mo','xili-dictionary'), '<br />') ; |
|
2621 } else { |
|
2622 printf ( __('SuperAdmin: %sonly as theme .po','xili-dictionary'), '<br />') ; |
|
2623 } |
|
2624 ?> |
|
2625 <input id="only-theme" name="only-theme" type="checkbox" value="only" /> |
|
2626 </label> |
|
2627 |
|
2628 <?php } |
|
2629 |
|
2630 if ( $action=='export' || $action=='exportpo' ) { ?> |
|
2631 <br /><br /><label for="only-local"> |
|
2632 <?php |
|
2633 if ( $action == 'export' ) { |
|
2634 _e('Save only local-xx_XX.mo sub-selection','xili-dictionary'); |
|
2635 |
|
2636 } else { |
|
2637 _e('Save only local-xx_XX.po sub-selection','xili-dictionary'); |
|
2638 } |
|
2639 |
|
2640 ?> |
|
2641 <input id="only-local" name="only-local" type="checkbox" value="local" /> |
|
2642 </label> |
|
2643 |
|
2644 <?php } |
|
2645 |
|
2646 ?> |
|
2647 </div> |
|
2648 <?php |
|
2649 if ( $action=='import' || $action=='importmo' ) { |
|
2650 echo '<div class="dialogorigin">'; |
|
2651 echo '<label><input type="checkbox" id="local-import" name="local-import" value="local-import" /> ' . sprintf(__('import terms from local-xx_YY.%s', 'xili-dictionary'), ( ($action=='import') ? 'po' : 'mo' ) ) . '</label>'; |
|
2652 echo '</div>'; |
|
2653 } |
|
2654 // check origin theme |
|
2655 if ( $action=='export' || $action=='exportpo' ) { |
|
2656 if ( function_exists('is_child_theme') && is_child_theme() ) { |
|
2657 $cur_theme_name = get_option("stylesheet"); |
|
2658 } else { |
|
2659 $cur_theme_name = get_option("template"); |
|
2660 } |
|
2661 $listterms = get_terms( 'origin', array('hide_empty' => false) ); |
|
2662 echo '<div class="dialogorigin">'; |
|
2663 if ( $listterms ) { |
|
2664 $checkline = __ ( 'Check Origin(s) to be exported', 'xili-dictionary' ).':<br />'; |
|
2665 $i = 0; |
|
2666 echo '<table class="checktheme" ><tr>'; |
|
2667 foreach ( $listterms as $onetheme) { |
|
2668 $checked = ( $onetheme->name == $cur_theme_name ) ? 'checked="checked"' : '' ; |
|
2669 $checkline .= '<td><input type="checkbox" '. $checked .' id="theme-'.$onetheme->term_id.'" name="theme-'.$onetheme->term_id.'" value="'.$onetheme->slug.'" /> ' . $onetheme->name .'</td>'; |
|
2670 $i++; |
|
2671 if ( ($i % 2) == 0 ) $checkline .= '</tr><tr>'; |
|
2672 } |
|
2673 echo $checkline.'</tr></table>'; |
|
2674 } |
|
2675 echo '</div>'; |
|
2676 } |
|
2677 // end container ?> |
|
2678 </div> |
|
2679 <div class="dialogbbt"> |
|
2680 <input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" /> |
|
2681 <input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /> |
|
2682 </div> |
|
2683 </div> |
318 <?php |
2684 <?php |
319 } elseif ($action=='importcats' || $action=='erasedictionary' || $action=='importcurthemeterms') { |
2685 } elseif ($action=='importbloginfos' || $action=='importtaxonomy' || $action=='erasedictionary' || $action=='importcurthemeterms') { |
|
2686 |
|
2687 if ( $action == 'importtaxonomy' ) { ?> |
|
2688 <label for="taxonomy_name"><?php _e('Slug:','xili-dictionary') ?></label> |
|
2689 <input name="taxonomy_name" id="taxonomy_name" type="text" value="<?php echo ( $selecttaxonomy != '') ? $selecttaxonomy : 'category'; ?>" /><br /> |
|
2690 <?php } |
320 ?> |
2691 ?> |
321 |
2692 <br /> <br /> |
322 <br /> <br /> |
2693 <input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" /> |
323 <input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" /> |
2694 <input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /><br /> |
324 <input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /><br /></div> |
2695 </div> |
|
2696 </div> |
325 <?php |
2697 <?php |
326 |
2698 // nothing inside |
327 |
|
328 } else { |
2699 } else { |
329 //print_r($dictioline); |
2700 echo '<p>'.__( 'This box is used for input dialog, leave it opened and visible…', 'xili-dictionary' ).'</p></div></div>'; |
330 |
2701 } |
331 /* rules for edit dictioline */ |
2702 ?> |
332 $noedit = "" ; $noedited = "" ; |
2703 <?php |
333 if ($action=='edit' && $dictioline->parent == 0) { |
2704 } |
334 $noedited = 'disabled="disabled"'; |
2705 |
335 $extend = ""; |
2706 /** |
336 } elseif ($action=='edit') { |
2707 * @since 2.1 |
337 /* search default */ |
2708 * built checked themes array |
338 $extend = substr($dictioline->slug,-5); |
2709 * |
339 } elseif ($action=='delete' && $dictioline->parent == 0) { |
2710 */ |
340 $noedit = 'disabled="disabled"'; |
2711 function checked_themes_array( ) { |
341 $extend = ""; |
2712 $checked_themes = array(); |
342 } elseif ($action=='delete') { |
2713 $listterms = get_terms( 'origin', array('hide_empty' => false) ); |
343 $noedit = 'disabled="disabled"'; |
2714 if ( $listterms ) { |
344 $extend = substr($dictioline->slug,-5); |
2715 foreach ( $listterms as $onetheme) { |
345 } |
2716 $idcheck = 'theme-'.$onetheme->term_id; |
346 ?> |
2717 if ( isset ( $_POST[$idcheck] ) ) $checked_themes[] = $onetheme->name; |
347 <table class="editform" width="100%" cellspacing="2" cellpadding="5"> |
2718 } |
348 <tr> |
2719 } |
349 <?php if ($action=='edit' || $action=='delete') { |
2720 return $checked_themes; |
350 $areacontent = $dictioline->description; |
2721 } |
351 $textareas = explode(XPLURAL,$dictioline->description); |
2722 |
352 $firstcontent = $textareas[0]; /* also always before js splitting*/ |
2723 /** |
353 } else { |
2724 * @updated 1.0.2 |
354 $areacontent = ""; |
2725 * manage files |
355 $firstcontent = ""; |
2726 */ |
356 } |
2727 function on_normal_3_content( $data ) { |
357 ?> |
2728 extract( $data ); |
358 <th scope="row" valign="top" align="right" width="25%"><label for="dictioline_description1"> |
2729 ?> |
359 <?php |
2730 <h4 id="manage_file"><?php _e('The files','xili-dictionary') ;?></h4> |
360 if ($action=='edit' && $dictioline->parent == 0) { |
2731 <a class="action-button blue-button" href="<?php echo $this->xd_settings_page.'&action=export'; ?>" title="<?php _e('Create or Update mo file in current theme folder','xili-dictionary') ?>"><?php _e('Export mo file','xili-dictionary') ?></a> |
361 _e('Full msgid (original)','xili-dictionary'); |
2732 <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> |
362 } elseif ($action=='edit') { |
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 /> |
363 _e('Full msgstr (translation)','xili-dictionary'); |
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> |
364 } else { |
2735 |
365 _e('Full msg (id or str)','xili-dictionary'); |
2736 <h4 id="manage_categories"><?php _e('The taxonomies','xili-dictionary') ;?></h4> |
366 } ?> : </label> |
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> |
367 <textarea style="visibility:hidden" name="dictioline_description" id="dictioline_description" cols="12" rows="3" disabled="disabled" ><?php echo $areacontent; ?></textarea> |
2738 |
368 </th> |
2739 <h4 id="manage_website_infos"><?php _e('The website infos (title, sub-title and more…)','xili-dictionary') ;?></h4> |
369 <td align="left"> |
2740 <?php if ( class_exists ('xili_language') && XILILANGUAGE_VER > '2.3.9' ) { |
370 |
2741 _e ( '…and comment, locale, date terms.', 'xili-dictionary' ); echo '<br /><br />'; |
371 <input type="hidden" id="termnblines" name="termnblines" value="1" /> |
2742 } ?> |
372 |
2743 <a class="action-button blue-button" href="<?php echo $this->xd_settings_page.'&action=importbloginfos'; ?>" title="<?php _e('Import infos of web site and more','xili-dictionary') ?>"><?php _e("Import terms of website's infos",'xili-dictionary') ?></a> |
373 <div id="input1" style="margin-bottom:4px;" class="clonedInput"> |
2744 |
374 <p id="areatitle1"><?php _e('Singular text','xili-dictionary'); ?></p> |
2745 <h4 id="manage_dictionary"><?php _e('Dictionary','xili-dictionary') ;?></h4> |
375 <textarea style="visibility:visible" class="plural" name="dictioline_description1" id="dictioline_description1" cols="50" rows="3" <?php echo $noedit; ?> ><?php echo $firstcontent; ?></textarea> |
2746 <a class="action-button grey-button" href="?post_type=xdmsg&action=erasedictionary&page=dictionary_page" title="<?php _e('Erase all terms of dictionary ! (but not .mo or .po files)','xili-dictionary') ?>"><?php _e('Erase all terms','xili-dictionary') ?></a> |
376 |
2747 |
377 </div> |
2748 <?php // erase and import theme |
378 <?php if ($action != 'delete') { ?> |
2749 } |
379 <div> |
2750 |
380 <span style="display:block; float:right; width:60%"><small> <?php _e('Use only plural terms if theme contains _n() functions','xili-dictionary') ?></small></span> |
2751 /** |
381 <input type="button" id="btnAdd" value="<?php _e('Add a plural','xili-dictionary') ?>" /> |
2752 * @since 090423 - |
382 <input type="button" id="btnDel" value="<?php _e('Delete a plural','xili-dictionary') ?>" /> |
2753 * Sub selection box |
383 |
2754 */ |
384 </div> |
|
385 <?php } ?> |
|
386 </td> |
|
387 |
|
388 </tr> |
|
389 <tr class="form-field"> |
|
390 <th scope="row" valign="top" align="right"><label for="dictioline_lang"><?php _e('Language','xili-dictionary') ?></label> : </th> |
|
391 <td> |
|
392 <select name="dictioline_lang" id="dictioline_lang" <?php echo $noedit.$noedited;?> > |
|
393 <option value="" <?php if ($extend == '') { ?> selected="selected"<?php } ?>> |
|
394 <?php _e('default','xili-dictionary'); ?></option> |
|
395 <?php $listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $curlang)); |
|
396 if (is_wp_error($listlanguages) || empty($listlanguages)) { |
|
397 $langs_array = $this->xili_settings[XDDICTLANGS]; |
|
398 foreach ($langs_array as $lkey => $reflanguage) { |
|
399 echo '<option value="'.$reflanguage[0].'"'; |
|
400 if ($extend == strtolower($reflanguage[0])) { |
|
401 echo ' selected="selected"'; |
|
402 } |
|
403 echo ">".__($reflanguage[1],'xili-dictionary').'</option>'; |
|
404 } |
|
405 |
|
406 } else { |
|
407 foreach ($listlanguages as $reflanguage) { |
|
408 echo '<option value="'.$reflanguage->slug.'"'; |
|
409 if ($extend == $reflanguage->slug) { |
|
410 echo ' selected="selected"'; |
|
411 } |
|
412 echo ">".__($reflanguage->description,'xili-dictionary').'</option>'; |
|
413 |
|
414 } |
|
415 } |
|
416 ?> |
|
417 </select> |
|
418 </td> |
|
419 </tr> |
|
420 <tr> |
|
421 <th scope="row" valign="top" align="right"><label for="dictioline_slug"><?php _e('Term slug','xili-dictionary') ?></label> : </th> |
|
422 <td><input name="dictioline_slug" id="dictioline_slug" type="text" readonly="readonly" value="<?php echo attribute_escape($dictioline->slug); ?>" size="40" <?php echo $noedit; ?> /></td> |
|
423 </tr> |
|
424 <tr class="form-field"> |
|
425 <th scope="row" valign="top" align="right"><label for="dictioline_parent"><?php _e('Relationship (msgid)','xili-dictionary') ?></label> : </th> |
|
426 <td> |
|
427 <fieldset style="margin:2px; padding:10px 5px; border:1px solid #ccc;"><legend><?php |
|
428 if ($action=='edit' || $action=='delete') { |
|
429 if ($dictioline->parent == 0) { |
|
430 _e('Original','xili-dictionary'); |
|
431 } else { |
|
432 _e('Translation','xili-dictionary'); |
|
433 } |
|
434 } else { |
|
435 _e('Original or translation','xili-dictionary'); |
|
436 } |
|
437 ?></legend> |
|
438 <?php $this->xili_select_row($term_id,$dictioline); /* choice of parent line */?> |
|
439 </fielset> |
|
440 </td> |
|
441 </tr> |
|
442 <tr> |
|
443 <th scope="row" valign="top" align="right"><label for="alias_of"><?php _e('Alias of','xili-dictionary') ?></label> : </th> |
|
444 <td><input name="alias_of" id="alias_of" type="text" value="" size="40" <?php echo $noedit; ?> /></td> |
|
445 </tr> |
|
446 <?php if ($action=='edit') { ?> |
|
447 <tr> |
|
448 <th scope="row" valign="top" align="right" style="color:#eee;"><label for="dictioline_name"><?php _e('Text') ?> : </label></th> |
|
449 <td style="color:#eee;"><?php echo attribute_escape($dictioline->name); ?></td> |
|
450 </tr> |
|
451 <?php } ?> |
|
452 <tr> |
|
453 <th><input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /></th> |
|
454 <td> |
|
455 <p class="submit"><input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" /></p> |
|
456 </td> |
|
457 </tr> |
|
458 </table></div> |
|
459 <?php |
|
460 if ($action=='edit' || $action=='delete') { ?> |
|
461 <input type="hidden" name="dictioline_term_id" value="<?php echo $dictioline->term_id ?>" /> |
|
462 <?php } |
|
463 if ($action=='edit') { ?> |
|
464 <input type="hidden" name="dictioline_name" id="dictioline_name" value="<?php echo attribute_escape($dictioline->name); ?>" /> |
|
465 <?php } |
|
466 } |
|
467 } |
|
468 /** * @updated 1.0.2 * manage files */ |
|
469 function on_normal_3_content($data) { ?> |
|
470 <h4 id="manage_file"><?php _e('The files','xili-dictionary') ;?></h4> |
|
471 <?php |
|
472 switch ($this->xililanguage) { |
|
473 case 'neveractive'; |
|
474 echo '<p>'._e('xili-language plugin is not present !','xili-dictionary').'</p>'; |
|
475 break; |
|
476 case 'wasactive'; |
|
477 echo '<p>'._e('xili-language plugin is not activated !','xili-dictionary').'</p><br />'; |
|
478 break; |
|
479 } |
|
480 $linkstyle = "text-decoration:none; text-align:center; display:block; width:70%; margin:0px 1px 1px 30px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;" ; |
|
481 $linkstyle3 = "text-decoration:none; text-align:center; display:inline-block; width:16%; margin:0px 1px 1px 10px; padding:4px 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; border:1px #ccc solid;" ; |
|
482 $linkstyle1 = $linkstyle." border:1px #33f solid;"; |
|
483 $linkstyle2 = $linkstyle." border:1px #ccc solid;"; |
|
484 ?> |
|
485 <a style="<?php echo $linkstyle1 ; ?>" href="?action=export&page=dictionary_page" title="<?php _e('Create or Update mo file in current theme folder','xili-dictionary') ?>"><?php _e('Export mo file','xili-dictionary') ?></a> |
|
486 <br /><?php _e('Import po/mo file','xili-dictionary') ?>:<a style="<?php echo $linkstyle3 ; ?>" href="?action=import&page=dictionary_page" title="<?php _e('Import an existing .po file from current theme folder','xili-dictionary') ?>">PO</a> |
|
487 <a style="<?php echo $linkstyle3 ; ?>" href="?action=importmo&page=dictionary_page" title="<?php _e('Import an existing .mo file from current theme folder','xili-dictionary') ?>">MO</a><br /> |
|
488 <br /><a style="<?php echo $linkstyle2 ; ?>" href="?action=exportpo&page=dictionary_page" title="<?php _e('Create or Update po file in current theme folder','xili-dictionary') ?>"><?php _e('Export po file','xili-dictionary') ?></a> |
|
489 <h4 id="manage_categories"><?php _e('The categories','xili-dictionary') ;?></h4> |
|
490 <a style="<?php echo $linkstyle2 ; ?>" href="?action=importcats&page=dictionary_page" title="<?php _e('Import name and description of categories','xili-dictionary') ?>"><?php _e('Import terms of categories','xili-dictionary') ?></a> |
|
491 <h4 id="manage_dictionary"><?php _e('Dictionary','xili-dictionary') ;?></h4> |
|
492 <a style="<?php echo $linkstyle2 ; ?>" href="?action=erasedictionary&page=dictionary_page" title="<?php _e('Erase all terms of dictionary ! (but not .mo or .po files)','xili-dictionary') ?>"><?php _e('Erase all terms','xili-dictionary') ?></a> |
|
493 <br /><a style="<?php echo $linkstyle2 ; ?>" href="?action=importcurthemeterms&page=dictionary_page" title="<?php _e('Import all terms from current theme files - alpha test -','xili-dictionary') ?>"><?php _e('Import all terms from current theme','xili-dictionary') ?></a> |
|
494 |
|
495 <?php |
|
496 } |
|
497 /** * @since 090423 - */ |
|
498 function on_normal_4_content($data=array()) { |
2755 function on_normal_4_content($data=array()) { |
499 extract($data); |
2756 extract($data); |
500 ?> |
2757 ?> |
501 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Sub list of terms','xili-dictionary'); ?></legend> |
2758 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"> |
502 <label for="tagsnamelike"><?php _e('Starting with:','xili-dictionary') ?></label> |
2759 <legend><?php _e('Sub list of terms','xili-dictionary'); ?></legend> |
503 <input name="tagsnamelike" id="tagsnamelike" type="text" value="<?php echo $tagsnamelike; ?>" /><br /> |
2760 <label for="tagsnamelike"><?php _e('Starting with:','xili-dictionary') ?></label> |
504 <label for="tagsnamesearch"><?php _e('Containing:','xili-dictionary') ?></label> |
2761 <input name="tagsnamelike" id="tagsnamelike" type="text" value="<?php echo $tagsnamelike; ?>" /><br /> |
505 <input name="tagsnamesearch" id="tagsnamesearch" type="text" value="<?php echo $tagsnamesearch; ?>" /> |
2762 <label for="tagsnamesearch"><?php _e('Containing:','xili-dictionary') ?></label> |
506 <p class="submit"><input type="submit" id="tagssublist" name="tagssublist" value="<?php _e('Sub select…','xili-dictionary'); ?>" /> <input type="submit" id="notagssublist" name="notagssublist" value="<?php _e('No select…','xili-dictionary'); ?>" /></p> |
2763 <input name="tagsnamesearch" id="tagsnamesearch" type="text" value="<?php echo $tagsnamesearch; ?>" /> |
507 </fieldset> |
2764 <p class="submit"> |
508 |
2765 <input type="submit" id="tagssublist" name="tagssublist" value="<?php _e('Sub select…','xili-dictionary'); ?>" /> |
509 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Selection by language','xili-dictionary'); ?></legend> |
2766 <input type="submit" id="notagssublist" name="notagssublist" value="<?php _e('No select…','xili-dictionary'); ?>" /> |
510 <select name="tagsgroup_parent_select" id="tagsgroup_parent_select" style="width:100%;"> |
2767 </p> |
511 <option value="no_select" ><?php _e('No sub-selection','xili-dictionary'); ?></option> |
2768 </fieldset> |
|
2769 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"> |
|
2770 <legend><?php _e('Selection by language','xili-dictionary'); ?></legend> |
|
2771 <select name="tagsgroup_parent_select" id="tagsgroup_parent_select" style="width:100%;"> |
|
2772 <option value="no_select" ><?php _e('No sub-selection','xili-dictionary'); ?></option> |
512 <?php $checked = ($this->subselect == "msgid") ? 'selected="selected"' :'' ; |
2773 <?php $checked = ($this->subselect == "msgid") ? 'selected="selected"' :'' ; |
513 echo '<option value="msgid" '.$checked.' >'.__('Only MsgID (en_US)','xili-dictionary').'</option>'; |
2774 echo '<option value="msgid" '.$checked.' >'.__('Only MsgID (en_US)','xili-dictionary').'</option>'; |
514 echo $this->build_grouplist(); |
2775 $checked = ($this->subselect == "msgstr") ? 'selected="selected"' :'' ; |
|
2776 echo '<option value="msgstr" '.$checked.' >'.__('Only Msgstr','xili-dictionary').'</option>'; |
|
2777 $checked = ($this->subselect == "msgstr_0") ? 'selected="selected"' :'' ; |
|
2778 echo '<option value="msgstr_0" '.$checked.' >'.__('Only Msgstr plural','xili-dictionary').'</option>'; |
|
2779 echo $this->build_grouplist(); |
|
2780 echo $this->build_grouplist('nottransin_'); // 2.1.2 - not translated in |
515 ?> |
2781 ?> |
516 </select> |
2782 </select> |
517 <br /> <p class="submit"><input type="submit" id="subselection" name="subselection" value="<?php _e('Sub select…','xili-dictionary'); ?>" /></p> |
2783 <br /> |
518 </fieldset> |
2784 <p class="submit"> |
|
2785 <input type="submit" id="subselection" name="subselection" value="<?php _e('Sub select…','xili-dictionary'); ?>" /> |
|
2786 </p> |
|
2787 </fieldset> |
519 <?php |
2788 <?php |
520 } |
2789 } |
521 /** * @since 1.0.2 * only if xili-language plugin is absent */ |
2790 /** |
|
2791 * @since 1.0.2 |
|
2792 * only if xili-language plugin is absent |
|
2793 */ |
522 function on_normal_5_content($data=array()) { |
2794 function on_normal_5_content($data=array()) { |
523 extract($data); |
2795 extract($data); |
524 ?> |
2796 ?> |
525 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Language to delete','xili-dictionary'); ?></legend> |
2797 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"> |
526 <p><?php _e('Only the languages list is here modified (but not the dictionary\'s contents)','xili-dictionary'); ?></p> |
2798 <legend><?php _e('Language to delete','xili-dictionary'); ?></legend> |
527 <select name="langs_list" id="langs_list" style="width:100%;"> |
2799 <p><?php _e('Only the languages list is here modified (but not the dictionary\'s contents)','xili-dictionary'); ?> |
528 <option value="no_select" ><?php _e('Select...','xili-dictionary'); ?></option> |
2800 </p> |
|
2801 <select name="langs_list" id="langs_list" style="width:100%;"> |
|
2802 <option value="no_select" ><?php _e('Select...','xili-dictionary'); ?></option> |
529 <?php echo $this->build_grouplist(''); |
2803 <?php echo $this->build_grouplist(''); |
530 ?> |
2804 ?> |
531 </select> |
2805 </select> |
532 <br /> |
2806 <br /> |
533 <p class="submit"><input type="submit" id="lang_delete" name="lang_delete" value="<?php _e('Delete a language','xili-dictionary'); ?>" /></p></fieldset><br /> |
2807 <p class="submit"> |
534 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Language to add','xili-dictionary'); ?></legend> |
2808 <input type="submit" id="lang_delete" name="lang_delete" value="<?php _e('Delete a language','xili-dictionary'); ?>" /> |
535 <label for="lang_ISO"><?php _e('ISO (xx_YY)','xili-dictionary') ?></label>: |
2809 </p> |
536 <input name="lang_ISO" id="lang_ISO" type="text" value="" size="5"/><br /> |
2810 </fieldset><br /> |
537 <label for="lang_name"><?php _e('Name (eng.)','xili-dictionary') ?></label>: |
2811 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"> |
538 <input name="lang_name" id="lang_name" type="text" value="" size="20" /> |
2812 <legend><?php _e('Language to add','xili-dictionary'); ?></legend> |
539 <br /> |
2813 <label for="lang_ISO"><?php _e('ISO (xx_YY)','xili-dictionary') ?></label>: |
540 <p class="submit"><input type="submit" id="lang_add" name="lang_add" value="<?php _e('Add a language','xili-dictionary'); ?>" /></p> |
2814 <input name="lang_ISO" id="lang_ISO" type="text" value="" size="5"/><br /> |
541 </fieldset> |
2815 <label for="lang_name"><?php _e('Name (eng.)','xili-dictionary') ?></label>: |
|
2816 <input name="lang_name" id="lang_name" type="text" value="" size="20" /> |
|
2817 <br /> |
|
2818 <p class="submit"> |
|
2819 <input type="submit" id="lang_add" name="lang_add" value="<?php _e('Add a language','xili-dictionary'); ?>" /> |
|
2820 </p> |
|
2821 </fieldset> |
542 <?php } |
2822 <?php } |
|
2823 |
543 /** |
2824 /** |
544 * build the list of group of languages for dictionary |
2825 * build the list of group of languages for dictionary |
545 * |
2826 * |
546 * @updated 1.0.2 |
2827 * @updated 1.0.2 |
547 * |
2828 * |
548 */ |
2829 */ |
549 function build_grouplist ($left_line = 'Only:') { |
2830 function build_grouplist ($left_line = '') { |
550 if ($this->xililanguage == 'isactive') { |
2831 |
551 $listdictlanguages = get_terms(XDDICTLANGS, array('hide_empty' => false)); |
2832 $listdictlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
|
2833 $optionlist = ""; |
|
2834 $lefttext = ""; |
|
2835 if ( $left_line == 'nottransin_' ) $lefttext = __('not translated in','xili-dictionary').' '; |
552 foreach($listdictlanguages as $dictlanguage) { |
2836 foreach($listdictlanguages as $dictlanguage) { |
553 $checked = ($this->subselect == $dictlanguage->slug) ? 'selected="selected"' :'' ; |
2837 $checked = ($this->subselect == $left_line.$dictlanguage->slug) ? 'selected="selected"' :'' ; |
554 $optionlist .= '<option value="'.$dictlanguage->slug.'" '.$checked.' >'.__('Only:','xili-dictionary').' '.$dictlanguage->name.'</option>'; |
2838 $optionlist .= '<option value="'.$left_line.$dictlanguage->slug.'" '.$checked.' >'.$lefttext.$dictlanguage->name .' ('.$dictlanguage->description.')</option>'; |
555 } |
2839 } |
556 } else { |
2840 |
557 $langs_array = $this->xili_settings[XDDICTLANGS]; |
|
558 foreach ($langs_array as $lkey => $dictlanguage) { |
|
559 $checked = ($this->subselect == $lkey) ? 'selected="selected"' :'' ; |
|
560 $optionlist .= '<option value="'.$lkey.'" '.$checked.' >'.__($left_line,'xili-dictionary').' '.$dictlanguage[0].'</option>'; |
|
561 } |
|
562 } |
|
563 return $optionlist; |
2841 return $optionlist; |
564 } |
2842 } |
|
2843 |
565 /** |
2844 /** |
566 * @since 0.9.9 |
2845 * @since 1.3.3 |
567 * |
2846 * |
568 * |
2847 * |
569 */ |
2848 */ |
570 function test_and_create_slug($description, $slug, $lang='') { |
2849 function xd_wp_set_object_terms( $term_id, $lang_slug, $taxo_dictgroup , $bool = false) { |
571 $slug = sanitize_title(str_replace(' ','_',$slug)); |
2850 |
572 //echo $slug; |
2851 // check if lang_slug exists in this dict taxonomy |
573 $found = is_term($slug,DTAXONAME); |
2852 if ( ! $term_info = term_exists($lang_slug, $taxo_dictgroup) ) { |
574 if ($found){ |
2853 // Skip if a non-existent term ID is passed. |
575 /* compare description*/ |
2854 if ( is_int( $term_info ) ) |
576 $found_term = get_term($found['term_id'],DTAXONAME); |
2855 continue; |
577 if ($found_term->description == $description) { |
2856 $args = array( 'alias_of' => '', 'description' => 'Dictionary Group in '.$lang_slug ); |
578 return $slug; |
2857 $term_info = wp_insert_term($lang_slug, $taxo_dictgroup, $args); //print_r ($term_info); |
579 } else { |
2858 } |
580 if ( '' == $lang) { |
2859 wp_set_object_terms( $term_id, $lang_slug, $taxo_dictgroup, $bool ); |
581 //echo 'nul'; |
2860 |
582 $slug = $slug.'z'; |
|
583 return $this->test_and_create_slug($description, $slug, $lang); |
|
584 } else { |
|
585 //echo $slug; |
|
586 $theslug = str_replace('_'.$lang,'',$slug); |
|
587 $theslug = $theslug.'z'.'_'.$lang; /* risk the parent term cannot be created after */ |
|
588 return $this->test_and_create_slug($description, $theslug, $lang); |
|
589 } |
|
590 } |
|
591 } else { |
|
592 //echo 'pas nul'; |
|
593 return $slug; |
|
594 } |
|
595 } |
2861 } |
596 /** * @since 1.0.0 */ |
2862 |
597 function xili_dic_update_term($term, $taxonomy, $args) { |
2863 |
598 remove_filter('pre_term_description', 'wp_filter_kses'); /* 0.9.8.2 to allow more tag in msg str or id */ |
2864 /** |
599 $rterm_id = wp_update_term( $term, $taxonomy, $args); |
2865 * Dashboard - Manage - Dictionary |
600 add_filter('pre_term_description', 'wp_filter_kses'); |
2866 * |
601 return $rterm_id; |
2867 * @since 0.9 |
602 } |
2868 * @updated 2.0 |
603 function xili_dic_insert_term($termname, $taxonomy, $args) { |
2869 * |
604 remove_filter('pre_term_description', 'wp_filter_kses'); /* 0.9.8.2 to allow more tag in msg str or id */ |
2870 */ |
605 $rterm_id = wp_insert_term( $termname, $taxonomy, $args); |
|
606 add_filter('pre_term_description', 'wp_filter_kses'); |
|
607 return $rterm_id; |
|
608 } |
|
609 |
|
610 /* Dashboard - Manage - Dictionary */ |
|
611 function xili_dictionary_settings() { |
2871 function xili_dictionary_settings() { |
612 $formtitle = __('Add a term','xili-dictionary'); |
2872 $action = ""; |
|
2873 |
|
2874 $term_id = 0; |
|
2875 $formtitle = __('Dialog box','xili-dictionary'); |
613 $formhow = " "; |
2876 $formhow = " "; |
614 $submit_text = __('Add »','xili-dictionary'); |
2877 $submit_text = __('Do »','xili-dictionary'); |
615 $cancel_text = __('Cancel'); |
2878 $cancel_text = __('Cancel'); |
616 $this->langfolder = (defined('THEME_LANGS_FOLDER') && THEME_LANGS_FOLDER !='/') ? '/'.str_replace("/","",THEME_LANGS_FOLDER).'/' : "/"; |
2879 $langfolderset = $this->xili_settings['langs_folder']; |
617 $tagsnamelike = $_POST['tagsnamelike']; |
2880 $this->langfolder = ( $langfolderset !='' ) ? $langfolderset.'/' : '/'; |
|
2881 // doublon |
|
2882 $this->langfolder = str_replace ("//","/", $this->langfolder ); // upgrading... 2.0 and sub folder sub |
|
2883 $selecttaxonomy = ""; |
|
2884 |
|
2885 $tagsnamelike = ( isset ( $_POST['tagsnamelike'] ) ) ? $_POST['tagsnamelike'] : ''; |
618 if (isset($_GET['tagsnamelike'])) |
2886 if (isset($_GET['tagsnamelike'])) |
619 $tagsnamelike = $_GET['tagsnamelike']; /* if link from table */ |
2887 $tagsnamelike = $_GET['tagsnamelike']; /* if link from table */ |
620 $tagsnamesearch = $_POST['tagsnamesearch']; |
2888 $tagsnamesearch = ( isset ( $_POST['tagsnamesearch'] ) ) ? $_POST['tagsnamesearch'] : ''; |
621 if (isset($_GET['tagsnamesearch'])) |
2889 if (isset($_GET['tagsnamesearch'])) |
622 $tagsnamesearch = $_GET['tagsnamesearch']; |
2890 $tagsnamesearch = $_GET['tagsnamesearch']; |
623 |
2891 |
624 if (isset($_POST['reset'])) { |
2892 if (isset($_POST['reset'])) { |
625 $action=$_POST['reset']; |
2893 $action=$_POST['reset']; |
968 $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),2); |
3335 $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),2); |
969 $formhow = $this->tempoutput.'<br /><br /><strong>'.$formhow .'</strong>'; |
3336 $formhow = $this->tempoutput.'<br /><br /><strong>'.$formhow .'</strong>'; |
970 |
3337 |
971 break; |
3338 break; |
972 |
3339 |
973 case 'importingcurthemeterms'; |
3340 case 'importingcurthemeterms'; // temporary inactive 2.1 |
974 $actiontype = "add"; |
3341 $actiontype = "add"; |
975 $message .= ' '.__('All terms imported !','xili-dictionary'); |
3342 $message .= ' '.__('All terms imported !','xili-dictionary'); $msg = 5 ; |
976 $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),0); |
3343 $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),0); |
977 if (is_array($themeterms)) { |
3344 if (is_array($themeterms)) { |
978 $nbterms = $this->xili_importthemeterms_in_tables($themeterms); |
3345 //$nbterms = $this->xili_importthemeterms_in_tables($themeterms); |
979 $message .= __('terms = ','xili-dictionary').$nbterms; |
3346 $message .= __('terms = ','xili-dictionary').$nbterms; |
980 } else { |
3347 } else { |
981 $message .= ' '.$readfile.__('theme’s terms pbs!','xili-dictionary'); |
3348 $message .= ' '.$readfile.__('theme’s terms pbs!','xili-dictionary'); |
982 } |
3349 } |
983 break; |
3350 break; |
984 case 'reset'; |
3351 case 'reset'; |
985 $actiontype = "add"; |
3352 $actiontype = "add"; |
986 break; |
3353 break; |
987 default: |
3354 default: |
988 $actiontype = "add"; |
3355 $actiontype = "add"; |
989 $message .= ' '.__('Find above the list of terms.','xili-dictionary'); |
3356 $message .= ' '.__('Find below the list of terms.','xili-dictionary'); |
990 |
3357 |
991 } |
3358 } |
992 /* register the main boxes always available */ |
3359 /* register the main boxes always available */ |
993 |
3360 |
994 add_meta_box('xili-dictionary-sidebox-3', __('Import & export','xili-dictionary'), array(&$this,'on_normal_3_content'), $this->thehook , 'side', 'core'); /* files */ |
3361 add_meta_box('xili-dictionary-sidebox-3', __('Import & export','xili-dictionary'), array(&$this,'on_normal_3_content'), $this->thehook , 'side', 'core'); /* files */ |
995 add_meta_box('xili-dictionary-sidebox-4', __('Terms list management','xili-dictionary'), array(&$this,'on_normal_4_content'), $this->thehook , 'side', 'core'); /* files */ |
3362 add_meta_box('xili-dictionary-sidebox-4', __('Terms list management','xili-dictionary'), array(&$this,'on_normal_4_content'), $this->thehook , 'side', 'core'); /* files */ |
996 if ($this->xililanguage != 'isactive') |
3363 if ($this->xililanguage != 'isactive') |
997 add_meta_box('xili-dictionary-sidebox-5', __('Languages list management','xili-dictionary'), array(&$this,'on_normal_5_content'), $this->thehook , 'side', 'core'); /* Languages list when xili-language is absent */ |
3364 add_meta_box('xili-dictionary-sidebox-5', __('Languages list management','xili-dictionary'), array(&$this,'on_normal_5_content'), $this->thehook , 'side', 'core'); /* Languages list when xili-language is absent */ |
998 |
3365 |
999 add_meta_box('xili-dictionary-normal-2', __('Multilingual Terms','xili-dictionary'), array(&$this,'on_normal_1_content'), $this->thehook , 'normal', 'core'); /* list of terms*/ |
3366 add_meta_box('xili-dictionary-normal-1', __( $formtitle, 'xili-dictionary'), array(&$this,'on_normal_2_files_dialog'), $this->thehook , 'normal', 'core'); /* input form */ |
1000 add_meta_box('xili-dictionary-normal-1', __($formtitle,'xili-dictionary'), array(&$this,'on_normal_2_content'), $this->thehook , 'normal', 'core'); /* input form */ |
3367 add_meta_box('xili-dictionary-normal-cpt', __('Multilingual Terms','xili-dictionary'), array(&$this,'on_normal_cpt_content_list'), $this->thehook , 'normal', 'core'); /* list of terms*/ |
1001 |
3368 |
|
3369 |
|
3370 // since 1.2.2 - need to be upgraded... |
|
3371 if ($msg == 0 && $message != '' ) $msg = 6 ; //by temporary default |
|
3372 $themessages[1] = __('A new term was added.','xili-dictionary'); |
|
3373 $themessages[2] = __('A term was updated.','xili-dictionary'); |
|
3374 $themessages[3] = __('A term was deleted.','xili-dictionary'); |
|
3375 $themessages[4] = __('terms imported from WP: ','xili-dictionary') . $message; |
|
3376 $themessages[5] = __('All terms imported !','xili-dictionary'); |
|
3377 $themessages[6] = 'beta testing log: '.$message ; |
|
3378 $themessages[7] = __('All terms erased !','xili-dictionary'); |
|
3379 $themessages[8] = __('Error when adding !','xili-dictionary'); |
|
3380 $themessages[9] = __('Error when updating !','xili-dictionary'); |
1002 |
3381 |
1003 /* form datas in array for do_meta_boxes() */ |
3382 /* form datas in array for do_meta_boxes() */ |
1004 $data = array('message'=>$message,'messagepost'=>$messagepost,'action'=>$action, 'formtitle'=>$formtitle, 'dictioline'=>$dictioline,'submit_text'=>$submit_text,'cancel_text'=>$cancel_text, 'formhow'=>$formhow, 'orderby'=>$orderby,'term_id'=>$term_id, 'tagsnamesearch'=>$tagsnamesearch, 'tagsnamelike'=>$tagsnamelike); |
3383 $data = array('message'=>$message, 'action'=>$action, 'formtitle'=>$formtitle, 'submit_text'=>$submit_text,'cancel_text'=>$cancel_text, 'formhow'=>$formhow, 'orderby'=>$orderby,'term_id'=>$term_id, 'tagsnamesearch'=>$tagsnamesearch, 'tagsnamelike'=>$tagsnamelike, 'selecttaxonomy' =>$selecttaxonomy); |
|
3384 if ( isset ( $dictioline ) ) $data['dictioline'] = $dictioline ; |
|
3385 |
1005 ?> |
3386 ?> |
1006 <div id="xili-dictionary-settings" class="wrap" style="min-width:850px"> |
3387 <div id="xili-dictionary-settings" class="wrap columns-2" style="min-width:850px"> |
1007 <?php screen_icon('tools'); ?> |
3388 <?php screen_icon('tools'); ?> |
1008 <h2><?php _e('Dictionary','xili-dictionary') ?></h2> |
3389 <h2><?php _e('Dictionary','xili-dictionary') ?></h2> |
1009 <form name="add" id="add" method="post" action="tools.php?page=dictionary_page"> |
3390 <?php if (0!= $msg ) { // 1.2.2 ?> |
1010 <input type="hidden" name="action" value="<?php echo $actiontype ?>" /> |
3391 <div id="message" class="updated fade"><p><?php echo $themessages[$msg]; ?></p></div> |
|
3392 <?php } |
|
3393 |
|
3394 global $wp_version; |
|
3395 if ( version_compare($wp_version, '3.3.9', '<') ) { |
|
3396 $poststuff_class = 'class="metabox-holder has-right-sidebar"'; |
|
3397 $postbody_class = ""; |
|
3398 $postleft_id = ""; |
|
3399 $postright_id = "side-info-column"; |
|
3400 $postleft_class = ""; |
|
3401 $postright_class = "inner-sidebar"; |
|
3402 } else { // 3.4 |
|
3403 $poststuff_class = ""; |
|
3404 $postbody_class = 'class="metabox-holder columns-2"'; |
|
3405 $postleft_id = 'id="postbox-container-2"'; |
|
3406 $postright_id = "postbox-container-1"; |
|
3407 $postleft_class = 'class="postbox-container"'; |
|
3408 $postright_class = "postbox-container"; |
|
3409 } |
|
3410 ?> |
|
3411 <form name="add" id="add" method="post" action="<?php echo $this->xd_settings_page; ?>"> |
|
3412 <input type="hidden" name="action" value="<?php echo $actiontype ?>" /> |
1011 <?php wp_nonce_field('xili-dictionary-settings'); ?> |
3413 <?php wp_nonce_field('xili-dictionary-settings'); ?> |
|
3414 <?php wp_nonce_field('xilidicoptions'); ?> |
1012 <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?> |
3415 <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?> |
1013 <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); |
3416 <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); |
1014 /* 0.9.6 add has-right-sidebar for next wp 2.8*/ ?> |
3417 /* 0.9.6 add has-right-sidebar for next wp 2.8*/ ?> |
1015 <div id="poststuff" class="metabox-holder has-right-sidebar"> |
3418 <div id="poststuff" <?php echo $poststuff_class; ?> > |
1016 <div id="side-info-column" class="inner-sidebar"> |
3419 |
|
3420 <div id="post-body" <?php echo $postbody_class; ?> > |
|
3421 <div id="<?php echo $postright_id; ?>" class="<?php echo $postright_class; ?>"> |
1017 <?php do_meta_boxes($this->thehook, 'side', $data); ?> |
3422 <?php do_meta_boxes($this->thehook, 'side', $data); ?> |
|
3423 </div> |
|
3424 <div id="post-body-content" > |
|
3425 <div <?php echo $postleft_id; ?> <?php echo $postleft_class; ?> style="min-width:360px"> |
|
3426 <?php do_meta_boxes($this->thehook, 'normal', $data); ?> |
1018 </div> |
3427 </div> |
1019 <div id="post-body" class="has-sidebar has-right-sidebar"> |
3428 <h4><a href="http://dev.xiligroup.com/xili-dictionary" title="Plugin page and docs" target="_blank" style="text-decoration:none" ><img style="vertical-align:middle" src="<?php echo plugins_url( 'images/xilidico-logo-32.jpg', __FILE__ ) ; ?>" alt="xili-dictionary logo"/></a> - © <a href="http://dev.xiligroup.com" target="_blank" title="<?php _e('Author'); ?>" >xiligroup.com</a>™ - msc 2007-12 - v. <?php echo XILIDICTIONARY_VER; ?></h4> |
1020 <div id="post-body-content" class="has-sidebar-content" style="min-width:360px"> |
|
1021 |
|
1022 <?php do_meta_boxes($this->thehook, 'normal', $data); ?> |
|
1023 </div> |
|
1024 |
|
1025 <h4><a href="http://dev.xiligroup.com/xili-dictionary" title="Plugin page and docs" target="_blank" style="text-decoration:none" ><img style="vertical-align:middle" src="<?php echo WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)).'/xilidico-logo-32.gif'; ?>" alt="xili-dictionary logo"/> xili-dictionary</a> - © <a href="http://dev.xiligroup.com" target="_blank" title="<?php _e('Author'); ?>" >xiligroup.com</a>™ - msc 2007-9 - v. <?php echo XILIDICTIONARY_VER; ?></h4> |
|
1026 |
|
1027 </div> |
|
1028 </div> |
3429 </div> |
1029 </form> |
3430 </div> |
|
3431 <br class="clear" /> |
1030 </div> |
3432 </div> |
1031 <script type="text/javascript"> |
3433 </form> |
1032 //<![CDATA[ |
3434 </div> |
1033 jQuery(document).ready( function($) { |
3435 |
1034 // close postboxes that should be closed |
|
1035 $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); |
|
1036 // postboxes setup |
|
1037 postboxes.add_postbox_toggles('<?php echo $this->thehook; ?>'); |
|
1038 }); |
|
1039 //]]> |
|
1040 </script> |
|
1041 <?php //end settings div |
3436 <?php //end settings div |
1042 } |
3437 $this->insert_js_for_datatable( array('swidth2'=>'60%') ); |
1043 |
3438 } |
1044 /** * private function for admin page : select of parents */ |
3439 |
1045 function xili_select_row($term_id=0,$editterm,$listby='name') { |
3440 |
1046 // select all terms if current term is new |
3441 /** |
1047 if ($term_id == 0) { |
3442 * delete lines of dictionary |
1048 $listterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => '0')); |
3443 * |
1049 echo '<small>'.__('Choose the original term (msgid) to translate','xili-dictionary').'<br /></small>'; ?> |
3444 * |
1050 <select name="dictioline_parent" id="dictioline_parent" style="width:100%;"> |
3445 */ |
1051 <option value="no_parent" ><?php _e('no parent (= msgid)','xili-dictionary'); ?></option> |
3446 function erase_dictionary ( $selection = "" ) { |
1052 <?php |
3447 |
1053 foreach ($listterms as $curterm) { |
3448 if ( $selection == "" ) { |
1054 echo '<option value="'.$curterm->term_id.'" >'.substr($curterm->slug,0,50).' ('.$curterm->term_id.') </option>'; |
3449 // select all ids |
1055 } |
3450 $listdictiolines = get_posts( array( |
1056 ?> |
3451 'numberposts' => -1, 'offset' => 0, |
1057 </select> |
3452 'category' => 0, 'orderby' => 'ID', |
1058 <br /> |
3453 'order' => 'ASC', 'include' => array(), |
1059 <?php |
3454 'exclude' => array(), 'post_type' => XDMSG, |
1060 } else { |
3455 'suppress_filters' => true |
1061 |
3456 ) ); |
1062 if ($editterm->parent == 0) { |
3457 |
1063 $listterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => $term_id)); |
3458 |
1064 // display childs |
3459 } else { // to improve soon |
1065 if (!empty($listterms)) { |
3460 |
1066 echo '<small>'.__('translated as','xili-dictionary').": </small>"; |
3461 } |
1067 echo '<ul>'; |
3462 |
1068 foreach ($listterms as $curterm) { |
3463 if ( $listdictiolines ) { |
1069 $edit = "<a href='?action=edit&page=dictionary_page&term_id=".$curterm->term_id."' >".__( 'Edit' )."</a>"; |
3464 // loop |
1070 echo '<li value="'.$curterm->term_id.'" >'.$this->display_singular_or_plural ($curterm->description, true).' <small>'.$edit.'</small></li>'; |
3465 foreach ( $listdictiolines as $oneline ) { |
1071 } |
3466 wp_delete_post( $oneline->ID, false ) ; |
1072 echo '</ul>'; |
3467 } |
1073 } else { |
3468 } |
1074 echo __('not yet translated','xili-dictionary')."<br /><br />"; |
3469 } |
1075 } |
3470 |
1076 } else { |
3471 |
1077 echo '<small>'.__('translation of','xili-dictionary').": </small>"; |
3472 /** |
1078 $edit = "<a href='?action=edit&page=dictionary_page&term_id=".$editterm->parent."' >".__( 'Edit' )."</a>"; |
3473 * create an array of mo content of theme (maintained by super-admin) |
1079 $parent_term = get_term($editterm->parent,DTAXONAME,OBJECT,'edit'); |
3474 * |
1080 echo $this->display_singular_or_plural ($parent_term->description, true).' <small>'.$edit.'</small>'; ?> |
3475 * @since 1.1.0 |
1081 <input type="hidden" name="dictioline_parent" value="<?php echo $parent_term->term_id ?>" /> |
3476 */ |
1082 <?php } |
3477 function get_pomo_from_theme( $local = false ) { |
1083 } |
3478 $theme_mos = array(); |
1084 } |
3479 if ( defined ('TAXONAME') ) { |
1085 /** * private function for admin page : one line of taxonomy */ |
3480 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
1086 |
3481 foreach ($listlanguages as $reflanguage) { |
1087 function xili_dict_row($listby='name',$tagsnamelike='',$tagsnamesearch='') { |
3482 $res = $this->pomo_import_MO ( $reflanguage->name, '', $local); |
1088 global $default_lang; |
3483 if (false !== $res) $theme_mos[$reflanguage->slug] = $res->entries; |
1089 /*list of dictiolines*/ |
3484 } |
1090 |
3485 } |
1091 if ($this->subselect == 'msgid' || $this->subselect == '') { |
3486 return $theme_mos; |
1092 $parentselect = ''; |
3487 } |
1093 if ($this->subselect == 'msgid') $parentselect = '0'; |
3488 |
1094 $listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false,'orderby' => $listby,'get'=>'all','name__like'=>$tagsnamelike,'search'=>$tagsnamesearch, 'parent'=>$parentselect)); |
3489 /** |
|
3490 * create an array of mo content of theme (maintained by admin of current site) |
|
3491 * currently contains the msgid which are not in theme mo |
|
3492 * |
|
3493 * @since 1.2.0 |
|
3494 */ |
|
3495 function get_pomo_from_site( $local = false ) { |
|
3496 $theme_mos = array(); |
|
3497 if ( defined ('TAXONAME') ) { |
|
3498 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
|
3499 foreach ($listlanguages as $reflanguage) { |
|
3500 $res = $this->import_mo_file_wpmu ( $reflanguage->name, false, $local ); // of current site |
|
3501 if (false !== $res) $theme_mos[$reflanguage->slug] = $res->entries; |
|
3502 } |
|
3503 } |
|
3504 return $theme_mos; |
|
3505 } |
|
3506 |
|
3507 /** |
|
3508 * private function for admin page : one line of taxonomy |
|
3509 * |
|
3510 * |
|
3511 */ |
|
3512 function xili_dict_cpt_row( $listby='name', $tagsnamelike='', $tagsnamesearch='' ) { /* the lines */ |
|
3513 |
|
3514 // select msg |
|
3515 $special_query = false; |
|
3516 switch ( $this->subselect ) { |
|
3517 |
|
3518 case 'msgid' : |
|
3519 $meta_key_val = $this->msgtype_meta; |
|
3520 $meta_value_val = 'msgid'; |
|
3521 break; |
|
3522 case 'msgstr' : |
|
3523 $meta_key_val = $this->msgtype_meta; |
|
3524 $meta_value_val = 'msgstr'; |
|
3525 break; |
|
3526 case 'msgstr_0' : |
|
3527 $meta_key_val = $this->msgtype_meta; |
|
3528 $meta_value_val = 'msgstr_0'; |
|
3529 break; |
|
3530 case '' : |
|
3531 $meta_key_val = ''; |
|
3532 $meta_value_val = ''; |
|
3533 break; |
|
3534 default; |
|
3535 if ( false !== strpos ( $this->subselect, 'only=' ) ) { |
|
3536 $exps = explode ('=', $this->subselect); |
|
3537 $special_query = 'strlang' ; |
|
3538 $curlang = $exps[1]; |
|
3539 |
|
3540 } else { |
|
3541 if ( false !== strpos ( $this->subselect, 'nottransin_' ) ) { |
|
3542 $exps = explode ('_', $this->subselect); |
|
3543 $special_query = 'idlang' ; |
|
3544 $curlang = $exps[1]; |
|
3545 $this->searchtranslated = 'not'; // 2.1.2 |
|
3546 } else { |
|
3547 // msgid + language |
|
3548 $curlang = $this->subselect; |
|
3549 $special_query = 'idlang' ; |
|
3550 } |
|
3551 } |
|
3552 } |
|
3553 if ( $special_query == 'idlang' ) { |
|
3554 if ( $this->searchtranslated != 'not' ) { |
|
3555 $listdictiolines = $this->get_cpt_msgids( $curlang ) ; |
|
3556 } else { |
|
3557 $listdictiolines = $this->get_cpt_msgids( $curlang, 'mo', array(), true ) ; // search not translated in target language |
|
3558 } |
|
3559 } elseif ( $special_query == 'strlang' ) { |
|
3560 $listdictiolines = get_posts( array( |
|
3561 'numberposts' => -1, 'offset' => 0, |
|
3562 'category' => 0, 'orderby' => 'ID', |
|
3563 'order' => 'ASC', 'include' => array(), |
|
3564 'exclude' => array(), |
|
3565 'post_type' => XDMSG, |
|
3566 'suppress_filters' => true, 's' => $tagsnamesearch, |
|
3567 'tax_query' => array( |
|
3568 array( |
|
3569 'taxonomy' => TAXONAME, |
|
3570 'field' => 'name', |
|
3571 'terms' => $curlang |
|
3572 ) |
|
3573 ), |
|
3574 'meta_query' => array( |
|
3575 array( |
|
3576 'key' => $this->msgtype_meta, |
|
3577 'value' => array( 'msgstr', 'msgstr_0', 'msgstr_1' ), |
|
3578 'compare' => 'IN' |
|
3579 ) |
|
3580 ) |
|
3581 ) ); |
|
3582 |
|
3583 } else { |
|
3584 $listdictiolines = get_posts( array( |
|
3585 'numberposts' => -1, 'offset' => 0, |
|
3586 'category' => 0, 'orderby' => 'ID', |
|
3587 'order' => 'ASC', 'include' => array(), |
|
3588 'exclude' => array(), 'meta_key' => $meta_key_val, |
|
3589 'meta_value' =>$meta_value_val, 'post_type' => XDMSG, |
|
3590 'suppress_filters' => true, 's' => $tagsnamesearch |
|
3591 ) ); |
|
3592 } |
|
3593 $class = ""; |
|
3594 $this->mo_files_array (); |
|
3595 //print_r( $this->file_site_mos ); |
|
3596 foreach ( $listdictiolines as $dictioline ) { |
|
3597 |
|
3598 $class = (( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; |
|
3599 |
|
3600 $type = get_post_meta ( $dictioline->ID, $this->msgtype_meta, true); |
|
3601 $context = get_post_meta ( $dictioline->ID, $this->ctxt_meta, true); |
|
3602 |
|
3603 $res = $this->is_saved_cpt_in_theme( $dictioline->post_content, $type, $context ); |
|
3604 $save_state = $res[0] . ' (local: '.$res[2].')'; // improve for str and multisite |
|
3605 |
|
3606 if ( is_multisite() ) $save_state .= '<br />'.__('this site', 'xili-dictionary').': '.$res[1] . ' (local: '.$res[3].')'; |
|
3607 |
|
3608 $edit = "<a href='post.php?post=$dictioline->ID&action=edit' >".__( 'Edit' )."</a></td>"; |
|
3609 |
|
3610 $line = "<tr id='cat-$dictioline->ID'$class> |
|
3611 <td scope='row' style='text-align: center'>$dictioline->ID</td> |
|
3612 |
|
3613 <td>". htmlspecialchars( $dictioline->post_content ) ."</td> |
|
3614 |
|
3615 <td>"; |
|
3616 echo $line; |
|
3617 $this->msg_link_display ( $dictioline->ID, false, $dictioline ) ; |
|
3618 $line = "</td> |
|
3619 <td class='center'>$save_state</td> |
|
3620 |
|
3621 <td class='center'>$edit</td>\n\t</tr>\n"; /*to complete*/ |
|
3622 echo $line; |
|
3623 |
|
3624 } |
|
3625 } |
|
3626 |
|
3627 /** |
|
3628 * return count of msgid (local or theme domain) |
|
3629 * @since |
|
3630 */ |
|
3631 function count_msgids ( $curlang, $local = true, $theme_domain = '' ) { |
|
3632 |
|
3633 if ( $local ) { |
|
3634 // msg id with lang |
|
3635 $the_query = array( |
|
3636 'post_type' => XDMSG, |
|
3637 'meta_query' => array( |
|
3638 'relation' => 'AND', |
|
3639 array( |
|
3640 'key' => $this->msgtype_meta, |
|
3641 'value' => 'msgid', |
|
3642 'compare' => '=' |
|
3643 ), |
|
3644 array( |
|
3645 'key' => $this->msglang_meta, |
|
3646 'value' => $curlang, |
|
3647 'compare' => 'LIKE' // 2.1.2 |
|
3648 ), |
|
3649 array( |
|
3650 'key' => $this->msg_extracted_comments, |
|
3651 'value' => $this->local_tag, |
|
3652 'compare' => 'LIKE' |
|
3653 ) |
|
3654 ) |
|
3655 ); |
|
3656 |
|
3657 } else if ( $theme_domain == '') { |
|
3658 $the_query = array( |
|
3659 'post_type' => XDMSG, |
|
3660 'tax_query' => array( |
|
3661 array( |
|
3662 'taxonomy' => TAXONAME, |
|
3663 'field' => 'name', |
|
3664 'terms' => $curlang |
|
3665 ) |
|
3666 ) |
|
3667 ); |
|
3668 |
1095 } else { |
3669 } else { |
1096 /* */ |
3670 |
1097 $group = is_term($this->subselect,XDDICTLANGS); |
3671 $the_query = array( |
1098 $listdictiolines = get_terms_of_groups(array($group['term_id']),XDDICTLANGS,DTAXONAME, array('hide_empty' => false,'orderby' => $listby,'get'=>'all','name__like'=>$tagsnamelike,'search'=>$tagsnamesearch)); |
3672 'post_type' => XDMSG, |
1099 } |
3673 'meta_query' => array( |
1100 if (empty($listdictiolines) && $tagsnamelike=='' && $tagsnamesearch=='') : /*create a default line with the default language (as in config)*/ |
3674 'relation' => 'AND', |
1101 $term = 'term'; |
3675 array( |
1102 $args = array( 'alias_of' => '', 'description' => "term", 'parent' => 0, 'slug' =>''); |
3676 'key' => $this->msgtype_meta, |
1103 wp_insert_term( $term, DTAXONAME, $args); |
3677 'value' => 'msgid', |
1104 $listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false)); |
3678 'compare' => '=' |
1105 endif; |
3679 ), |
1106 if (empty($listdictiolines)) { |
3680 array( |
1107 echo '<p>'.__('try another sub-selection !','xili-dictionary').'</p>'; |
3681 'key' => $this->msglang_meta, |
1108 } else { |
3682 'value' => $curlang, |
1109 $subselect = (($tagsnamelike=='') ? '' : '&tagsnamelike='.$tagsnamelike); |
3683 'compare' => 'LIKE' // 2.1.2 |
1110 $subselect .= (($tagsnamesearch=='') ? '' : '&tagsnamesearch='.$tagsnamesearch); |
3684 ) |
1111 |
3685 ), |
1112 foreach ($listdictiolines as $dictioline) { |
3686 'tax_query' => array( |
1113 |
3687 |
1114 $class = (( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; |
3688 array( |
1115 |
3689 'taxonomy' => 'origin', |
1116 $dictioline->count = number_format_i18n( $dictioline->count ); |
3690 'field' => 'slug', |
1117 $posts_count = ( $dictioline->count > 0 ) ? "<a href='edit.php?lang=$dictioline->term_id'>$dictioline->count</a>" : $dictioline->count; |
3691 'terms' => array($theme_domain), |
1118 |
3692 'operator' => 'IN' |
1119 $edit = "<a href='?action=edit&page=dictionary_page".$subselect."&term_id=".$dictioline->term_id."' >".__( 'Edit' )."</a></td>"; |
3693 ) |
1120 /* delete link */ |
3694 ) |
1121 $edit .= "<td><a href='?action=delete&page=dictionary_page".$subselect."&term_id=".$dictioline->term_id."' class='delete'>".__( 'Delete' )."</a>"; |
3695 ); |
1122 /* modify to allow all html tags in msg str or id - 0.9.8.2*/ |
3696 |
1123 $line="<tr id='cat-$dictioline->term_id'$class> |
3697 } |
1124 <th scope='row' style='text-align: center'>$dictioline->term_id</th> |
3698 |
1125 |
3699 |
1126 <td>".$this->display_singular_or_plural($dictioline->description)."</td> |
3700 $query_4_test = new WP_Query( $the_query ); |
1127 |
3701 return $query_4_test->found_posts; |
1128 <td>".$dictioline->slug."</td> |
3702 |
1129 <td align='center'>$dictioline->term_group</td> |
3703 } |
1130 |
3704 /** |
1131 <td>$edit</td>\n\t</tr>\n"; /*to complete*/ |
3705 * test if line is in entries |
1132 echo $line; |
3706 * @since |
1133 } |
3707 */ |
1134 } |
3708 function is_intheme_mos ( $msg, $type, $entries, $context ) { |
1135 } |
3709 foreach ($entries as $entry) { |
1136 function display_singular_or_plural ($msg, $onlyfirst = false) { |
3710 $diff = 1; |
1137 if (false === strpos($msg,XPLURAL)) { |
3711 switch ( $type ) { |
1138 return wp_filter_kses($msg); |
3712 case 'msgid' : |
1139 } else { |
3713 $diff = strcmp( $msg , $entry->singular ); |
1140 $list = explode (XPLURAL,$msg); |
3714 if ( $context != "" ) { |
1141 if ($onlyfirst === false) { |
3715 if ( $entry->context != null ) { |
1142 $list = array_map('wp_filter_kses',$list); |
3716 $diff += strcmp( $context , $entry->context ); |
1143 return implode('<br />',$list); |
3717 } |
1144 } else { |
3718 } |
1145 return wp_filter_kses($list[0]); |
3719 break; |
1146 } |
3720 case 'msgid_plural' : |
1147 } |
3721 $diff = strcmp( $msg , $entry->plural ); |
1148 } |
3722 break; |
|
3723 case 'msgstr' : |
|
3724 if ( isset ( $entry->translations[0] ) ) |
|
3725 $diff = strcmp( $msg , $entry->translations[0] ); |
|
3726 break; |
|
3727 default: |
|
3728 if ( false !== strpos ( $type, 'msgstr_' ) ) { |
|
3729 $indice = (int) substr ( $type, -1) ; |
|
3730 if ( isset ( $entry->translations[$indice] ) ) |
|
3731 $diff = strcmp( $msg , $entry->translations[$indice] ); |
|
3732 } |
|
3733 } |
|
3734 |
|
3735 //if ( $diff != 0) { echo $msg.' i= '.strlen($msg); echo $entry->singular.') e= '.strlen($entry->singular); } |
|
3736 if ( $diff == 0) return true; |
|
3737 } |
|
3738 return false; |
|
3739 } |
|
3740 |
|
3741 /** |
|
3742 * Detect if cpt are saved in theme's languages folder |
|
3743 * @since 2.0 |
|
3744 * |
|
3745 */ |
|
3746 function is_saved_cpt_in_theme( $msg, $type, $context = "" ) { |
|
3747 $thelist = array(); |
|
3748 $thelistsite = array(); |
|
3749 $thelist_local = array(); |
|
3750 $thelistsite_local = array(); |
|
3751 $outputsite = ""; |
|
3752 $localfile_site = ""; |
|
3753 $output = ""; |
|
3754 $localfile=""; |
|
3755 |
|
3756 if ( defined ('TAXONAME') ) { |
|
3757 $listlanguages = $this->get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC' ); //get_terms(TAXONAME, array('hide_empty' => false)); |
|
3758 |
|
3759 foreach ($listlanguages as $reflanguage) { |
|
3760 if ( isset( $this->theme_mos[$reflanguage->slug]) ) { |
|
3761 if ( $this->is_intheme_mos ( $msg, $type, $this->theme_mos[$reflanguage->slug], $context ) ) |
|
3762 $thelist[] = $reflanguage->name.".mo"; |
|
3763 } |
|
3764 // local data |
|
3765 if ( isset( $this->local_mos[$reflanguage->slug]) ) { |
|
3766 if ( $this->is_intheme_mos ( $msg, $type, $this->local_mos[$reflanguage->slug], $context ) ) |
|
3767 $thelist_local[] = $reflanguage->name.".mo"; |
|
3768 } |
|
3769 |
|
3770 if ( is_multisite() ) { |
|
3771 if ( isset($this->file_site_mos[$reflanguage->slug]) ) { |
|
3772 if ( $this->is_intheme_mos ( $msg, $type, $this->file_site_mos[$reflanguage->slug], $context ) ) |
|
3773 $thelistsite[] = $reflanguage->name.".mo"; |
|
3774 } |
|
3775 // local data |
|
3776 if ( isset($this->file_site_local_mos[$reflanguage->slug]) ) { |
|
3777 if ( $this->is_intheme_mos ( $msg, $type, $this->file_site_local_mos[$reflanguage->slug], $context ) ) |
|
3778 $thelistsite_local[] = $reflanguage->name.".mo"; |
|
3779 } |
|
3780 } |
|
3781 |
|
3782 } |
|
3783 |
|
3784 $output = ($thelist == array()) ? '<br /><small><span style="color:black" title="'.__("No translations saved in theme's .mo files","xili-dictionary").'">**</span></small>' : '<br /><small><span style="color:green" title="'.__("Original with translations saved in theme's files: ","xili-dictionary").'" >'. implode(', ',$thelist).'</small></small>'; |
|
3785 |
|
3786 $localfile = ($thelist_local == array()) ? '<small><span style="color:black" title="'.__("No translations saved in local-xx_XX .mo files","xili-dictionary").'">?</span></small>' : '<small><span style="color:green" title="'.__("Original with translations saved in local-xx_XX files: ","xili-dictionary").'" >'. implode(', ', $thelist_local ).'</small></small>'; |
|
3787 |
|
3788 if ( is_multisite() ) { |
|
3789 |
|
3790 $outputsite = ($thelistsite == array()) ? '<br /><small><span style="color:black" title="'.__("No translations saved in site's .mo files","xili-dictionary").'">**</span></small>' : '<br /><small><span style="color:green" title="'.__("Original with translations saved in site's files: ","xili-dictionary").'" >'. implode(', ',$thelistsite).'</small></small>'; |
|
3791 |
|
3792 $localfile_site = ($thelistsite_local == array()) ? '<small><span style="color:black" title="' . __("No translations saved in site's local .mo files","xili-dictionary").'">?</span></small>' : '<small><span style="color:green" title="'.__("Original with translations saved in site's local files: ","xili-dictionary").'" >'. implode(', ',$thelistsite_local).'</small></small>'; |
|
3793 |
|
3794 } |
|
3795 |
|
3796 return array ( $output, $outputsite, $localfile, $localfile_site ) ; |
|
3797 } |
|
3798 } |
|
3799 |
|
3800 |
1149 /** |
3801 /** |
1150 * Import PO file in class PO |
3802 * Import PO file in class PO |
1151 * |
3803 * |
1152 * |
3804 * |
1153 * @since 1.0 - only WP >= 2.8.4 |
3805 * @since 1.0 - only WP >= 2.8.4 |
1154 */ |
3806 * @updated 1.05 - import .pot if domain name - fixed 1.3.1 |
1155 function pomo_import_PO ($lang = "") { |
3807 * @updated 2.1 - local-xx_XX |
|
3808 */ |
|
3809 function pomo_import_PO ( $lang = "", $local = false ) { |
1156 $po = new PO(); |
3810 $po = new PO(); |
1157 $pofile = get_template_directory().$this->langfolder.$lang.'.po'; |
3811 $t = ""; |
1158 if ( !$po->import_from_file( $pofile ) ) { |
3812 if ( function_exists('the_theme_domain') ) { |
|
3813 $t = ($lang == the_theme_domain()) ? 't': ''; /* from UI to select .pot */ |
|
3814 } else { |
|
3815 if ( function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 and WP 3.0 |
|
3816 $theme_name = get_option("stylesheet"); |
|
3817 } else { |
|
3818 $theme_name = get_option("template"); |
|
3819 } |
|
3820 $t = ( $lang == $theme_name ) ? 't': ''; /* from UI to select .pot */ |
|
3821 } |
|
3822 |
|
3823 if ( $local == false ) { |
|
3824 $pofile = $this->get_template_directory.$this->langfolder.$lang.'.po'.$t; |
|
3825 } else { |
|
3826 $pofile = $this->get_template_directory.$this->langfolder.'local-'.$lang.'.po'; // fixed 2.1.1 |
|
3827 } |
|
3828 |
|
3829 if ( file_exists( $pofile ) ) { |
|
3830 if ( !$po->import_from_file( $pofile ) ) { |
|
3831 return false; |
|
3832 } else { |
|
3833 return $po; |
|
3834 } |
|
3835 } else { |
1159 return false; |
3836 return false; |
1160 } else { |
3837 } |
1161 return $po; |
3838 } |
1162 } |
3839 |
1163 } |
|
1164 /** |
|
1165 * the PO object to twinlines (msgid - msgstr) for list |
|
1166 * |
|
1167 * |
|
1168 * @since 1.0 - only WP >= 2.8.4 |
|
1169 */ |
|
1170 function from_PO_to_twin ($po) { |
|
1171 $twinlines = array(); |
|
1172 foreach ($po->entries as $pomsgid => $pomsgstr) { |
|
1173 if ($pomsgstr->is_plural == null) { |
|
1174 $twinlines[$pomsgid] = $pomsgstr->translations[0]; |
|
1175 } else { |
|
1176 $keytwin = $pomsgstr->singular.XPLURAL.$pomsgstr->plural; |
|
1177 $twinlines[$keytwin] = implode (XPLURAL, $pomsgstr->translations); |
|
1178 } |
|
1179 |
|
1180 } |
|
1181 //print_r($twinlines); |
|
1182 return $twinlines; |
|
1183 } |
|
1184 /** |
3840 /** |
1185 * Import MO file in class PO |
3841 * Import MO file in class PO |
1186 * |
3842 * |
1187 * |
3843 * |
1188 * @since 1.0.2 - only WP >= 2.8.4 |
3844 * @since 1.0.2 - only WP >= 2.8.4 |
1189 */ |
3845 * @updated 1.0.5 - for wp-net |
1190 function pomo_import_MO ($lang = "") { |
3846 * @param lang |
|
3847 * @param $mofile since 1.0.5 |
|
3848 * @updated 2.1 - local-xx_XX |
|
3849 */ |
|
3850 function pomo_import_MO ($lang = "", $mofile = "", $local = false ) { |
1191 $mo = new MO(); |
3851 $mo = new MO(); |
1192 $mofile = get_template_directory().$this->langfolder.$lang.'.mo'; |
3852 |
1193 if ( !$mo->import_from_file( $mofile ) ) { |
3853 if ( $mofile == "" && $local == true ) { |
|
3854 $mofile = $this->get_template_directory.$this->langfolder.'local-'.$lang.'.mo'; |
|
3855 } else if ( '' == $mofile ) { |
|
3856 $mofile = $this->get_template_directory.$this->langfolder.$lang.'.mo'; |
|
3857 } |
|
3858 |
|
3859 if ( file_exists( $mofile ) ) { |
|
3860 if ( !$mo->import_from_file( $mofile ) ) { |
|
3861 return false; |
|
3862 } else { |
|
3863 return $mo; |
|
3864 } |
|
3865 } else { |
1194 return false; |
3866 return false; |
1195 } else { |
|
1196 return $mo; |
|
1197 } |
3867 } |
1198 } |
3868 } |
1199 /** |
3869 /** |
1200 * the MO object to twinlines (msgid - msgstr) for list |
3870 * import mo for temporary diff mo files or check if saved |
1201 * |
3871 * |
1202 * |
3872 * @since 1.0.6 |
1203 * @since 1.0.2 - only WP >= 2.8.4 |
3873 * |
|
3874 */ |
|
3875 function import_mo_file_wpmu ($lang = "", $istheme = true, $local = false ){ |
|
3876 if ($istheme == true) { |
|
3877 return $this->pomo_import_MO ( $lang, "", $local ); |
|
3878 } else { |
|
3879 global $wpdb; |
|
3880 $thesite_ID = $wpdb->blogid; |
|
3881 if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { |
|
3882 //if ($thesite_ID > 1) { |
|
3883 if ( $local == true ) { |
|
3884 $mofile = $uploads['basedir']."/languages/local-".$lang.'.mo'; |
|
3885 } else { |
|
3886 $mofile = $uploads['basedir']."/languages/".$lang.'.mo'; //normally inside theme's folder if root wp-net |
|
3887 } |
|
3888 |
|
3889 return $this->pomo_import_MO ( $lang, $mofile, $local ); |
|
3890 //} else { |
|
3891 //return false; // normally inside theme's folder if root wp-net |
|
3892 //} |
|
3893 } else { |
|
3894 return false; |
|
3895 } |
|
3896 } |
|
3897 } |
|
3898 |
|
3899 |
|
3900 /** |
|
3901 * convert twinlines (msgid - msgstr) to MOs in wp-net |
|
3902 * @since 1.0.4 |
|
3903 * @updated 2.0 |
|
3904 * @params as from_twin_to_POMO and $superadmin |
1204 */ |
3905 */ |
1205 function from_MO_to_twin ($mo) { |
3906 function from_cpt_to_POMO_wpmu ($curlang, $obj='mo', $superadmin = false, $extract = array() ) { |
1206 $twinlines = array(); |
3907 global $user_identity,$user_url,$user_email; |
1207 foreach ($mo->entries as $pomsgid => $pomsgstr) { |
3908 // the table array |
1208 if ($pomsgstr->is_plural == null) { |
3909 $table_mo = $this->from_cpt_to_POMO( $curlang, $obj, $extract ); |
1209 $twinlines[$pomsgid] = $pomsgstr->translations[0]; |
3910 $site_mo = new MO () ; |
|
3911 $translation =' |
|
3912 Project-Id-Version: theme: '.get_option("template").'\n |
|
3913 Report-Msgid-Bugs-To: contact@xiligroup.com\n |
|
3914 POT-Creation-Date: '.date("c").'\n |
|
3915 PO-Revision-Date: '.date("c").'\n |
|
3916 Last-Translator: '.$user_identity.' <'.$user_email.'>\n |
|
3917 Language-Team: xili-dictionary WP plugin and '.$user_url.' <'.$user_email.'>\n |
|
3918 MIME-Version: 1.0\n |
|
3919 Content-Type: text/plain; charset=utf-8\n |
|
3920 Content-Transfer-Encoding: 8bit\n |
|
3921 Plural-Forms: '.$this->plural_forms_rule($curlang).'\n |
|
3922 X-Poedit-Language: '.$curlang.'\n |
|
3923 X-Poedit-Country: '.$curlang.'\n |
|
3924 X-Poedit-SourceCharset: utf-8\n'; |
|
3925 |
|
3926 $site_mo->set_headers($site_mo->make_headers($translation)); |
|
3927 // array diff |
|
3928 if (false === $superadmin) { |
|
3929 // special for superadmin who don't need diff. |
|
3930 // the pomo array available in theme's folder |
|
3931 $theme_mo = $this->import_mo_file_wpmu ( $curlang, true ); |
|
3932 if ( false !== $theme_mo ) { |
|
3933 // without keys available in theme' mo |
|
3934 $site_mo->entries = array_diff_key ( $table_mo->entries, $theme_mo->entries ); // those differents ex. categories |
|
3935 // those with same keys but translations[0] diff |
|
3936 $diff_mo_trans = array_uintersect_assoc ( $table_mo->entries, $theme_mo->entries, array(&$this,'test_translations') ) ; |
|
3937 |
|
3938 $site_mo->entries += $diff_mo_trans ; |
|
3939 //print_r ( array_keys ( $diff_mo_trans )); |
|
3940 |
|
3941 } |
|
3942 return $site_mo; |
|
3943 } elseif ( $extract != '' ) { |
|
3944 |
|
3945 return $table_mo; |
|
3946 } |
|
3947 } |
|
3948 |
|
3949 function test_translations ( $table, $theme ) { |
|
3950 if ( $table->translations[0] != $theme->translations[0] ) { |
|
3951 if ( $table->singular == $theme->singular ) { |
|
3952 //echo '--tQuote--not'.$table->translations[0]; |
|
3953 return 0; |
|
3954 |
1210 } else { |
3955 } else { |
1211 $keytwin = $pomsgstr->singular.XPLURAL.$pomsgstr->plural; |
3956 return 1; |
1212 $twinlines[$keytwin] = implode (XPLURAL, $pomsgstr->translations); |
3957 } |
1213 } |
3958 } |
1214 |
3959 if ( $table->singular > $theme->singular ) return 1; |
1215 } |
3960 return -1; |
1216 //print_r($twinlines); |
|
1217 return $twinlines; |
|
1218 } |
3961 } |
1219 |
3962 |
1220 /** |
3963 /** |
1221 * convert twinlines (msgid - msgstr) to MO |
3964 * return array of msgid objects |
1222 * |
3965 * @since 2.0 |
1223 * |
3966 * |
1224 * @since 1.0 - only WP >= 2.8.4 |
3967 * @updated 2.1.2 |
|
3968 */ |
|
3969 function get_cpt_msgids( $curlang, $pomo = "mo", $extract_array = array(), $not = false ) { |
|
3970 global $wpdb; |
|
3971 $like = ($not === true ) ? 'NOT LIKE' : 'LIKE' ; |
|
3972 if ( $pomo == "mo" ) { |
|
3973 |
|
3974 if ( $extract_array == array() ) { |
|
3975 //$posts_query = $wpdb->prepare("SELECT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) INNER JOIN $wpdb->postmeta as mt1 ON ($wpdb->posts.ID = mt1.post_id) INNER JOIN $wpdb->postmeta as mt2 ON ($wpdb->posts.ID = mt2.post_id) INNER JOIN $wpdb->postmeta as mt3 ON ($wpdb->posts.ID = mt3.post_id) WHERE post_status = %s AND post_type = %s AND $wpdb->postmeta.meta_key='{$this->msgtype_meta}' AND mt1.meta_key='{$this->msgtype_meta}' AND mt1.meta_value = %s AND mt2.meta_key='{$this->msglang_meta}' AND mt3.meta_key='{$this->msglang_meta}' AND mt3.meta_value LIKE %s ", 'publish', XDMSG ,'msgid', '%'.$curlang.'%' ); |
|
3976 //return $wpdb->get_results($posts_query); |
|
3977 return get_posts( array( |
|
3978 'numberposts' => -1, 'offset' => 0, |
|
3979 'category' => 0, 'orderby' => 'ID', |
|
3980 'order' => 'ASC', 'include' => array(), |
|
3981 'exclude' => array(), |
|
3982 'post_type' => XDMSG, |
|
3983 'suppress_filters' => true, |
|
3984 'meta_query' => array( |
|
3985 'relation' => 'AND', |
|
3986 array( |
|
3987 'key' => $this->msgtype_meta, |
|
3988 'value' => 'msgid', |
|
3989 'compare' => '=' |
|
3990 ), |
|
3991 array( |
|
3992 'key' => $this->msglang_meta, |
|
3993 'value' => $curlang, |
|
3994 'compare' => $like // 2.1.2 |
|
3995 ) |
|
3996 ) |
|
3997 ) ); |
|
3998 |
|
3999 |
|
4000 } else if ( isset ( $extract_array [ $this->msg_extracted_comments ] ) ) { |
|
4001 $extract = $extract_array [ $this->msg_extracted_comments ]; |
|
4002 |
|
4003 //$posts_query = $wpdb->prepare("SELECT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) INNER JOIN $wpdb->postmeta as mt1 ON ($wpdb->posts.ID = mt1.post_id) INNER JOIN $wpdb->postmeta as mt2 ON ($wpdb->posts.ID = mt2.post_id) INNER JOIN $wpdb->postmeta as mt3 ON ($wpdb->posts.ID = mt3.post_id) INNER JOIN $wpdb->postmeta as mt4 ON ($wpdb->posts.ID = mt4.post_id) INNER JOIN $wpdb->postmeta as mt5 ON ($wpdb->posts.ID = mt5.post_id) WHERE post_status = %s AND post_type = %s AND $wpdb->postmeta.meta_key='{$this->msgtype_meta}' AND mt1.meta_key='{$this->msgtype_meta}' AND mt1.meta_value = %s AND mt2.meta_key='{$this->msglang_meta}' AND mt3.meta_key='{$this->msglang_meta}' AND mt3.meta_value LIKE %s AND mt4.meta_key='{$this->msg_extracted_comments}' AND mt5.meta_key='{$this->msg_extracted_comments}' AND mt5.meta_value LIKE %s ", 'publish', XDMSG ,'msgid', '%'.$curlang.'%', '%'.$extract.'%' ); |
|
4004 //return $wpdb->get_results($posts_query); |
|
4005 |
|
4006 return get_posts( array( |
|
4007 'numberposts' => -1, 'offset' => 0, |
|
4008 'category' => 0, 'orderby' => 'ID', |
|
4009 'order' => 'ASC', 'include' => array(), |
|
4010 'exclude' => array(), |
|
4011 'post_type' => XDMSG, |
|
4012 'suppress_filters' => true, |
|
4013 'meta_query' => array( |
|
4014 'relation' => 'AND', |
|
4015 array( |
|
4016 'key' => $this->msgtype_meta, |
|
4017 'value' => 'msgid', |
|
4018 'compare' => '=' |
|
4019 ), |
|
4020 array( |
|
4021 'key' => $this->msglang_meta, |
|
4022 'value' => $curlang, |
|
4023 'compare' => 'LIKE' |
|
4024 ), |
|
4025 array( |
|
4026 'key' => $this->msg_extracted_comments, |
|
4027 'value' => $extract, |
|
4028 'compare' => 'LIKE' |
|
4029 ) |
|
4030 ) |
|
4031 ) ); |
|
4032 |
|
4033 |
|
4034 |
|
4035 } else if ( isset ( $extract_array [ 'origin' ] ) ) { |
|
4036 //error_log ( '------------' . serialize ( $extract_array [ 'origin' ] )); |
|
4037 if ( !is_array( $extract_array [ 'origin' ] ) ) { |
|
4038 |
|
4039 $array_tax = array( |
|
4040 'taxonomy' => 'origin', |
|
4041 'field' => 'slug', |
|
4042 'terms' => $extract_array [ 'origin' ] |
|
4043 ); |
|
4044 |
|
4045 } else { |
|
4046 |
|
4047 $array_tax = array( |
|
4048 'taxonomy' => 'origin', |
|
4049 'field' => 'slug', |
|
4050 'terms' => $extract_array [ 'origin' ], |
|
4051 'operator' => 'IN' |
|
4052 ); |
|
4053 } |
|
4054 |
|
4055 if ( $extract_array [ 'origin' ] == '' || $extract_array [ 'origin' ] == array() ) { |
|
4056 |
|
4057 return get_posts( array( |
|
4058 'numberposts' => -1, 'offset' => 0, |
|
4059 'category' => 0, 'orderby' => 'ID', |
|
4060 'order' => 'ASC', 'include' => array(), |
|
4061 'exclude' => array(), |
|
4062 'post_type' => XDMSG, |
|
4063 'suppress_filters' => true, |
|
4064 'meta_query' => array( |
|
4065 'relation' => 'AND', |
|
4066 array( |
|
4067 'key' => $this->msgtype_meta, |
|
4068 'value' => 'msgid', |
|
4069 'compare' => '=' |
|
4070 ), |
|
4071 array( |
|
4072 'key' => $this->msglang_meta, |
|
4073 'value' => $curlang, |
|
4074 'compare' => 'LIKE' |
|
4075 ) |
|
4076 ) |
|
4077 ) ); |
|
4078 |
|
4079 } else { |
|
4080 |
|
4081 return get_posts( array( |
|
4082 'numberposts' => -1, 'offset' => 0, |
|
4083 'category' => 0, 'orderby' => 'ID', |
|
4084 'order' => 'ASC', 'include' => array(), |
|
4085 'exclude' => array(), |
|
4086 'post_type' => XDMSG, |
|
4087 'suppress_filters' => true, |
|
4088 'meta_query' => array( |
|
4089 'relation' => 'AND', |
|
4090 array( |
|
4091 'key' => $this->msgtype_meta, |
|
4092 'value' => 'msgid', |
|
4093 'compare' => '=' |
|
4094 ), |
|
4095 array( |
|
4096 'key' => $this->msglang_meta, |
|
4097 'value' => $curlang, |
|
4098 'compare' => 'LIKE' |
|
4099 ) |
|
4100 ), |
|
4101 'tax_query' => array( |
|
4102 $array_tax |
|
4103 ) |
|
4104 ) ); |
|
4105 } |
|
4106 |
|
4107 } |
|
4108 |
|
4109 |
|
4110 |
|
4111 } else { // po |
|
4112 |
|
4113 if ( $extract_array == array() ) { |
|
4114 // to have also empty translation |
|
4115 $meta_key_val = $this->msgtype_meta; |
|
4116 $meta_value_val = 'msgid'; |
|
4117 return get_posts( array( |
|
4118 'numberposts' => -1, 'offset' => 0, |
|
4119 'category' => 0, 'orderby' => 'ID', |
|
4120 'order' => 'ASC', 'include' => array(), |
|
4121 'exclude' => array(), 'post_type' => XDMSG, |
|
4122 'suppress_filters' => true, |
|
4123 'meta_query' => array( |
|
4124 array ( |
|
4125 'meta_key' => $meta_key_val, |
|
4126 'meta_value' =>$meta_value_val |
|
4127 ) |
|
4128 ), |
|
4129 ) |
|
4130 ); |
|
4131 |
|
4132 } else if ( isset ( $extract_array [ 'origin' ] ) ) { |
|
4133 |
|
4134 |
|
4135 if ( !is_array( $extract_array [ 'origin' ] ) ) { |
|
4136 |
|
4137 $array_tax = array( |
|
4138 'taxonomy' => 'origin', |
|
4139 'field' => 'slug', |
|
4140 'terms' => $extract_array [ 'origin' ] |
|
4141 ); |
|
4142 |
|
4143 } else { |
|
4144 |
|
4145 $array_tax = array( |
|
4146 'taxonomy' => 'origin', |
|
4147 'field' => 'slug', |
|
4148 'terms' => $extract_array [ 'origin' ], |
|
4149 'operator' => 'IN' |
|
4150 ); |
|
4151 } |
|
4152 |
|
4153 return get_posts( array( |
|
4154 'numberposts' => -1, 'offset' => 0, |
|
4155 'category' => 0, 'orderby' => 'ID', |
|
4156 'order' => 'ASC', 'include' => array(), |
|
4157 'exclude' => array(), |
|
4158 'post_type' => XDMSG, |
|
4159 'suppress_filters' => true, |
|
4160 'meta_query' => array( |
|
4161 array( |
|
4162 'key' => $this->msgtype_meta, |
|
4163 'value' => 'msgid', |
|
4164 'compare' => '=' |
|
4165 ) |
|
4166 ), |
|
4167 'tax_query' => array( |
|
4168 $array_tax |
|
4169 ) |
|
4170 ) ); |
|
4171 |
|
4172 } else { |
|
4173 |
|
4174 $extract = $extract_array [ $this->msg_extracted_comments ]; |
|
4175 |
|
4176 $like_or_not = ( $extract_array [ 'like-'. $this->msg_extracted_comments ] == true )? 'LIKE' : 'NOT LIKE' ; |
|
4177 |
|
4178 return get_posts( array( |
|
4179 'numberposts' => -1, 'offset' => 0, |
|
4180 'category' => 0, 'orderby' => 'ID', |
|
4181 'order' => 'ASC', 'include' => array(), |
|
4182 'exclude' => array(), |
|
4183 'post_type' => XDMSG, |
|
4184 'suppress_filters' => true, |
|
4185 'meta_query' => array( |
|
4186 'relation' => 'AND', |
|
4187 array( |
|
4188 'key' => $this->msgtype_meta, |
|
4189 'value' => 'msgid', |
|
4190 'compare' => '=' |
|
4191 ), |
|
4192 array( |
|
4193 'key' => $this->msg_extracted_comments, |
|
4194 'value' => $extract , |
|
4195 'compare' => $like_or_not |
|
4196 ) |
|
4197 ) |
|
4198 ) ); |
|
4199 |
|
4200 } |
|
4201 } |
|
4202 } |
|
4203 |
|
4204 /** |
|
4205 * return msgstr object (array translation) |
|
4206 * @since 2.0 |
|
4207 */ |
|
4208 function get_cpt_msgstr( $cur_msgid_ID, $curlang, $plural = false ) { |
|
4209 $res = get_post_meta ( $cur_msgid_ID, $this->msglang_meta, false ); |
|
4210 $thelangs = ( is_array ( $res ) && array() != $res ) ? $res[0] : array(); |
|
4211 if ( $plural ) { |
|
4212 |
|
4213 $cur_msgstr_ID = $thelangs['msgstrlangs'][$curlang]['msgstr_0']; |
|
4214 // get_parent (msgstr_0) |
|
4215 |
|
4216 $msgstr_array = array ( get_post( $cur_msgstr_ID ) ) ; |
|
4217 // get_children |
|
4218 $args = array( |
|
4219 'numberposts' => -1, 'post_type' => XDMSG, |
|
4220 'post_status' => 'publish', 'post_parent' => $cur_msgstr_ID |
|
4221 ); |
|
4222 $children = get_posts( $args ); |
|
4223 return array_merge($msgstr_array, $children); |
|
4224 |
|
4225 } else { |
|
4226 if ( isset ( $thelangs['msgstrlangs'][$curlang]['msgstr'] ) ) { |
|
4227 $cur_msgstr_ID = $thelangs['msgstrlangs'][$curlang]['msgstr']; |
|
4228 // get_content |
|
4229 //echo ' - '.$cur_msgstr_ID; |
|
4230 return get_post( $cur_msgstr_ID ); |
|
4231 } else { |
|
4232 return false; |
|
4233 } |
|
4234 } |
|
4235 } |
|
4236 |
|
4237 /** |
|
4238 * convert cpt (msgid - msgstr) to MO or PO |
|
4239 * |
|
4240 * @since 2.0 |
|
4241 * |
1225 */ |
4242 */ |
1226 function from_twin_to_POMO ($curlang, $obj='mo') { |
4243 function from_cpt_to_POMO ( $curlang, $obj='mo', $extract = array() ) { |
1227 global $user_identity,$user_url,$user_email; |
4244 global $user_identity,$user_url,$user_email; |
1228 if ($obj == 'mo') { |
4245 if ($obj == 'mo') { |
1229 $mo = new MO(); /* par default */ |
4246 $mo = new MO(); /* par default */ |
1230 } else { |
4247 } else { |
1231 $mo = new PO(); |
4248 $mo = new PO(); |