|
1 <?php |
|
2 /* |
|
3 Plugin Name: 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... - |
|
6 Author: MS |
|
7 Version: 1.0.3 |
|
8 Author URI: http://dev.xiligroup.com |
|
9 */ |
|
10 |
|
11 # beta 1.0.3 - fixes some directories issues in (rare) xamp servers and in theme's terms import. Create .po with empty translations. |
|
12 # beta 1.0.2 - JS and vars, create lang list, if xili-language absent, for international themes - lot of fixes |
|
13 # beta 1.0.1 - add scripts for form with plural msg (id or str) |
|
14 # beta 1.0.0 - use pomo libraries and classes - ONLY >= 2.8 |
|
15 # beta 0.9.9 - fixes existing msgid terms - better log display when importing theme's terms |
|
16 # beta 0.9.8.2 - more html tags in msg str or id |
|
17 # beta 0.9.8.1 - some fixes for IIS server and PHP 5.2.1 |
|
18 # beta 0.9.8 - WP 2.8 - fix query error |
|
19 # beta 0.9.7.3 <- to - see readme.txt - from 0.9.4 |
|
20 # beta 0.9.3 - first published - 090131 MS |
|
21 |
|
22 |
|
23 # This plugin is free software; you can redistribute it and/or |
|
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 |
|
39 include_once(ABSPATH . WPINC . '/pomo/po.php'); /* not included in wp-settings */ |
|
40 |
|
41 class xili_dictionary { |
|
42 |
|
43 var $subselect = ''; /* used to subselect by msgid or languages*/ |
|
44 var $xililanguage = ''; /* neveractive isactive wasactive */ |
|
45 var $tempoutput = ""; |
|
46 var $langfolder ='/'; /* where po or mo files */ |
|
47 var $xili_settings; /* saved in options */ |
|
48 var $ossep = "/"; /* for recursive file search in xamp */ |
|
49 |
|
50 function xili_dictionary($langsfolder = '/') { |
|
51 /* activated when first activation of plug */ |
|
52 register_activation_hook(__FILE__,array(&$this,'xili_dictionary_activation')); |
|
53 $this->ossep = strtoupper(substr(PHP_OS,0,3)=='WIN')?'\\':'/'; /* for rare xamp servers*/ |
|
54 /* get current settings - name of taxonomy - name of query-tag */ |
|
55 $this->xililanguage_state(); |
|
56 $this->xili_settings = get_option('xili_dictionary_settings'); |
|
57 if(empty($this->xili_settings)) { |
|
58 $this->xili_dictionary_activation(); |
|
59 $this->xili_settings = get_option('xili_dictionary_settings'); |
|
60 } |
|
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 |
|
72 /* test if version changed */ |
|
73 $version = $this->xili_settings['version']; |
|
74 if ($version <= '0.2') { |
|
75 /* update relationships for grouping existing dictionary terms */ |
|
76 $this->update_terms_langs_grouping(); |
|
77 $this->xili_settings['version'] = '1.0'; |
|
78 update_option('xili_dictionary_settings', $this->xili_settings); |
|
79 } |
|
80 $this->fill_default_languages_list(); |
|
81 /* Actions */ |
|
82 add_action('admin_menu', array(&$this,'xili_add_dict_pages')); |
|
83 add_action('init', array(&$this, 'init_textdomain')); |
|
84 add_filter('plugin_action_links', array(&$this,'xilidict_filter_plugin_actions'), 10, 2); |
|
85 } |
|
86 |
|
87 function xili_dictionary_activation() { |
|
88 $this->xili_settings = get_option('xili_dictionary_settings'); |
|
89 if(empty($this->xili_settings)) { |
|
90 $submitted_settings = array( |
|
91 'taxonomy' => 'dictionary', |
|
92 'langs_folder' => '', |
|
93 'version' => '1.0' |
|
94 ); |
|
95 update_option('xili_dictionary_settings', $submitted_settings); |
|
96 } |
|
97 } |
|
98 |
|
99 /** * add js in admin * @updated 1.0.2 */ |
|
100 function xili_add_js() { |
|
101 wp_enqueue_script( 'xd-plural', '/'.PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/plural.php?var='.XPLURAL, array('jquery'), XILIDICTIONARY_VER); |
|
102 } |
|
103 |
|
104 /** *add admin menu and associated page */ |
|
105 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')); |
|
107 add_action('load-'.$this->thehook, array(&$this,'on_load_page')); |
|
108 add_action( "admin_print_scripts-".$this->thehook, array(&$this,'xili_add_js')); |
|
109 } |
|
110 |
|
111 function on_load_page() { |
|
112 wp_enqueue_script('common'); |
|
113 wp_enqueue_script('wp-lists'); |
|
114 wp_enqueue_script('postbox'); |
|
115 |
|
116 add_meta_box('xili-dictionary-sidebox-1', __('Message','xili-dictionary'), array(&$this,'on_sidebox_1_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'); |
|
118 |
|
119 |
|
120 } |
|
121 |
|
122 /** |
|
123 * Add action link(s) to plugins page |
|
124 * |
|
125 * @since 0.9.3 |
|
126 * @author MS |
|
127 * @copyright Dion Hulse, http://dd32.id.au/wordpress-plugins/?configure-link and scripts@schloebe.de |
|
128 */ |
|
129 function xilidict_filter_plugin_actions($links, $file){ |
|
130 static $this_plugin; |
|
131 |
|
132 if (!$this_plugin ) $this_plugin = plugin_basename(__FILE__); |
|
133 |
|
134 if ($file == $this_plugin ) { |
|
135 $settings_link = '<a href="tools.php?&page=dictionary_page">' . __('Settings') . '</a>'; |
|
136 $links = array_merge( array($settings_link), $links); // before other links |
|
137 } |
|
138 return $links; |
|
139 } |
|
140 |
|
141 function init_textdomain() { |
|
142 /*multilingual for admin pages and menu*/ |
|
143 load_plugin_textdomain('xili-dictionary',PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__))); |
|
144 |
|
145 if (!defined('THEME_LANGS_FOLDER')) { /* set or detect at least a .mo or .po */ |
|
146 if ($this->xili_settings['langs_folder'] == "") { |
|
147 $this->find_files(get_template_directory(), '/.[mp]o$/', array(&$this,'searchpath')); |
|
148 update_option('xili_dictionary_settings', $this->xili_settings); |
|
149 } |
|
150 define('THEME_LANGS_FOLDER',$this->xili_settings['langs_folder']); // for bkwd compatibility with xili-dictionary |
|
151 } |
|
152 } |
|
153 function searchpath($path, $filename) { |
|
154 $this->xili_settings['langs_folder'] = str_replace(get_template_directory(),'',$path); |
|
155 } |
|
156 |
|
157 function xililanguage_state() { |
|
158 /* test if xili-language is present or was present */ |
|
159 if (class_exists('xili_language')) { |
|
160 $this->xililanguage = 'isactive'; |
|
161 } else { |
|
162 /* test if language taxonomy relationships are present */ |
|
163 $xl_settings = get_option('xili_language_settings'); |
|
164 if (empty($xl_settings)) { |
|
165 $this->xililanguage = 'neveractive'; |
|
166 } else { |
|
167 $this->xililanguage = 'wasactive'; |
|
168 } |
|
169 } |
|
170 } |
|
171 /** * @since 1.02 */ |
|
172 function fill_default_languages_list() { |
|
173 if ($this->xililanguage == 'neveractive' || $this->xililanguage == 'wasactive') { |
|
174 |
|
175 if (!$this->xili_settings[XDDICTLANGS]) { |
|
176 $default_langs_array = array( |
|
177 'en_us' => array('en_US', 'english'), |
|
178 'fr_fr' => array('fr_FR', 'french'), |
|
179 'de_de' => array('de_DE', 'german'), |
|
180 'es_es' => array('es_ES', 'spanish'), |
|
181 'it_it' => array('it_IT', 'italian') |
|
182 ); |
|
183 /* add wp admin lang */ |
|
184 if (defined ('WPLANG')) { |
|
185 $lkey = strtolower(WPLANG); |
|
186 if (!array_key_exists($lkey, $default_langs_array)) $default_langs_array[$lkey] = array (WPLANG, WPLANG); |
|
187 } |
|
188 $this->xili_settings[XDDICTLANGS] = $default_langs_array; |
|
189 update_option('xili_dictionary_settings', $this->xili_settings); |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 /** |
|
195 * private function to update grouping of terms if xili-language is active |
|
196 * |
|
197 * |
|
198 * |
|
199 */ |
|
200 function update_terms_langs_grouping() { |
|
201 if ($this->xililanguage == 'isactive') { |
|
202 |
|
203 $listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false,'get'=>'all')); |
|
204 if (!empty($listdictiolines)) { |
|
205 foreach ($listdictiolines as $dictioline) { |
|
206 /* check slug before creating relationship if parent = O select msgid */ |
|
207 if ($dictioline->parent != 0) { |
|
208 $extend = substr($dictioline->slug,-5); |
|
209 $lang = get_term_by('slug',$extend,TAXONAME,OBJECT); |
|
210 if ($lang) { |
|
211 $term = $lang->name; |
|
212 } else { |
|
213 $term = $extend; |
|
214 } |
|
215 $args = array( 'alias_of' => '', 'description' => 'Dictionary Group in '.$term, 'parent' => 0, 'slug' =>$extend); |
|
216 $theids = wp_insert_term( $term, XDDICTLANGS, $args); |
|
217 wp_set_object_terms((int) $dictioline->term_id, $extend, XDDICTLANGS,false); |
|
218 } |
|
219 } |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 /** |
|
225 * private functions for dictionary_settings |
|
226 * @since 0.9.3 |
|
227 * |
|
228 * fill the content of the boxes (right side and normal) |
|
229 * |
|
230 */ |
|
231 |
|
232 function on_sidebox_1_content($data) { |
|
233 extract($data); |
|
234 ?> |
|
235 <h4><?php _e('Note:','xili-dictionary') ?></h4> |
|
236 <p><?php echo $message;?></p> |
|
237 <?php |
|
238 } |
|
239 |
|
240 function on_sidebox_2_content() { ?> |
|
241 |
|
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> |
|
243 <fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"><legend><?php echo __("Theme's informations:",'xili-dictionary').' ('.get_option("template").')'; ?></legend> |
|
244 <p> |
|
245 <?php $langfolder = (defined('THEME_LANGS_FOLDER')) ? THEME_LANGS_FOLDER : $this->xili_settings['langs_folder']; |
|
246 echo __("Languages sub-folder:",'xili-dictionary').' '. $langfolder; ?><br /> |
|
247 <?php _e('Available MO files:','xili-dictionary'); echo '<br />'; |
|
248 $this->find_files(get_template_directory(), '/.mo$/', array(&$this,'available_mo_files')) ;?> |
|
249 </p> |
|
250 </fieldset> |
|
251 |
|
252 <?php |
|
253 } |
|
254 |
|
255 function on_normal_1_content($data) { |
|
256 extract($data); |
|
257 $sortparent = (($this->subselect == '') ? '' : '&tagsgroup_parent_select='.$this->subselect ); |
|
258 ?> |
|
259 <table class="widefat"> |
|
260 <thead> |
|
261 <tr> |
|
262 <th scope="col"><a href="?page=dictionary_page"><?php _e('ID') ?></a></th> |
|
263 <th scope="col"><a href="?page=dictionary_page&orderby=name<?php echo $sortparent; ?>"><?php _e('Text') ?></a></th> |
|
264 |
|
265 <th scope="col"><a href="?page=dictionary_page&orderby=slug<?php echo $sortparent; ?>"><?php _e('Slug','xili-dictionary') ?></a></th> |
|
266 <th scope="col" ><?php _e('Group','xili-dictionary') ?></th> |
|
267 |
|
268 <th colspan="2"><?php _e('Action') ?></th> |
|
269 </tr> |
|
270 </thead> |
|
271 <tbody id="the-list"> |
|
272 <?php $this->xili_dict_row($orderby,$tagsnamelike,$tagsnamesearch); /* the lines */ |
|
273 ?> |
|
274 </tbody> |
|
275 </table> |
|
276 <?php if ($action=='edit' || $action=='delete') :?> |
|
277 <p>(<a href="?action=add&page=dictionary_page"><?php _e('Add a term','xili-dictionary') ?></a>)</p> |
|
278 <?php endif; |
|
279 } |
|
280 |
|
281 function on_normal_2_content($data) { |
|
282 extract($data); |
|
283 |
|
284 /* the create - edit - delete form */ ?> |
|
285 <div style="background:#f5f5fe;"> |
|
286 <p id="add_edit"><?php _e($formhow,'xili-dictionary') ?></p> |
|
287 <?php |
|
288 if ($action=='export' || $action=='importmo' || $action=='import' || $action=='exportpo' ) { ?> |
|
289 |
|
290 <label for="language_file"> |
|
291 <select name="language_file" ><?php |
|
292 $extend = WPLANG; |
|
293 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
|
294 if (is_wp_error($listlanguages) || empty($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) { |
|
307 echo '<option value="'.$reflanguage->name.'"'; |
|
308 if ($extend == $reflanguage->name) { |
|
309 echo ' selected="selected"'; |
|
310 } |
|
311 echo ">".__($reflanguage->description,'xili-dictionary').'</option>'; |
|
312 |
|
313 } |
|
314 } ?> |
|
315 </select></label> |
|
316 <br /> <br /> |
|
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> |
|
318 <?php |
|
319 } elseif ($action=='importcats' || $action=='erasedictionary' || $action=='importcurthemeterms') { |
|
320 ?> |
|
321 |
|
322 <br /> <br /> |
|
323 <input class="button" type="submit" name="reset" value="<?php echo $cancel_text ?>" /> |
|
324 <input class="button-primary" type="submit" name="submit" value="<?php echo $submit_text ?>" /><br /></div> |
|
325 <?php |
|
326 |
|
327 |
|
328 } else { |
|
329 //print_r($dictioline); |
|
330 |
|
331 /* rules for edit dictioline */ |
|
332 $noedit = "" ; $noedited = "" ; |
|
333 if ($action=='edit' && $dictioline->parent == 0) { |
|
334 $noedited = 'disabled="disabled"'; |
|
335 $extend = ""; |
|
336 } elseif ($action=='edit') { |
|
337 /* search default */ |
|
338 $extend = substr($dictioline->slug,-5); |
|
339 } elseif ($action=='delete' && $dictioline->parent == 0) { |
|
340 $noedit = 'disabled="disabled"'; |
|
341 $extend = ""; |
|
342 } elseif ($action=='delete') { |
|
343 $noedit = 'disabled="disabled"'; |
|
344 $extend = substr($dictioline->slug,-5); |
|
345 } |
|
346 ?> |
|
347 <table class="editform" width="100%" cellspacing="2" cellpadding="5"> |
|
348 <tr> |
|
349 <?php if ($action=='edit' || $action=='delete') { |
|
350 $areacontent = $dictioline->description; |
|
351 $textareas = explode(XPLURAL,$dictioline->description); |
|
352 $firstcontent = $textareas[0]; /* also always before js splitting*/ |
|
353 } else { |
|
354 $areacontent = ""; |
|
355 $firstcontent = ""; |
|
356 } |
|
357 ?> |
|
358 <th scope="row" valign="top" align="right" width="25%"><label for="dictioline_description1"> |
|
359 <?php |
|
360 if ($action=='edit' && $dictioline->parent == 0) { |
|
361 _e('Full msgid (original)','xili-dictionary'); |
|
362 } elseif ($action=='edit') { |
|
363 _e('Full msgstr (translation)','xili-dictionary'); |
|
364 } else { |
|
365 _e('Full msg (id or str)','xili-dictionary'); |
|
366 } ?> : </label> |
|
367 <textarea style="visibility:hidden" name="dictioline_description" id="dictioline_description" cols="12" rows="3" disabled="disabled" ><?php echo $areacontent; ?></textarea> |
|
368 </th> |
|
369 <td align="left"> |
|
370 |
|
371 <input type="hidden" id="termnblines" name="termnblines" value="1" /> |
|
372 |
|
373 <div id="input1" style="margin-bottom:4px;" class="clonedInput"> |
|
374 <p id="areatitle1"><?php _e('Singular text','xili-dictionary'); ?></p> |
|
375 <textarea style="visibility:visible" class="plural" name="dictioline_description1" id="dictioline_description1" cols="50" rows="3" <?php echo $noedit; ?> ><?php echo $firstcontent; ?></textarea> |
|
376 |
|
377 </div> |
|
378 <?php if ($action != 'delete') { ?> |
|
379 <div> |
|
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> |
|
381 <input type="button" id="btnAdd" value="<?php _e('Add a plural','xili-dictionary') ?>" /> |
|
382 <input type="button" id="btnDel" value="<?php _e('Delete a plural','xili-dictionary') ?>" /> |
|
383 |
|
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()) { |
|
499 extract($data); |
|
500 ?> |
|
501 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Sub list of terms','xili-dictionary'); ?></legend> |
|
502 <label for="tagsnamelike"><?php _e('Starting with:','xili-dictionary') ?></label> |
|
503 <input name="tagsnamelike" id="tagsnamelike" type="text" value="<?php echo $tagsnamelike; ?>" /><br /> |
|
504 <label for="tagsnamesearch"><?php _e('Containing:','xili-dictionary') ?></label> |
|
505 <input name="tagsnamesearch" id="tagsnamesearch" type="text" value="<?php echo $tagsnamesearch; ?>" /> |
|
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> |
|
507 </fieldset> |
|
508 |
|
509 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Selection by language','xili-dictionary'); ?></legend> |
|
510 <select name="tagsgroup_parent_select" id="tagsgroup_parent_select" style="width:100%;"> |
|
511 <option value="no_select" ><?php _e('No sub-selection','xili-dictionary'); ?></option> |
|
512 <?php $checked = ($this->subselect == "msgid") ? 'selected="selected"' :'' ; |
|
513 echo '<option value="msgid" '.$checked.' >'.__('Only MsgID (en_US)','xili-dictionary').'</option>'; |
|
514 echo $this->build_grouplist(); |
|
515 ?> |
|
516 </select> |
|
517 <br /> <p class="submit"><input type="submit" id="subselection" name="subselection" value="<?php _e('Sub select…','xili-dictionary'); ?>" /></p> |
|
518 </fieldset> |
|
519 <?php |
|
520 } |
|
521 /** * @since 1.0.2 * only if xili-language plugin is absent */ |
|
522 function on_normal_5_content($data=array()) { |
|
523 extract($data); |
|
524 ?> |
|
525 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Language to delete','xili-dictionary'); ?></legend> |
|
526 <p><?php _e('Only the languages list is here modified (but not the dictionary\'s contents)','xili-dictionary'); ?></p> |
|
527 <select name="langs_list" id="langs_list" style="width:100%;"> |
|
528 <option value="no_select" ><?php _e('Select...','xili-dictionary'); ?></option> |
|
529 <?php echo $this->build_grouplist(''); |
|
530 ?> |
|
531 </select> |
|
532 <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 /> |
|
534 <fieldset style="margin:2px; padding:3px; border:1px solid #ccc;"><legend><?php _e('Language to add','xili-dictionary'); ?></legend> |
|
535 <label for="lang_ISO"><?php _e('ISO (xx_YY)','xili-dictionary') ?></label>: |
|
536 <input name="lang_ISO" id="lang_ISO" type="text" value="" size="5"/><br /> |
|
537 <label for="lang_name"><?php _e('Name (eng.)','xili-dictionary') ?></label>: |
|
538 <input name="lang_name" id="lang_name" type="text" value="" size="20" /> |
|
539 <br /> |
|
540 <p class="submit"><input type="submit" id="lang_add" name="lang_add" value="<?php _e('Add a language','xili-dictionary'); ?>" /></p> |
|
541 </fieldset> |
|
542 <?php } |
|
543 /** |
|
544 * build the list of group of languages for dictionary |
|
545 * |
|
546 * @updated 1.0.2 |
|
547 * |
|
548 */ |
|
549 function build_grouplist ($left_line = 'Only:') { |
|
550 if ($this->xililanguage == 'isactive') { |
|
551 $listdictlanguages = get_terms(XDDICTLANGS, array('hide_empty' => false)); |
|
552 foreach($listdictlanguages as $dictlanguage) { |
|
553 $checked = ($this->subselect == $dictlanguage->slug) ? 'selected="selected"' :'' ; |
|
554 $optionlist .= '<option value="'.$dictlanguage->slug.'" '.$checked.' >'.__('Only:','xili-dictionary').' '.$dictlanguage->name.'</option>'; |
|
555 } |
|
556 } else { |
|
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; |
|
564 } |
|
565 /** |
|
566 * @since 0.9.9 |
|
567 * |
|
568 * |
|
569 */ |
|
570 function test_and_create_slug($description, $slug, $lang='') { |
|
571 $slug = sanitize_title(str_replace(' ','_',$slug)); |
|
572 //echo $slug; |
|
573 $found = is_term($slug,DTAXONAME); |
|
574 if ($found){ |
|
575 /* compare description*/ |
|
576 $found_term = get_term($found['term_id'],DTAXONAME); |
|
577 if ($found_term->description == $description) { |
|
578 return $slug; |
|
579 } else { |
|
580 if ( '' == $lang) { |
|
581 //echo 'nul'; |
|
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 } |
|
596 /** * @since 1.0.0 */ |
|
597 function xili_dic_update_term($term, $taxonomy, $args) { |
|
598 remove_filter('pre_term_description', 'wp_filter_kses'); /* 0.9.8.2 to allow more tag in msg str or id */ |
|
599 $rterm_id = wp_update_term( $term, $taxonomy, $args); |
|
600 add_filter('pre_term_description', 'wp_filter_kses'); |
|
601 return $rterm_id; |
|
602 } |
|
603 function xili_dic_insert_term($termname, $taxonomy, $args) { |
|
604 remove_filter('pre_term_description', 'wp_filter_kses'); /* 0.9.8.2 to allow more tag in msg str or id */ |
|
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() { |
|
612 $formtitle = __('Add a term','xili-dictionary'); |
|
613 $formhow = " "; |
|
614 $submit_text = __('Add »','xili-dictionary'); |
|
615 $cancel_text = __('Cancel'); |
|
616 $this->langfolder = (defined('THEME_LANGS_FOLDER') && THEME_LANGS_FOLDER !='/') ? '/'.str_replace("/","",THEME_LANGS_FOLDER).'/' : "/"; |
|
617 $tagsnamelike = $_POST['tagsnamelike']; |
|
618 if (isset($_GET['tagsnamelike'])) |
|
619 $tagsnamelike = $_GET['tagsnamelike']; /* if link from table */ |
|
620 $tagsnamesearch = $_POST['tagsnamesearch']; |
|
621 if (isset($_GET['tagsnamesearch'])) |
|
622 $tagsnamesearch = $_GET['tagsnamesearch']; |
|
623 |
|
624 if (isset($_POST['reset'])) { |
|
625 $action=$_POST['reset']; |
|
626 |
|
627 } elseif (isset($_POST['action'])) { |
|
628 $action=$_POST['action']; |
|
629 } |
|
630 |
|
631 if (isset($_GET['action'])) { |
|
632 $action=$_GET['action']; |
|
633 $term_id = $_GET['term_id']; |
|
634 } |
|
635 /* language delete or add */ |
|
636 if (isset($_POST['lang_delete'])) { |
|
637 $action='lang_delete'; |
|
638 } |
|
639 if (isset($_POST['lang_add'])) { |
|
640 $action='lang_add'; |
|
641 } |
|
642 /* sub lists */ |
|
643 if (isset($_POST['notagssublist'])) { |
|
644 $action='notagssublist'; |
|
645 } |
|
646 |
|
647 if (isset($_POST['tagssublist'])) { |
|
648 $action='tagssublist'; |
|
649 } |
|
650 if (isset($_GET['orderby'])) : |
|
651 $orderby = $_GET['orderby'] ; |
|
652 else : |
|
653 $orderby = 't.term_id'; /* 0.9.8 */ |
|
654 endif; |
|
655 if(isset($_POST['tagsgroup_parent_select']) && $_POST['tagsgroup_parent_select'] != 'no_select') { |
|
656 $this->subselect = $_POST['tagsgroup_parent_select']; |
|
657 } else { |
|
658 $this->subselect = ''; |
|
659 } |
|
660 if (isset($_GET['tagsgroup_parent_select'])) |
|
661 $this->subselect = $_GET['tagsgroup_parent_select']; |
|
662 |
|
663 if (isset($_POST['subselection'])) { |
|
664 $action='subselection'; |
|
665 } |
|
666 |
|
667 $message = $action." = " ; |
|
668 switch($action) { |
|
669 |
|
670 case 'lang_delete'; |
|
671 $reflang = $_POST['langs_list']; |
|
672 $wp_lang = (defined('WPLANG')) ? strtolower(WPLANG) : 'en_us'; |
|
673 if ($reflang != 'no_select' && $reflang != 'en_us' && $reflang != $wp_lang) { |
|
674 unset($this->xili_settings[XDDICTLANGS][$reflang]); |
|
675 update_option('xili_dictionary_settings', $this->xili_settings); |
|
676 $message .= ' '.$reflang.' deleted'; |
|
677 } else { |
|
678 $message .= ' nothing to delete'; |
|
679 } |
|
680 |
|
681 $actiontype = "add"; |
|
682 break; |
|
683 |
|
684 case 'lang_add'; |
|
685 $reflang = ('' != $_POST['lang_ISO'] ) ? $_POST['lang_ISO'] : "???"; |
|
686 $reflangname = ('' !=$_POST['lang_name']) ? $_POST['lang_name'] : $reflang; |
|
687 if ($reflang != '???' && strlen($reflang) == 5 && substr($reflang,2,1) == '_') { |
|
688 $lkey = strtolower($reflang); |
|
689 $reflang = strtolower(substr($reflang,0,3)).strtoupper(substr($reflang,-2)); |
|
690 $msg = (array_key_exists($lkey, $this->xili_settings[XDDICTLANGS])) ? ' updated' : ' added'; |
|
691 $this->xili_settings[XDDICTLANGS][$lkey] = array($reflang,$reflangname); |
|
692 update_option('xili_dictionary_settings', $this->xili_settings); |
|
693 $message .= ' '.$reflang.$msg; |
|
694 } else { |
|
695 $message .= ' error ('.$reflang.') ! no add'; |
|
696 } |
|
697 |
|
698 $actiontype = "add"; |
|
699 break; |
|
700 |
|
701 case 'subselection'; |
|
702 $tagsnamelike = $_POST['tagsnamelike']; |
|
703 $tagsnamesearch = $_POST['tagsnamesearch']; |
|
704 $message .= ' selection of '.$_POST['tagsgroup_parent_select']; |
|
705 $actiontype = "add"; |
|
706 break; |
|
707 |
|
708 case 'notagssublist'; |
|
709 $tagsnamelike = ''; |
|
710 $tagsnamesearch = ''; |
|
711 $message .= ' no sub list of terms'; |
|
712 $actiontype = "add"; |
|
713 break; |
|
714 |
|
715 case 'tagssublist'; |
|
716 $message .= ' sub list of terms starting with '.$_POST['tagsnamelike']; |
|
717 $actiontype = "add"; |
|
718 break; |
|
719 |
|
720 case 'add': |
|
721 |
|
722 $originalortrans = $_POST['dictioline_description1']; |
|
723 $nblines = $_POST['termnblines']; /**/ |
|
724 if ( $nblines > 1 ) { |
|
725 for ($i = 2; $i <= $nblines; $i++) { |
|
726 $originalortrans .= XPLURAL.$_POST['dictioline_description'.$i]; |
|
727 } |
|
728 } |
|
729 |
|
730 /*create the slug with term and add prefix*/ |
|
731 $possible = true; |
|
732 if (''!=$_POST['dictioline_lang']) { |
|
733 if ('no_parent' != $_POST['dictioline_parent'] ) { |
|
734 $parent_id = $_POST['dictioline_parent']; |
|
735 $parent_term = get_term($parent_id,DTAXONAME,OBJECT,'edit'); |
|
736 $sslug = $parent_term->slug.'_'.$_POST['dictioline_lang'] ; |
|
737 |
|
738 $lang = $_POST['dictioline_lang']; |
|
739 } else { |
|
740 $message .= __('No parent term defined','xili-dictionary'); |
|
741 $possible = false; |
|
742 } |
|
743 } else { |
|
744 $lang = ''; |
|
745 /* is content plural */ |
|
746 if (false === strpos($originalortrans,XPLURAL)) { |
|
747 $sslug = htmlentities($originalortrans); |
|
748 |
|
749 } else { |
|
750 $plurals = explode (XPLURAL,$originalortrans); |
|
751 $sslug = htmlentities($plurals[0]); /* in term slug only first*/ |
|
752 } |
|
753 } |
|
754 $sslug = $this->test_and_create_slug($originalortrans, $sslug, $lang); |
|
755 |
|
756 if ($possible) { |
|
757 $aliasof = $_POST['alias_of']; |
|
758 $args = array('alias_of' => $aliasof, 'description' => $originalortrans, 'parent' => $_POST['dictioline_parent'], 'slug' => $sslug); |
|
759 |
|
760 $rterm_id = $this->xili_dic_insert_term( $originalortrans, DTAXONAME, $args); |
|
761 |
|
762 if (''!=$_POST['dictioline_lang']) { |
|
763 if (is_wp_error($rterm_id)) {$message .= ' ---- error ---- '; $possible = false ;} else { |
|
764 wp_set_object_terms((int) $rterm_id['term_id'], $_POST['dictioline_lang'], XDDICTLANGS,false); |
|
765 } |
|
766 } else { |
|
767 if (is_wp_error($rterm_id)) { $message .= ' ---- error ---- '; $possible = false ; } else { $message .= " (". $rterm_id['term_id'] .") "; } |
|
768 } |
|
769 } |
|
770 $actiontype = "add"; |
|
771 if ($possible) $message .= " - ".__('A new term was added.','xili-dictionary'); |
|
772 break; |
|
773 |
|
774 case 'edit'; |
|
775 $actiontype = "edited"; |
|
776 |
|
777 $dictioline = get_term($term_id,DTAXONAME,OBJECT,'edit'); |
|
778 $submit_text = __('Update »','xili-dictionary'); |
|
779 $formtitle = 'Edit term'; |
|
780 $message .= " - ".__('Term to update.','xili-dictionary'); |
|
781 break; |
|
782 |
|
783 case 'edited'; |
|
784 $actiontype = "add"; |
|
785 $term = $_POST['dictioline_term_id']; |
|
786 $termname = $_POST['dictioline_name']; |
|
787 $sslug = $_POST['dictioline_slug']; |
|
788 $originalortrans = $_POST['dictioline_description1']; |
|
789 $nblines = $_POST['termnblines']; /**/ |
|
790 if ( $nblines > 1 ) { |
|
791 for ($i = 2; $i <= $nblines; $i++) { |
|
792 $originalortrans .= XPLURAL.$_POST['dictioline_description'.$i]; |
|
793 } |
|
794 } |
|
795 |
|
796 if (''!=$_POST['dictioline_lang']) { |
|
797 $parent_id = $_POST['dictioline_parent']; |
|
798 $parent_term = get_term($parent_id,DTAXONAME,OBJECT,'edit'); |
|
799 $sslug = $parent_term->slug.'_'.$_POST['dictioline_lang'] ; |
|
800 } |
|
801 |
|
802 $args = array('name'=>$termname, 'alias_of' => $_POST['alias_of'], 'description' => $originalortrans , 'parent' => $_POST['dictioline_parent'], 'slug' => $sslug); |
|
803 |
|
804 $this->xili_dic_update_term($term, DTAXONAME, $args); |
|
805 |
|
806 if (''!=$_POST['dictioline_lang']) { |
|
807 if (is_wp_error($rterm_id)) {$message .= ' ---- error ---- ';} else { |
|
808 wp_set_object_terms((int) $rterm_id['term_id'], $_POST['dictioline_lang'], XDDICTLANGS,false); |
|
809 } |
|
810 } |
|
811 $message .= " - ".__('A term was updated.','xili-dictionary').' '.$_POST['dictioline_term_id']; |
|
812 break; |
|
813 |
|
814 case 'delete'; |
|
815 $actiontype = "deleting"; |
|
816 $submit_text = __('Delete »','xili-dictionary'); |
|
817 $formtitle = 'Delete term ?'; |
|
818 $dictioline = get_term($term_id,DTAXONAME,OBJECT,'edit'); |
|
819 |
|
820 $message .= " - ".__('A term to delete. CLICK MENU DICTIONARY TO CANCEL !','xili-dictionary'); |
|
821 |
|
822 break; |
|
823 |
|
824 case 'deleting'; |
|
825 $actiontype = "add"; |
|
826 $term_id = $_POST['dictioline_term_id']; |
|
827 wp_delete_object_term_relationships( $term_id, XDDICTLANGS ); |
|
828 wp_delete_term( $term_id, DTAXONAME, $args); |
|
829 $message .= " - ".__('A term was deleted.','xili-dictionary'); |
|
830 $term_id = 0; /* 0.9.7.2 */ |
|
831 break; |
|
832 |
|
833 case 'export'; |
|
834 $actiontype = "exporting"; |
|
835 $formtitle = __('Export mo file','xili-dictionary'); |
|
836 $formhow = __('To create a .mo file, choose language and click below.','xili-dictionary'); |
|
837 $submit_text = __('Export »','xili-dictionary'); |
|
838 break; |
|
839 case 'exporting'; |
|
840 $actiontype = "add"; |
|
841 $selectlang = $_POST['language_file']; |
|
842 if ("" != $selectlang){ |
|
843 //$this->xili_create_mo_file(strtolower($selectlang)); |
|
844 $mo = $this->from_twin_to_POMO ($selectlang); |
|
845 if (false === $this->Save_MO_to_file ($selectlang , $mo )) { |
|
846 $message .= ' '.sprintf(__('error during exporting in %1s.mo file.','xili-dictionary'),$selectlang); |
|
847 } else { |
|
848 $message .= ' '.sprintf(__('exported in %1s.mo file.','xili-dictionary'),$selectlang); |
|
849 } |
|
850 } else { |
|
851 $message .= ' : error "'.$selectlang.'"'; |
|
852 } |
|
853 break; |
|
854 |
|
855 case 'exportpo'; |
|
856 $actiontype = "exportingpo"; |
|
857 $formtitle = __('Export po file','xili-dictionary'); |
|
858 $formhow = __('To export terms in a .po file, choose language and click below.','xili-dictionary'); |
|
859 $submit_text = __('Export »','xili-dictionary'); |
|
860 break; |
|
861 case 'exportingpo'; |
|
862 $actiontype = "add"; |
|
863 $selectlang = $_POST['language_file']; |
|
864 if ("" != $selectlang){ |
|
865 $po = $this->from_twin_to_POMO ($selectlang,'po'); |
|
866 //if ($this->xili_exportterms_inpo(strtolower($selectlang))) { |
|
867 if (false === $this->Save_PO_to_file ($selectlang , $po )) { |
|
868 $message .= ' '.sprintf(__('error during exporting in %1s.po file.','xili-dictionary'),$selectlang); |
|
869 } else { |
|
870 $message .= ' '.sprintf(__('exported in %1s.po file.','xili-dictionary'),$selectlang); |
|
871 } |
|
872 } else { |
|
873 $message .= ' : error "'.$selectlang.'"'; |
|
874 } |
|
875 break; |
|
876 |
|
877 case 'import'; |
|
878 $actiontype = "importing"; |
|
879 $formtitle = __('Import po file','xili-dictionary'); |
|
880 $formhow = __('To import terms of the current .po, choose language and click below.','xili-dictionary'); |
|
881 $submit_text = __('Import »','xili-dictionary'); |
|
882 break; |
|
883 case 'importmo'; |
|
884 $actiontype = "importingmo"; |
|
885 $formtitle = __('Import mo file','xili-dictionary'); |
|
886 $formhow = __('To import terms of the current .mo, choose language and click below.','xili-dictionary'); |
|
887 $submit_text = __('Import »','xili-dictionary'); |
|
888 break; |
|
889 |
|
890 case 'importing'; |
|
891 $actiontype = "add"; |
|
892 $message .= ' '.__('line imported from po file: ','xili-dictionary'); |
|
893 $selectlang = $_POST['language_file']; |
|
894 |
|
895 $po = $this->pomo_import_PO ($selectlang); //print_r($po); |
|
896 if (false !== $po ) $twintexts = $this->from_PO_to_twin ($po); |
|
897 |
|
898 if (is_array($twintexts)) { |
|
899 $nblines = $this->xili_import_in_tables($twintexts,$selectlang); |
|
900 $message .= __('id lines = ','xili-dictionary').$nblines[0].' & ' .__('str lines = ','xili-dictionary').$nblines[1].' & ' .__('str lines up = ','xili-dictionary').$nblines[2]; |
|
901 } else { |
|
902 |
|
903 $readfile = get_template_directory().$this->langfolder.$selectlang.'.po'; |
|
904 $message .= ' '.$readfile.__('po file is not present.','xili-dictionary'); |
|
905 } |
|
906 break; |
|
907 |
|
908 case 'importingmo'; |
|
909 $actiontype = "add"; |
|
910 $message .= ' '.__('line imported from mo file: ','xili-dictionary'); |
|
911 $selectlang = $_POST['language_file']; |
|
912 $mo = $this->pomo_import_MO ($selectlang); |
|
913 if (false !== $mo ) $twintexts = $this->from_MO_to_twin ($mo); |
|
914 if (is_array($twintexts)) { |
|
915 $nblines = $this->xili_import_in_tables($twintexts,$selectlang); |
|
916 $message .= __('id lines = ','xili-dictionary').$nblines[0].' & ' .__('str lines = ','xili-dictionary').$nblines[1].' & ' .__('str lines up = ','xili-dictionary').$nblines[2]; |
|
917 } else { |
|
918 $readfile = get_template_directory().$this->langfolder.$selectlang.'.mo'; |
|
919 $message .= ' '.$readfile.__('mo file is not present.','xili-dictionary'); |
|
920 } |
|
921 break; |
|
922 |
|
923 case 'importcats'; |
|
924 $actiontype = "importingcats"; |
|
925 $formtitle = __('Import terms of categories','xili-dictionary'); |
|
926 $formhow = __('To import terms of the current categories, click below.','xili-dictionary'); |
|
927 $submit_text = __('Import category’s terms »','xili-dictionary'); |
|
928 break; |
|
929 |
|
930 case 'importingcats'; |
|
931 $actiontype = "add"; |
|
932 $message .= ' '.__('terms imported from WP: ','xili-dictionary'); |
|
933 |
|
934 $catterms = $this->xili_read_catsterms(); |
|
935 |
|
936 if (is_array($catterms)) { |
|
937 $nbterms = $this->xili_importcatsterms_in_tables($catterms); |
|
938 $message .= __('names = ','xili-dictionary').$nbterms[0].' & ' .__('descs = ','xili-dictionary').$nbterms[1]; |
|
939 } else { |
|
940 $message .= ' '.$readfile.__('category’terms pbs!','xili-dictionary'); |
|
941 } |
|
942 break; |
|
943 case 'erasedictionary'; |
|
944 $actiontype = "erasingdictionary"; |
|
945 $formtitle = __('Erase all terms','xili-dictionary'); |
|
946 $formhow = __('To erase terms of the dictionary, click below. (before, create a .po if necessary!)'); |
|
947 $submit_text = __('Erase all terms »','xili-dictionary'); |
|
948 break; |
|
949 case 'erasingdictionary'; |
|
950 $actiontype = "add"; |
|
951 $message .= ' '.__('All terms erased !','xili-dictionary'); |
|
952 $listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false)); |
|
953 if (!empty($listdictiolines)) { |
|
954 foreach ($listdictiolines as $dictioline) { |
|
955 wp_delete_object_term_relationships( $dictioline->term_id, XDDICTLANGS ); |
|
956 wp_delete_term($dictioline->term_id, DTAXONAME, $args); |
|
957 } |
|
958 $dictioline = null; |
|
959 } |
|
960 break; |
|
961 case 'importcurthemeterms'; |
|
962 $actiontype = "importingcurthemeterms"; |
|
963 $formtitle = __('Import all terms from current theme','xili-dictionary'); |
|
964 $formhow = __('To import terms of the current theme, click below.','xili-dictionary'); |
|
965 $submit_text = __('Import all terms »','xili-dictionary'); |
|
966 |
|
967 $this->tempoutput = '<strong>'.__('List of scanned files:','xili-dictionary').'</strong><br />'; |
|
968 $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),2); |
|
969 $formhow = $this->tempoutput.'<br /><br /><strong>'.$formhow .'</strong>'; |
|
970 |
|
971 break; |
|
972 |
|
973 case 'importingcurthemeterms'; |
|
974 $actiontype = "add"; |
|
975 $message .= ' '.__('All terms imported !','xili-dictionary'); |
|
976 $themeterms = $this->scan_import_theme_terms(array(&$this,'build_scanned_files'),0); |
|
977 if (is_array($themeterms)) { |
|
978 $nbterms = $this->xili_importthemeterms_in_tables($themeterms); |
|
979 $message .= __('terms = ','xili-dictionary').$nbterms; |
|
980 } else { |
|
981 $message .= ' '.$readfile.__('theme’s terms pbs!','xili-dictionary'); |
|
982 } |
|
983 break; |
|
984 case 'reset'; |
|
985 $actiontype = "add"; |
|
986 break; |
|
987 default: |
|
988 $actiontype = "add"; |
|
989 $message .= ' '.__('Find above the list of terms.','xili-dictionary'); |
|
990 |
|
991 } |
|
992 /* register the main boxes always available */ |
|
993 |
|
994 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 */ |
|
996 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 */ |
|
998 |
|
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*/ |
|
1000 add_meta_box('xili-dictionary-normal-1', __($formtitle,'xili-dictionary'), array(&$this,'on_normal_2_content'), $this->thehook , 'normal', 'core'); /* input form */ |
|
1001 |
|
1002 |
|
1003 /* 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); |
|
1005 ?> |
|
1006 <div id="xili-dictionary-settings" class="wrap" style="min-width:850px"> |
|
1007 <?php screen_icon('tools'); ?> |
|
1008 <h2><?php _e('Dictionary','xili-dictionary') ?></h2> |
|
1009 <form name="add" id="add" method="post" action="tools.php?page=dictionary_page"> |
|
1010 <input type="hidden" name="action" value="<?php echo $actiontype ?>" /> |
|
1011 <?php wp_nonce_field('xili-dictionary-settings'); ?> |
|
1012 <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?> |
|
1013 <?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*/ ?> |
|
1015 <div id="poststuff" class="metabox-holder has-right-sidebar"> |
|
1016 <div id="side-info-column" class="inner-sidebar"> |
|
1017 <?php do_meta_boxes($this->thehook, 'side', $data); ?> |
|
1018 </div> |
|
1019 <div id="post-body" class="has-sidebar has-right-sidebar"> |
|
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> |
|
1029 </form> |
|
1030 </div> |
|
1031 <script type="text/javascript"> |
|
1032 //<![CDATA[ |
|
1033 jQuery(document).ready( function($) { |
|
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 |
|
1042 } |
|
1043 |
|
1044 /** * private function for admin page : select of parents */ |
|
1045 function xili_select_row($term_id=0,$editterm,$listby='name') { |
|
1046 // select all terms if current term is new |
|
1047 if ($term_id == 0) { |
|
1048 $listterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => '0')); |
|
1049 echo '<small>'.__('Choose the original term (msgid) to translate','xili-dictionary').'<br /></small>'; ?> |
|
1050 <select name="dictioline_parent" id="dictioline_parent" style="width:100%;"> |
|
1051 <option value="no_parent" ><?php _e('no parent (= msgid)','xili-dictionary'); ?></option> |
|
1052 <?php |
|
1053 foreach ($listterms as $curterm) { |
|
1054 echo '<option value="'.$curterm->term_id.'" >'.substr($curterm->slug,0,50).' ('.$curterm->term_id.') </option>'; |
|
1055 } |
|
1056 ?> |
|
1057 </select> |
|
1058 <br /> |
|
1059 <?php |
|
1060 } else { |
|
1061 |
|
1062 if ($editterm->parent == 0) { |
|
1063 $listterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => $term_id)); |
|
1064 // display childs |
|
1065 if (!empty($listterms)) { |
|
1066 echo '<small>'.__('translated as','xili-dictionary').": </small>"; |
|
1067 echo '<ul>'; |
|
1068 foreach ($listterms as $curterm) { |
|
1069 $edit = "<a href='?action=edit&page=dictionary_page&term_id=".$curterm->term_id."' >".__( 'Edit' )."</a>"; |
|
1070 echo '<li value="'.$curterm->term_id.'" >'.$this->display_singular_or_plural ($curterm->description, true).' <small>'.$edit.'</small></li>'; |
|
1071 } |
|
1072 echo '</ul>'; |
|
1073 } else { |
|
1074 echo __('not yet translated','xili-dictionary')."<br /><br />"; |
|
1075 } |
|
1076 } else { |
|
1077 echo '<small>'.__('translation of','xili-dictionary').": </small>"; |
|
1078 $edit = "<a href='?action=edit&page=dictionary_page&term_id=".$editterm->parent."' >".__( 'Edit' )."</a>"; |
|
1079 $parent_term = get_term($editterm->parent,DTAXONAME,OBJECT,'edit'); |
|
1080 echo $this->display_singular_or_plural ($parent_term->description, true).' <small>'.$edit.'</small>'; ?> |
|
1081 <input type="hidden" name="dictioline_parent" value="<?php echo $parent_term->term_id ?>" /> |
|
1082 <?php } |
|
1083 } |
|
1084 } |
|
1085 /** * private function for admin page : one line of taxonomy */ |
|
1086 |
|
1087 function xili_dict_row($listby='name',$tagsnamelike='',$tagsnamesearch='') { |
|
1088 global $default_lang; |
|
1089 /*list of dictiolines*/ |
|
1090 |
|
1091 if ($this->subselect == 'msgid' || $this->subselect == '') { |
|
1092 $parentselect = ''; |
|
1093 if ($this->subselect == 'msgid') $parentselect = '0'; |
|
1094 $listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false,'orderby' => $listby,'get'=>'all','name__like'=>$tagsnamelike,'search'=>$tagsnamesearch, 'parent'=>$parentselect)); |
|
1095 } else { |
|
1096 /* */ |
|
1097 $group = is_term($this->subselect,XDDICTLANGS); |
|
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)); |
|
1099 } |
|
1100 if (empty($listdictiolines) && $tagsnamelike=='' && $tagsnamesearch=='') : /*create a default line with the default language (as in config)*/ |
|
1101 $term = 'term'; |
|
1102 $args = array( 'alias_of' => '', 'description' => "term", 'parent' => 0, 'slug' =>''); |
|
1103 wp_insert_term( $term, DTAXONAME, $args); |
|
1104 $listdictiolines = get_terms(DTAXONAME, array('hide_empty' => false)); |
|
1105 endif; |
|
1106 if (empty($listdictiolines)) { |
|
1107 echo '<p>'.__('try another sub-selection !','xili-dictionary').'</p>'; |
|
1108 } else { |
|
1109 $subselect = (($tagsnamelike=='') ? '' : '&tagsnamelike='.$tagsnamelike); |
|
1110 $subselect .= (($tagsnamesearch=='') ? '' : '&tagsnamesearch='.$tagsnamesearch); |
|
1111 |
|
1112 foreach ($listdictiolines as $dictioline) { |
|
1113 |
|
1114 $class = (( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; |
|
1115 |
|
1116 $dictioline->count = number_format_i18n( $dictioline->count ); |
|
1117 $posts_count = ( $dictioline->count > 0 ) ? "<a href='edit.php?lang=$dictioline->term_id'>$dictioline->count</a>" : $dictioline->count; |
|
1118 |
|
1119 $edit = "<a href='?action=edit&page=dictionary_page".$subselect."&term_id=".$dictioline->term_id."' >".__( 'Edit' )."</a></td>"; |
|
1120 /* delete link */ |
|
1121 $edit .= "<td><a href='?action=delete&page=dictionary_page".$subselect."&term_id=".$dictioline->term_id."' class='delete'>".__( 'Delete' )."</a>"; |
|
1122 /* modify to allow all html tags in msg str or id - 0.9.8.2*/ |
|
1123 $line="<tr id='cat-$dictioline->term_id'$class> |
|
1124 <th scope='row' style='text-align: center'>$dictioline->term_id</th> |
|
1125 |
|
1126 <td>".$this->display_singular_or_plural($dictioline->description)."</td> |
|
1127 |
|
1128 <td>".$dictioline->slug."</td> |
|
1129 <td align='center'>$dictioline->term_group</td> |
|
1130 |
|
1131 <td>$edit</td>\n\t</tr>\n"; /*to complete*/ |
|
1132 echo $line; |
|
1133 } |
|
1134 } |
|
1135 } |
|
1136 function display_singular_or_plural ($msg, $onlyfirst = false) { |
|
1137 if (false === strpos($msg,XPLURAL)) { |
|
1138 return wp_filter_kses($msg); |
|
1139 } else { |
|
1140 $list = explode (XPLURAL,$msg); |
|
1141 if ($onlyfirst === false) { |
|
1142 $list = array_map('wp_filter_kses',$list); |
|
1143 return implode('<br />',$list); |
|
1144 } else { |
|
1145 return wp_filter_kses($list[0]); |
|
1146 } |
|
1147 } |
|
1148 } |
|
1149 /** |
|
1150 * Import PO file in class PO |
|
1151 * |
|
1152 * |
|
1153 * @since 1.0 - only WP >= 2.8.4 |
|
1154 */ |
|
1155 function pomo_import_PO ($lang = "") { |
|
1156 $po = new PO(); |
|
1157 $pofile = get_template_directory().$this->langfolder.$lang.'.po'; |
|
1158 if ( !$po->import_from_file( $pofile ) ) { |
|
1159 return false; |
|
1160 } else { |
|
1161 return $po; |
|
1162 } |
|
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 /** |
|
1185 * Import MO file in class PO |
|
1186 * |
|
1187 * |
|
1188 * @since 1.0.2 - only WP >= 2.8.4 |
|
1189 */ |
|
1190 function pomo_import_MO ($lang = "") { |
|
1191 $mo = new MO(); |
|
1192 $mofile = get_template_directory().$this->langfolder.$lang.'.mo'; |
|
1193 if ( !$mo->import_from_file( $mofile ) ) { |
|
1194 return false; |
|
1195 } else { |
|
1196 return $mo; |
|
1197 } |
|
1198 } |
|
1199 /** |
|
1200 * the MO object to twinlines (msgid - msgstr) for list |
|
1201 * |
|
1202 * |
|
1203 * @since 1.0.2 - only WP >= 2.8.4 |
|
1204 */ |
|
1205 function from_MO_to_twin ($mo) { |
|
1206 $twinlines = array(); |
|
1207 foreach ($mo->entries as $pomsgid => $pomsgstr) { |
|
1208 if ($pomsgstr->is_plural == null) { |
|
1209 $twinlines[$pomsgid] = $pomsgstr->translations[0]; |
|
1210 } else { |
|
1211 $keytwin = $pomsgstr->singular.XPLURAL.$pomsgstr->plural; |
|
1212 $twinlines[$keytwin] = implode (XPLURAL, $pomsgstr->translations); |
|
1213 } |
|
1214 |
|
1215 } |
|
1216 //print_r($twinlines); |
|
1217 return $twinlines; |
|
1218 } |
|
1219 |
|
1220 /** |
|
1221 * convert twinlines (msgid - msgstr) to MO |
|
1222 * |
|
1223 * |
|
1224 * @since 1.0 - only WP >= 2.8.4 |
|
1225 */ |
|
1226 function from_twin_to_POMO ($curlang, $obj='mo') { |
|
1227 global $user_identity,$user_url,$user_email; |
|
1228 if ($obj == 'mo') { |
|
1229 $mo = new MO(); /* par default */ |
|
1230 } else { |
|
1231 $mo = new PO(); |
|
1232 } |
|
1233 /* header */ |
|
1234 $translation =' |
|
1235 Project-Id-Version: theme: '.get_option("template").'\n |
|
1236 Report-Msgid-Bugs-To: contact@xiligroup.com\n |
|
1237 POT-Creation-Date: '.date("c").'\n |
|
1238 PO-Revision-Date: '.date("c").'\n |
|
1239 Last-Translator: '.$user_identity.' <'.$user_email.'>\n |
|
1240 Language-Team: xili-dictionary WP plugin and '.$user_url.' <'.$user_email.'>\n |
|
1241 MIME-Version: 1.0\n |
|
1242 Content-Type: text/plain; charset=utf-8\n |
|
1243 Content-Transfer-Encoding: 8bit\n |
|
1244 Plural-Forms: '.$this->plural_forms_rule($curlang).'\n |
|
1245 X-Poedit-Language: '.$curlang.'\n |
|
1246 X-Poedit-Country: '.$curlang.'\n |
|
1247 X-Poedit-SourceCharset: utf-8\n'; |
|
1248 |
|
1249 $mo->set_headers($mo->make_headers($translation)); |
|
1250 /* entries */ |
|
1251 $listterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => '')); //print_r($listterms); |
|
1252 foreach ($listterms as $curterm) { |
|
1253 if ($curterm->parent == 0) { |
|
1254 /* select child to create translated term */ |
|
1255 $listchildterms = get_terms(DTAXONAME, array('hide_empty' => false,'parent' => $curterm->term_id)); |
|
1256 $noentry = true; /* to create po with empty translation */ |
|
1257 foreach ($listchildterms as $curchildterm) { |
|
1258 if (substr($curchildterm->slug,-5) == strtolower($curlang)) { |
|
1259 if ($obj == 'mo') { |
|
1260 if (false === strpos($curterm->description,XPLURAL)) { |
|
1261 $mo->add_entry($mo->make_entry($curterm->description, $curchildterm->description)); |
|
1262 } else { |
|
1263 $msgidplural = explode(XPLURAL,$curterm->description); |
|
1264 $original = implode(chr(0),$msgidplural); |
|
1265 $msgstrplural = explode(XPLURAL,$curchildterm->description); |
|
1266 $translation = implode(chr(0),$msgstrplural); |
|
1267 |
|
1268 $mo->add_entry($mo->make_entry($original, $translation)); |
|
1269 } |
|
1270 } else { /* po */ |
|
1271 if (false === strpos($curterm->description,XPLURAL)) { |
|
1272 $entry = & new Translation_Entry(array('singular'=>$curterm->description,'translations'=> explode(XPLURAL, $curchildterm->description))); |
|
1273 } else { |
|
1274 $msgidplural = explode(XPLURAL,$curterm->description); |
|
1275 $msgstrplural = explode(XPLURAL,$curchildterm->description); |
|
1276 $entry = & new Translation_Entry(array('singular' => $msgidplural[0],'plural' => $msgidplural[1], 'is_plural' =>1, 'translations' => $msgstrplural)); |
|
1277 } |
|
1278 $mo->add_entry($entry); |
|
1279 $noentry = false; |
|
1280 } |
|
1281 } |
|
1282 } |
|
1283 /* to create po with empty translations */ |
|
1284 if ($obj == 'po' && $noentry == true) { |
|
1285 $entry = & new Translation_Entry(array('singular'=>$curterm->description,'translations'=> "")); |
|
1286 $mo->add_entry($entry); |
|
1287 } |
|
1288 } |
|
1289 } |
|
1290 //print_r ($mo); |
|
1291 return $mo; |
|
1292 } |
|
1293 |
|
1294 /** |
|
1295 * Save MO object to file |
|
1296 * |
|
1297 * |
|
1298 * @since 1.0 - only WP >= 2.8.4 |
|
1299 */ |
|
1300 function Save_MO_to_file ($curlang , $mo ) { |
|
1301 $filename = substr($curlang,0,3).strtoupper(substr($curlang,-2)); |
|
1302 $filename .= '.mo'; |
|
1303 $createfile = get_template_directory().$this->langfolder.$filename; |
|
1304 if (false === $mo->export_to_file($createfile)) return false; |
|
1305 } |
|
1306 |
|
1307 /** |
|
1308 * Save PO object to file |
|
1309 * |
|
1310 * |
|
1311 * @since 1.0 - only WP >= 2.8.4 |
|
1312 */ |
|
1313 function Save_PO_to_file ($curlang , $po ) { |
|
1314 $filename = substr($curlang,0,3).strtoupper(substr($curlang,-2)); |
|
1315 $filename .= '.po'; |
|
1316 $createfile = get_template_directory().$this->langfolder.$filename; |
|
1317 //print_r($po); |
|
1318 if (false === $po->export_to_file($createfile)) return false; |
|
1319 } |
|
1320 /** |
|
1321 * thanks to http://urbangiraffe.com/articles/translating-wordpress-themes-and-plugins/2/#plural_forms |
|
1322 * @since 1.0 - only WP >= 2.8 |
|
1323 */ |
|
1324 function plural_forms_rule($curlang) { |
|
1325 $curlang = substr($curlang,0,3).strtoupper(substr($curlang,-2)); |
|
1326 $rulesarrays = array( |
|
1327 'nplurals=1; plural=0' => array('tr_TR','ja_JA'), |
|
1328 'nplurals=2; plural=1' => array('zh_ZH'), |
|
1329 'nplurals=2; plural=n != 1' => array('en_US','en_UK','es_ES','da_DA'), |
|
1330 'nplurals=2; plural=n>1' => array('fr_FR','fr_CA','fr_BE','pt_BR'), |
|
1331 'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2' => array('lv_LV'), |
|
1332 'nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2' => array('gd_GD'), |
|
1333 'nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2' => array('lt_LT'), |
|
1334 'nplurals=3; plural=n%100/10==1 ? 2 : n%10==1 ? 0 : (n+9)%10>3 ? 2 : 1' => array('hr_HR','cs_CS','ru_RU','uk_UK'), |
|
1335 'nplurals=3; plural=(n==1) ? 1 : (n>=2 && n<=4) ? 2 : 0' => array('sk_SK'), |
|
1336 'nplurals=3; plural=n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2' => array('pl_PL'), |
|
1337 'nplurals=4; plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3' => array('sl_SL') |
|
1338 ); |
|
1339 foreach ($rulesarrays as $rule => $langs) { |
|
1340 if (in_array($curlang, $langs)) return $rule; |
|
1341 } |
|
1342 return 'nplurals=2; plural=n != 1'; /* english and most... */ |
|
1343 } |
|
1344 |
|
1345 /* |
|
1346 * import array of twintexts in terms tables |
|
1347 * |
|
1348 * @since 0.9.0 |
|
1349 * @updated 0.9.7 to set in langs group |
|
1350 * @updated 1.0.0 to manage plural |
|
1351 * |
|
1352 * @param array of msgid/msgstr, language (xx_XX) |
|
1353 * |
|
1354 */ |
|
1355 function xili_import_in_tables($twintexts=Array(),$translang) { |
|
1356 $nbline = 0; |
|
1357 $nbtline = 0; |
|
1358 foreach ($twintexts as $key => $line) { |
|
1359 |
|
1360 /* is content plural */ |
|
1361 if (false === strpos($key,XPLURAL)) { |
|
1362 $thekey = htmlentities($key); |
|
1363 } else { |
|
1364 $plurals = explode (XPLURAL,$key); |
|
1365 $thekey = htmlentities($plurals[0]); /* in term slug only first*/ |
|
1366 } |
|
1367 |
|
1368 // verify if origin msgid term exist |
|
1369 $cur_id = is_term($thekey, DTAXONAME); |
|
1370 if ($cur_id == 0) { |
|
1371 // create term |
|
1372 $args = array('description' => $key, 'slug'=>sanitize_title($thekey)); |
|
1373 $cur_id = is_term(sanitize_title($thekey),DTAXONAME); |
|
1374 if ($cur_id == 0) { |
|
1375 $result = $this->xili_dic_insert_term(htmlentities($thekey), DTAXONAME, $args); |
|
1376 $insertid = $result['term_id']; |
|
1377 $nbline++; |
|
1378 } else { |
|
1379 $insertid = $cur_id['term_id']; |
|
1380 } |
|
1381 $parent_term = get_term($insertid,DTAXONAME,OBJECT,'edit'); |
|
1382 |
|
1383 /* create the translated term */ |
|
1384 $sslug = $parent_term->slug.'_'.strtolower($translang); |
|
1385 $args = array('parent' => $parent_term->term_id, 'slug' => $sslug,'description' => $line); |
|
1386 $existing = get_term_by('slug', $sslug, DTAXONAME, OBJECT); |
|
1387 if ($existing == null && !is_wp_error($existing)) { /* perhaps in another lang */ |
|
1388 /* msgstr don't exist */ |
|
1389 /* is content plural */ |
|
1390 if (false === strpos($line,XPLURAL)) { |
|
1391 $theline = htmlentities($line); |
|
1392 } else { |
|
1393 $plurals = explode (XPLURAL,$line); |
|
1394 $theline = htmlentities($plurals[0]); /* in term slug only first*/ |
|
1395 } |
|
1396 |
|
1397 $result = $this->xili_dic_insert_term($theline, DTAXONAME, $args); |
|
1398 if (!is_wp_error($result)) wp_set_object_terms((int) $result['term_id'], strtolower($translang), XDDICTLANGS,false); |
|
1399 $nbtline++; |
|
1400 } else { |
|
1401 /* test slug of existing term */ |
|
1402 if ($line != $existing->description) { |
|
1403 $this->xili_dic_update_term($existing->term_id, DTAXONAME, $args); |
|
1404 $nbuline++; |
|
1405 } |
|
1406 } |
|
1407 } else { |
|
1408 /* echo msgid exist */ |
|
1409 $parent_term = get_term($cur_id['term_id'],DTAXONAME,OBJECT,'edit'); |
|
1410 |
|
1411 /* verify translated term msgstr */ |
|
1412 if (''!=$line) { |
|
1413 |
|
1414 $sslug = $parent_term->slug.'_'.strtolower($translang); |
|
1415 $args = array('parent' => $parent_term->term_id, 'slug' => $sslug, 'description' => $line); |
|
1416 $existing = get_term_by('slug', $sslug, DTAXONAME, OBJECT); |
|
1417 if ($existing == null && !is_wp_error($existing)) { |
|
1418 /* no term msgstr */ |
|
1419 /* is content plural */ |
|
1420 if (false === strpos($line,XPLURAL)) { |
|
1421 $theline = htmlentities($line); |
|
1422 } else { |
|
1423 $plurals = explode (XPLURAL,$line); |
|
1424 $theline = htmlentities($plurals[0]); /* in term slug only first*/ |
|
1425 } |
|
1426 $result = $this->xili_dic_insert_term($theline, DTAXONAME, $args); |
|
1427 if (!is_wp_error($result)) |
|
1428 wp_set_object_terms((int) $result['term_id'], strtolower($translang), XDDICTLANGS,false); |
|
1429 $nbtline++; |
|
1430 } else { |
|
1431 /* term exists */ |
|
1432 if ($line != $existing->description) { |
|
1433 $this->xili_dic_update_term($existing->term_id, DTAXONAME, $args); |
|
1434 $nbuline++; |
|
1435 } |
|
1436 } |
|
1437 } /* empty line */ |
|
1438 } /* parent exist */ |
|
1439 } /* loop */ |
|
1440 return array($nbline,$nbtline,$nbuline); //root id lines, translated lines and updated translated lines |
|
1441 } |
|
1442 |
|
1443 /* cat's terms in array (name - slug - description)*/ |
|
1444 function xili_read_catsterms(){ |
|
1445 $listcategories = get_terms('category', array('hide_empty' => false)); |
|
1446 foreach ($listcategories as $category) { |
|
1447 $catterms[] = Array($category->name,$category->description); |
|
1448 } |
|
1449 return $catterms; |
|
1450 } |
|
1451 /* array in tables */ |
|
1452 function xili_importcatsterms_in_tables($catterms= Array()){ |
|
1453 $nbname = 0; |
|
1454 $nbdesc = 0; |
|
1455 foreach ($catterms as $onecat) { |
|
1456 |
|
1457 $cur_id = is_term($onecat[0], DTAXONAME); |
|
1458 if ($cur_id == 0) { |
|
1459 |
|
1460 $args = array('description' => $onecat[0]); |
|
1461 $result = $this->xili_dic_insert_term( $onecat[0], DTAXONAME, $args); |
|
1462 $nbname++; |
|
1463 } |
|
1464 $cur_id = is_term(htmlentities($onecat[1]), DTAXONAME); |
|
1465 if ($cur_id == 0 && ""!=$onecat[1]) { |
|
1466 |
|
1467 $args = array('description' => $onecat[1]); |
|
1468 $result = $this->xili_dic_insert_term(htmlentities($onecat[1]), DTAXONAME, $args); |
|
1469 $nbdesc++; |
|
1470 } |
|
1471 } |
|
1472 return array($nbname,$nbdesc); |
|
1473 } |
|
1474 |
|
1475 |
|
1476 function scan_import_theme_terms($callback,$display) { |
|
1477 $path = get_template_directory(); |
|
1478 $themefiles = array(); |
|
1479 |
|
1480 $dir_handle = @opendir($path) or die("Unable to open $path"); |
|
1481 |
|
1482 while ($file = readdir($dir_handle)) { |
|
1483 |
|
1484 if (substr($file,0,1) == "_" || substr($file,0,1) == "." || substr($file,-4) != ".php") |
|
1485 continue; |
|
1486 |
|
1487 $themefiles[] = $file; |
|
1488 } |
|
1489 |
|
1490 |
|
1491 closedir($dir_handle); |
|
1492 |
|
1493 $resultterms = array(); |
|
1494 foreach ($themefiles as $themefile) { |
|
1495 |
|
1496 if( ! is_file( $path.'/'.$themefile) ) |
|
1497 { |
|
1498 $dualtexts = __('error'); |
|
1499 } elseif ($themefile != 'functions.php'){ |
|
1500 $lines = @file( $path.'/'.$themefile); |
|
1501 $t=0; |
|
1502 foreach ($lines as $line) { |
|
1503 $i = preg_match_all("/_[_e]\('(.*)', ?'/Ui", $line, $matches,PREG_PATTERN_ORDER); |
|
1504 if ($i > 0) { |
|
1505 $resultterms = array_merge ($resultterms, $matches[1]); |
|
1506 $t += $i; |
|
1507 } |
|
1508 } |
|
1509 if ($display >= 1) |
|
1510 call_user_func($callback, $themefile, $t); |
|
1511 } |
|
1512 } |
|
1513 if ($display == 2) |
|
1514 call_user_func($callback, $themefile, $t, $resultterms); |
|
1515 |
|
1516 return $resultterms; |
|
1517 } |
|
1518 function build_scanned_files ($themefile, $t, $resultterms = array()) { |
|
1519 if ($resultterms == array()) { |
|
1520 $this->tempoutput .= "- ".$themefile." (".$t.") "; |
|
1521 } else { |
|
1522 $this->tempoutput .= "<br /><strong>".__('List of found terms','xili-dictionary').": </strong><br />"; |
|
1523 $this->tempoutput .= implode (', ',$resultterms); |
|
1524 } |
|
1525 } |
|
1526 /* |
|
1527 * Import theme terms array in table |
|
1528 * |
|
1529 * |
|
1530 */ |
|
1531 function xili_importthemeterms_in_tables($themeterms= Array()){ |
|
1532 $nbname = 0; |
|
1533 |
|
1534 foreach ($themeterms as $onecat) { |
|
1535 |
|
1536 $cur_id = is_term($onecat, DTAXONAME); |
|
1537 if ($cur_id == 0) { |
|
1538 |
|
1539 $args = array('description' => $onecat); |
|
1540 $result = $this->xili_dic_insert_term(htmlentities($onecat), DTAXONAME, $args); |
|
1541 $nbname++; |
|
1542 } |
|
1543 } |
|
1544 return $nbname; |
|
1545 } |
|
1546 /** |
|
1547 * Recursive search of files in a path |
|
1548 * @since 1.0 |
|
1549 * |
|
1550 */ |
|
1551 function find_files($path, $pattern, $callback) { |
|
1552 //$path = rtrim(str_replace("\\", "/", $path), '/') . '/'; |
|
1553 $matches = Array(); |
|
1554 $entries = Array(); |
|
1555 $dir = dir($path); |
|
1556 while (false !== ($entry = $dir->read())) { |
|
1557 $entries[] = $entry; |
|
1558 } |
|
1559 $dir->close(); |
|
1560 foreach ($entries as $entry) { |
|
1561 $fullname = $path .$this->ossep. $entry; |
|
1562 if ($entry != '.' && $entry != '..' && is_dir($fullname)) { |
|
1563 $this->find_files($fullname, $pattern, $callback); |
|
1564 } else if (is_file($fullname) && preg_match($pattern, $entry)) { |
|
1565 call_user_func($callback, $path , $entry); |
|
1566 } |
|
1567 } |
|
1568 } |
|
1569 /** |
|
1570 * display lines of files in special sidebox |
|
1571 * @since 1.0 |
|
1572 */ |
|
1573 function available_mo_files($path , $filename) { |
|
1574 //echo $filename . " in : " . "/".str_replace("/","",str_replace(get_template_directory(),'',$path)) . "<br />"; |
|
1575 echo str_replace(".mo","",$filename ). " (".$this->ossep.str_replace($this->ossep,"",str_replace(get_template_directory(),'',$path)).")<br />"; |
|
1576 } |
|
1577 |
|
1578 } /* end of class */ |
|
1579 |
|
1580 /**** Functions that improve taxinomy.php ****/ |
|
1581 |
|
1582 /** |
|
1583 * get terms and add order in term's series that are in a taxonomy |
|
1584 * (not in class for general use) |
|
1585 * |
|
1586 * @since 0.9.8.2 - provided here if xili-tidy-tags plugin is not used |
|
1587 * |
|
1588 */ |
|
1589 if (!function_exists('get_terms_of_groups')) { |
|
1590 function get_terms_of_groups ($group_ids, $taxonomy, $taxonomy_child, $order = '') { |
|
1591 global $wpdb; |
|
1592 if ( !is_array($group_ids) ) |
|
1593 $group_ids = array($group_ids); |
|
1594 $group_ids = array_map('intval', $group_ids); |
|
1595 $group_ids = implode(', ', $group_ids); |
|
1596 $theorderby = ''; |
|
1597 $where = ''; |
|
1598 $defaults = array('orderby' => 'term_order', 'order' => 'ASC', |
|
1599 'hide_empty' => true, 'exclude' => '', 'exclude_tree' => '', 'include' => '', |
|
1600 'number' => '', 'slug' => '', 'parent' => '', |
|
1601 'name__like' => '', |
|
1602 'pad_counts' => false, 'offset' => '', 'search' => ''); |
|
1603 |
|
1604 if (is_array($order)) { |
|
1605 |
|
1606 $r = &$order; |
|
1607 $r = array_merge($defaults, $r); |
|
1608 extract($r); |
|
1609 |
|
1610 if ($order == 'ASC' || $order == 'DESC') { |
|
1611 if ('term_order'== $orderby) { |
|
1612 $theorderby = ' ORDER BY tr.'.$orderby.' '.$order ; |
|
1613 } elseif ('count'== $orderby || 'parent'== $orderby) { |
|
1614 $theorderby = ' ORDER BY tt2.'.$orderby.' '.$order ; |
|
1615 } elseif ('term_id'== $orderby || 'name'== $orderby) { |
|
1616 $theorderby = ' ORDER BY t.'.$orderby.' '.$order ; |
|
1617 } |
|
1618 } |
|
1619 |
|
1620 if ( !empty($name__like) ) |
|
1621 $where .= " AND t.name LIKE '{$name__like}%'"; |
|
1622 |
|
1623 if ( '' != $parent ) { |
|
1624 $parent = (int) $parent; |
|
1625 $where .= " AND tt2.parent = '$parent'"; |
|
1626 } |
|
1627 |
|
1628 if ( $hide_empty && !$hierarchical ) |
|
1629 $where .= ' AND tt2.count > 0'; |
|
1630 |
|
1631 if ( !empty($number) && '' == $parent ) { |
|
1632 if( $offset ) |
|
1633 $limit = ' LIMIT ' . $offset . ',' . $number; |
|
1634 else |
|
1635 $limit = ' LIMIT ' . $number; |
|
1636 |
|
1637 } else { |
|
1638 $limit = ''; |
|
1639 } |
|
1640 |
|
1641 if ( !empty($search) ) { |
|
1642 $search = like_escape($search); |
|
1643 $where .= " AND (t.name LIKE '%$search%')"; |
|
1644 } |
|
1645 |
|
1646 } else { |
|
1647 |
|
1648 if ($order == 'ASC' || $order == 'DESC') $theorderby = ' ORDER BY tr.term_order '.$order ; |
|
1649 } |
|
1650 $query = "SELECT t.*, tt2.term_taxonomy_id, tt2.description,tt2.parent, tt2.count, tt2.taxonomy, tr.term_order FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN $wpdb->terms AS t ON t.term_id = tr.object_id INNER JOIN $wpdb->term_taxonomy AS tt2 ON tt2.term_id = tr.object_id WHERE tt.taxonomy IN ('".$taxonomy."') AND tt2.taxonomy = '".$taxonomy_child."' AND tt.term_id IN (".$group_ids.") ".$where.$theorderby.$limit; |
|
1651 //echo $query; |
|
1652 $listterms = $wpdb->get_results($query); |
|
1653 if (!$listterms) |
|
1654 return array(); |
|
1655 return $listterms; |
|
1656 } |
|
1657 } |
|
1658 |
|
1659 /** |
|
1660 * instantiation when xili-language is loaded |
|
1661 */ |
|
1662 function dictionary_start () { |
|
1663 global $wp_version; |
|
1664 if ($wp_version >= '2.8') $xili_dictionary = new xili_dictionary(); /* instantiation php4 for last century servers replace by =& */ |
|
1665 } |
|
1666 add_action('plugins_loaded','dictionary_start'); |
|
1667 |
|
1668 /* © xiligroup dev 091108 10:00 */ |
|
1669 |
|
1670 ?> |