37 # |
43 # |
38 # You should have received a copy of the GNU Lesser General Public |
44 # You should have received a copy of the GNU Lesser General Public |
39 # License along with this plugin; if not, write to the Free Software |
45 # License along with this plugin; if not, write to the Free Software |
40 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
46 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
41 |
47 |
42 define('XILILANGUAGE_VER','1.4.1'); /* used in admin UI*/ |
48 |
|
49 define('XILILANGUAGE_VER','2.8.1'); /* used in admin UI*/ |
|
50 define('XILILANGUAGE_WP_VER','3.3'); /* used in error - see at end */ |
|
51 define('XILILANGUAGE_PHP_VER','5.0.0'); /* used in error - see at end */ |
|
52 define('XILILANGUAGE_PREV_VER','2.4.3'); |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 /********************* the CLASS **********************/ |
43 |
58 |
44 class xili_language { |
59 class xili_language { |
45 |
60 |
|
61 var $xili_settings; /* saved in options */ |
|
62 |
|
63 var $langs_group_id; /* group ID and Term Taxo ID */ |
|
64 var $langs_group_tt_id; |
|
65 |
46 var $default_lang; /* language of config.php*/ |
66 var $default_lang; /* language of config.php*/ |
|
67 var $default_slug; /* slug of language of config.php since 1.5.3 wpmu*/ |
47 var $curlang; |
68 var $curlang; |
|
69 |
|
70 var $thetextdomain = ""; /* since 1.5.2 - used if multiple */ |
48 var $langstate; /* undefined or not */ |
71 var $langstate; /* undefined or not */ |
|
72 |
49 var $browseroption = ''; |
73 var $browseroption = ''; |
|
74 var $lang_neither_browser = ''; // when neither match with browser |
50 var $authorbrowseroption = ''; |
75 var $authorbrowseroption = ''; |
51 var $functions_enable = ''; |
76 |
52 var $default_dir = ''; /* undefined or not in WP config '' or rtl or ltr */ |
77 var $default_dir = ''; /* undefined or not in WP config '' or rtl or ltr */ |
53 var $curlang_dir = ''; /* undefined or not according array */ |
78 var $curlang_dir = ''; /* undefined or not according array */ |
54 var $rtllanglist = 'ar-he-fa-ur'; /*default-list - can be set after class instantiation*/ |
79 var $rtllanglist = 'ar-he-fa-ur'; /* default-list - can be set after class instantiation */ |
55 var $post_ajax = false; /* ajax used in meta box in post edit UI unstable yet */ |
80 |
56 var $is_metabox = false; /* meta box in post edit UI - if used don't use custom fields that are not refreshed */ |
|
57 var $xili_settings; /* saved in options */ |
|
58 var $langs_group_id; /* group ID and Term Taxo ID */ |
|
59 var $langs_group_tt_id; |
|
60 var $get_archives_called = array(); /* if != '' - insert lang in link */ |
81 var $get_archives_called = array(); /* if != '' - insert lang in link */ |
61 var $idx = array(); /* used to identify filter or action set from this class - since 0.9.9.6 */ |
82 var $idx = array(); /* used to identify filter or action set from this class - since 0.9.9.6 */ |
62 var $theme_locale = false; /* to control locale hook */ |
83 var $theme_locale = false; /* to control locale hook */ |
63 var $ossep = "/"; /* for recursive file search in xamp */ |
84 var $ossep = "/"; /* for recursive file search in xamp */ |
|
85 |
64 var $current_lang_query_tag = ""; /* since 1.3.0 */ |
86 var $current_lang_query_tag = ""; /* since 1.3.0 */ |
65 var $temp_lang_query_tag = ""; |
87 var $temp_lang_query_tag = ""; |
66 |
88 |
67 function xili_language($metabox = false, $post_ajax = false, $locale_method = false) { |
89 var $domaindetectmsg = ""; // used if pb with load_theme_textdomain |
68 $this->is_metabox = $metabox; |
90 |
69 $this->post_ajax = $post_ajax; |
91 var $langs_list_options = array( array('','default'), array('typeone','Type #1'), array('typeonenew','Type for single'), array('navmenu', 'Nav Menu' ) , array('navmenu-1', 'Nav Menu Singular' ) ); // type of languages list see options in xili_language_list or navmenu |
|
92 |
|
93 var $comment_form_labels = array ( // since 1.6.0 for comment_form |
|
94 'name' => 'Name', |
|
95 'email' => 'Email', |
|
96 'website' => 'Website', |
|
97 'comment' => 'Comment', |
|
98 'youmustbe' => 'You must be <a href="%s">logged in</a> to post a comment.', |
|
99 'loggedinas' => 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', |
|
100 'emailnotpublished' => 'Your email address will not be published.', |
|
101 'requiredmarked' => ' Required fields are marked <span class="required">*</span>', |
|
102 'youmayuse' => 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:', |
|
103 'leavereply' => 'Leave a Reply', |
|
104 'replyto' => 'Leave a Reply to %s', |
|
105 'cancelreply' => 'Cancel reply', |
|
106 'postcomment' => 'Post Comment' |
|
107 ); |
|
108 |
|
109 var $sticky_keep_original = false ; // since 1.6.1 see translate_sticky_posts_ID function |
|
110 var $xl_recent_posts = false ; |
|
111 var $ltd = false ; // load_textdomain detected 1.8.5 |
|
112 var $arraydomains = array(); |
|
113 var $show = false ; |
|
114 |
|
115 var $langs_ids_array ; // array slug => id |
|
116 var $langs_slug_name_array ; // array slug => name // 2.4.2 |
|
117 var $langs_slug_fullname_array; // array slug => full name // 2.6.3 |
|
118 |
|
119 var $show_page_on_front = false; |
|
120 |
|
121 /* for permalink with lang at root */ |
|
122 var $lang_perma = false; // if true new permalink for root and categories /en_us/category/.... if special action available… 2.1.1 |
|
123 var $lpr = ''; // 2.3.2 |
|
124 var $show_page_on_front_array = array(); // array of lang=>page_id if show_on_front == page |
|
125 |
|
126 var $undefchar = "."; // 2.2.3 - used to detect undefined |
|
127 var $sublang = ""; // 2.2.3 - used to detect - or fr_fr- of like |
|
128 |
|
129 // 2.5 |
|
130 // other in class admin |
|
131 var $translation_state = '_xl_translation_state' ; // set to initial when post created from dashboard metabox (to update post slug) |
|
132 |
|
133 // 2.6 - class admin in separate file |
|
134 var $file_file = ''; // see in construct below |
|
135 var $file_basename = ''; |
|
136 var $plugin_basename = ''; |
|
137 var $plugin_url = ''; |
|
138 var $plugin_path = ''; // The path to this plugin - see construct |
|
139 |
|
140 var $xilidev_folder = '/xilidev-libraries'; //must be in plugins |
|
141 |
|
142 //since 2.7.1 - updated 2.8.0 |
|
143 var $examples_list = array(); |
|
144 |
|
145 /**** Construct is future ****/ |
|
146 |
|
147 public function __construct( $locale_method = false, $show = false, $class_admin = false ) { |
|
148 |
|
149 // 2.6 - class admin in separate file |
|
150 $this->file_file = __FILE__ ; // see in construct below |
|
151 $this->file_basename = basename(__FILE__) ; |
|
152 $this->plugin_basename = plugin_basename(__FILE__) ; |
|
153 $this->plugin_url = plugins_url('', __FILE__) ; |
|
154 $this->plugin_path = plugin_dir_path(__FILE__) ; |
|
155 |
70 $this->locale_method = $locale_method; /* added for compatibility with cache plugin from johan */ |
156 $this->locale_method = $locale_method; /* added for compatibility with cache plugin from johan */ |
71 /*activated when first activation of plug*/ |
157 $this->show = $show; |
|
158 $this->class_admin = $class_admin; |
|
159 /* activated when first activation of plug */ |
|
160 |
72 register_activation_hook(__FILE__,array(&$this,'xili_language_activate')); |
161 register_activation_hook(__FILE__,array(&$this,'xili_language_activate')); |
73 $this->ossep = strtoupper(substr(PHP_OS,0,3)=='WIN')?'\\':'/'; |
162 $this->ossep = strtoupper( substr(PHP_OS ,0 ,3 ) == 'WIN' ) ? '\\' : '/'; |
74 /*get current settings - name of taxonomy - name of query-tag - 0.9.8 new taxonomy taxolangsgroup */ |
163 |
75 $this->xili_settings = get_option('xili_language_settings'); |
164 |
76 if(empty($this->xili_settings)) { |
165 /** |
77 $submitted_settings = array( |
166 * get current settings |
|
167 */ |
|
168 $this->xili_settings = get_option('xili_language_settings'); |
|
169 if( false === $this->xili_settings ) { //1.9.1 |
|
170 $this->initial_settings (); |
|
171 update_option('xili_language_settings', $this->xili_settings); |
|
172 } else { |
|
173 if ($this->xili_settings['version'] == '1.9') { /* 2.4.0 */ |
|
174 $this->xili_settings['wp_locale'] = 'wp_locale'; //wp_locale new mode |
|
175 $this->xili_settings['version'] = '2.0'; |
|
176 update_option('xili_language_settings', $this->xili_settings); // |
|
177 } |
|
178 if ($this->xili_settings['version'] == '2.0') { /* 2.4.0 */ |
|
179 $this->xili_settings['available_langs'] = array(); // default array |
|
180 $this->xili_settings['version'] = '2.1'; |
|
181 update_option('xili_language_settings', $this->xili_settings); // |
|
182 } |
|
183 if ($this->xili_settings['version'] == '2.1') { /* 2.6.0 */ |
|
184 $this->xili_settings['external_xl_style'] = "on"; |
|
185 $this->xili_settings['creation_redirect'] = 'redirect'; // default - after initial creation |
|
186 $this->xili_settings['version'] = '2.2'; |
|
187 update_option('xili_language_settings', $this->xili_settings); // |
|
188 } |
|
189 |
|
190 if ( ! isset ( $this->xili_settings['version'] ) || $this->xili_settings['version'] != '2.2') { // repair or restart from new |
|
191 $this->initial_settings (); |
|
192 update_option('xili_language_settings', $this->xili_settings); |
|
193 } |
|
194 } |
|
195 if ( ! $class_admin ) { |
|
196 if ( ! defined( 'TAXONAME' ) ) define('TAXONAME', $this->xili_settings['taxonomy']); |
|
197 if ( ! defined( 'QUETAG' ) ) define('QUETAG', $this->xili_settings['reqtag']); // 'lang' |
|
198 if ( ! defined( 'TAXOLANGSGROUP' ) ) define('TAXOLANGSGROUP', $this->xili_settings['taxolangsgroup']); |
|
199 if ( ! defined( 'LANG_UNDEF' ) ) define('LANG_UNDEF', $this->xili_settings['lang_undefined']); //2.2.3 |
|
200 } |
|
201 |
|
202 $this->browseroption = $this->xili_settings['browseroption']; |
|
203 $this->lang_neither_browser = $this->xili_settings['lang_neither_browser']; // 2.3.1 |
|
204 $this->authorbrowseroption = $this->xili_settings['authorbrowseroption']; |
|
205 |
|
206 |
|
207 //$this->thetextdomain = $this->xili_settings['theme_domain']; /* since 1.5.2 */ |
|
208 $this->langsliststatus = $this->xili_settings['langs_list_status']; /* 1.6.0 */ |
|
209 |
|
210 /* detect research about permalinks */ |
|
211 |
|
212 //$this->lang_perma = ( has_filter ( 'term_link', 'insert_lang_4cat' ) ) ? true : false ; // 1.4.1 |
|
213 $this->show_page_on_front = ( 'page' == $this->get_option_wo_xili('show_on_front') ) ; |
|
214 |
|
215 if ( !$class_admin ) { // filtering only one time 2.6 |
|
216 add_action( 'init', array(&$this,'init_textdomain')); |
|
217 add_action( 'init', array(&$this,'init_and_register_language_post_taxonomy') ); |
|
218 } |
|
219 add_action( 'init', array(&$this,'init_vars') ); // moved here 2.8.0 |
|
220 |
|
221 if ( !$class_admin ) { // filtering only one time 2.6 |
|
222 |
|
223 add_action( 'init', array(&$this,'add_link_taxonomy'), 12 ); // 1.8.5 |
|
224 /* special to detect theme changing since 1.1.9 */ |
|
225 add_action( 'switch_theme', array(&$this,'theme_switched') ); |
|
226 |
|
227 /* query filters */ |
|
228 add_filter( 'posts_join', array(&$this,'posts_join_with_lang'), 10, 2 ); |
|
229 add_filter( 'posts_where', array(&$this,'posts_where_lang'), 10, 2 ); |
|
230 |
|
231 add_filter( 'posts_search', array(&$this,'posts_search_filter'), 10, 2 ); //2.2.3 |
|
232 add_action( 'pre_get_posts', array(&$this,'xiliml_modify_querytag') ); |
|
233 |
|
234 |
|
235 add_action( 'wp', array(&$this,'xiliml_language_wp') ); /// since 2.2.3 - wp_loaded - wp before |
|
236 /* 'wp' = where theme's language is defined just after query */ |
|
237 if ( $this->xili_settings['wp_locale'] == 'wp_locale' ) |
|
238 add_action( 'wp', array(&$this,'xili_locale_setup'), 15 ); // since 2.4 |
|
239 if ( $this->locale_method ) |
|
240 add_filter('locale', array(&$this,'xiliml_setlocale'), 10); |
|
241 /* to be compatible with l10n cache from Johan since 1.1.9 */ |
|
242 |
|
243 |
|
244 add_filter( 'widget_title', array(&$this,'one_text')); /* added 0.9.8.1 */ |
|
245 add_filter( 'widget_text', array(&$this,'one_text')); |
|
246 |
|
247 add_filter( 'list_cats', array(&$this,'xiliml_cat_language'), 10, 2 ); /* mode 2 : content = name */ |
|
248 add_filter( 'link_category', array(&$this,'one_text')); // 1.6.0 for wp_list_bookmarks (forgotten) |
|
249 add_filter( 'category_link', array(&$this,'xiliml_link_append_lang'), 10, 2 ); |
|
250 $filter = 'category_link'; |
|
251 $function = 'xiliml_link_append_lang'; |
|
252 $this->idx['xiliml_link_append_lang'] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), 10, 2); |
|
253 /* unique id of this filter from object fixed 1.0.1 */ |
|
254 add_filter( 'category_description',array(&$this,'xiliml_link_translate_desc')); |
|
255 add_filter( 'single_cat_title',array(&$this,'xiliml_single_cat_title_translate')); /* 1.4.1 wp_title() */ |
|
256 |
|
257 add_filter( 'tag_link', array(&$this,'xiliml_taglink_append_lang' )); |
|
258 |
|
259 add_filter( 'bloginfo', array(&$this,'xiliml_bloginfo'), 10, 2); /* since 1.6.0 - description - date - time */ |
|
260 |
|
261 /* filters for archives since 0.9.9.4 */ |
|
262 add_filter( 'getarchives_join', array(&$this, 'xiliml_getarchives_join'), 10, 2 ); |
|
263 add_filter( 'getarchives_where', array(&$this, 'xiliml_getarchives_where'), 10, 2 ); |
|
264 add_filter( 'get_archives_link', array(&$this, 'xiliml_get_archives_link') ); |
|
265 |
|
266 /* option modified */ |
|
267 add_filter( 'option_sticky_posts', array(&$this, 'translate_sticky_posts_ID') ); /* 1.6.1 */ |
|
268 |
|
269 add_filter( 'option_page_on_front', array(&$this, 'translate_page_on_front_ID') ); /* 1.7.0 */ |
|
270 $filter = 'option_page_on_front'; |
|
271 $function = 'translate_page_on_front_ID'; |
|
272 $this->idx['translate_page_on_front_ID'] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), 10, 2); |
|
273 |
|
274 /* bookmarks and widget_links 1.8.5 #2500 */ |
|
275 add_filter( 'widget_links_args', array( &$this, 'widget_links_args_and_lang' ), 10, 1 ); // in class WP_Widget_Links (default-widgets.php) |
|
276 add_filter( 'get_bookmarks', array( &$this, 'the_get_bookmarks_lang' ), 10, 2); // only active if 'lang' in wp_list_bookmarks() |
|
277 |
|
278 add_action( 'wp_head', array(&$this,'head_insert_language_metas'), 11 ); // © and options present in functions.php |
|
279 |
|
280 if ( !is_admin() ) { |
|
281 add_filter( 'the_category', array(&$this,'xl_get_the_category_list'), 10, 2); /* 1.7.0 */ |
|
282 add_filter( 'gettext', array(&$this,'change_plugin_domain'), 10, 3); /* 1.8.7 */ |
|
283 add_filter( 'gettext_with_context', array(&$this,'change_plugin_domain_with_context'), 10, 4); /* 1.8.8 */ |
|
284 add_filter( 'ngettext', array(&$this,'change_plugin_domain_plural'), 10, 5); |
|
285 add_filter( 'ngettext_with_context', array(&$this,'change_plugin_domain_plural_with_context'), 10, 6); |
|
286 |
|
287 // for wp nav menu |
|
288 add_filter('the_title', array(&$this,'wp_nav_title_text'),10,2); |
|
289 if ('' != $this->xili_settings['in_nav_menu']) |
|
290 add_filter('wp_nav_menu_items', 'xili_nav_lang_list',10,2); |
|
291 if ('' != $this->xili_settings['page_in_nav_menu']) |
|
292 add_filter('wp_nav_menu_items', 'xili_nav_page_list',9,2); // before lang's links - 1.7.1 |
|
293 if ('' != $this->xili_settings['home_item_nav_menu']) |
|
294 add_filter('walker_nav_menu_start_el', 'xili_nav_page_home_item',10,4); // add lang if - 1.8.9.2 |
|
295 |
|
296 add_filter( 'language_attributes', array(&$this,'head_language_attributes')); |
|
297 add_action( 'wp_head', array(&$this,'head_insert_hreflang_link' ), 10 ); // since 2.5 |
|
298 |
|
299 add_filter( 'option_date_format', array(&$this, 'translate_date_format') ); /* 1.7.0 */ |
|
300 |
|
301 add_filter( 'category_feed_link', array(&$this, 'category_feed_link') ); // 2.8.1 |
|
302 } |
|
303 |
|
304 // since 1.5.5 |
|
305 add_filter( 'comment_form_default_fields', array(&$this,'xili_comment_form_default_fields')); |
|
306 add_filter( 'comment_form_defaults', array(&$this,'xili_comment_form_defaults')); |
|
307 |
|
308 // since 2.4.0 for rtl.css |
|
309 add_filter( 'locale_stylesheet_uri', array(&$this, 'change_locale_stylesheet_uri' ),10, 2 ) ; |
|
310 |
|
311 // since 1.8.8 - activate xl widget series |
|
312 if ( $this->xili_settings['widget'] == 'enable' ) |
|
313 add_action( 'widgets_init', array(&$this,'add_new_widgets') ); |
|
314 |
|
315 /* new actions for xili-language theme's templates tags */ |
|
316 |
|
317 $this->add_action( 'xili_language_list', 'xili_language_list', 10, 5); /* add third param 0.9.7.4 - 4th 1.6.0*/ |
|
318 $this->add_action( 'xili_post_language', 'xili_post_language', 10, 2); |
|
319 |
|
320 $this->add_action( 'xiliml_the_other_posts', 'the_other_posts', 10, 4); /* add a param 1.1 */ |
|
321 $this->add_action( 'xiliml_the_category', 'the_category', 10, 3); |
|
322 $this->add_filter( 'xiliml_langinsearchform', 'xiliml_langinsearchform', 10, 3); // 1.8.2 action to filter |
|
323 |
|
324 // verify theme and set ltd for both parent and admin child |
|
325 add_filter( 'override_load_textdomain', array(&$this,'xiliml_override_load'), 10, 3); // since 1.5.0 |
|
326 add_filter( 'theme_locale', array(&$this,'xiliml_theme_locale'), 10, 2); // two times if is_admin() |
|
327 } |
|
328 } |
|
329 |
|
330 /** |
|
331 * first activation or empty settings |
|
332 */ |
|
333 function initial_settings () { |
|
334 $this->xili_settings = array( |
78 'taxonomy' => 'language', |
335 'taxonomy' => 'language', |
79 'version' => '0.4', |
336 'version' => '2.2', |
80 'reqtag' => 'lang', |
337 'reqtag' => 'lang', // query_var |
81 'browseroption' => '', |
338 'browseroption' => '', |
82 'authorbrowseroption' => '', |
339 'authorbrowseroption' => '', |
83 'taxolangsgroup' => 'languages_group', |
340 'taxolangsgroup' => 'languages_group', |
84 'functions_enable' => '', |
341 'functions_enable' => '', |
85 'langs_folder' => '', |
342 'langs_folder' => '', |
86 'theme_domain' => '', |
343 'theme_domain' => '', |
87 'homelang' => '' |
344 'homelang' => '', |
|
345 'langs_list_status' => '', |
|
346 'in_nav_menu' => '', |
|
347 'page_in_nav_menu' => '', |
|
348 'args_page_in_nav_menu' => '', |
|
349 'multilingual_custom_post' => array(), |
|
350 'langs_in_root_theme' => '', |
|
351 'domains' => array( 'all' => 'disable', 'default' => 'disable','bbpress' => 'disable' ), // no default domain to theme domain 1.8.7 |
|
352 'widget' => 'enable', |
|
353 'delete_settings' => '', //1.8.8 for uninstall |
|
354 'allcategories_lang' => 'browser', // 1.8.9.1 |
|
355 'lang_features' => array() , |
|
356 'home_item_nav_menu' => '', // 1.8.9.2 |
|
357 'lang_undefined' => $this->undefchar, //2.2.3 |
|
358 'lang_neither_browser' => '', // 2.3.1 |
|
359 'wp_locale' => 'wp_locale', // 2.7.1 new mode as default - 2.4.0 = old mode based on db strftime |
|
360 'available_langs' => array(), |
|
361 'creation_redirect' => 'redirect', // 2.6 to redirect to new post after creation |
|
362 'external_xl_style' => "on" // activate external xl-style.css - on by default :2.6.3 |
88 ); |
363 ); |
89 define('TAXONAME','language'); |
364 } |
90 define('QUETAG','lang'); |
365 |
91 define('TAXOLANGSGROUP','languages_group'); |
366 /* first activation of plugin */ |
92 update_option('xili_language_settings', $submitted_settings); |
367 function xili_language_activate() { |
93 $this->xili_settings = get_option('xili_language_settings'); |
368 $this->xili_settings = get_option('xili_language_settings'); |
94 } else { |
369 if( empty($this->xili_settings) ) { |
95 define('TAXONAME',$this->xili_settings['taxonomy']); |
370 $this->initial_settings (); |
96 define('QUETAG',$this->xili_settings['reqtag']); |
371 update_option('xili_language_settings', $this->xili_settings); |
97 $this->browseroption = $this->xili_settings['browseroption']; |
372 } |
98 $this->authorbrowseroption = $this->xili_settings['authorbrowseroption']; |
373 } |
99 $this->functions_enable = $this->xili_settings['functions_enable']; |
374 |
100 if ($this->xili_settings['version'] == '0.2' || $this->xili_settings['version'] == '0.3') { /* 1.3.2 */ |
375 function add_action ( $action, $function = '', $priority = 10, $accepted_args = 1 ) |
101 $this->xili_settings['taxolangsgroup'] = 'languages_group'; |
376 { |
102 $this->xili_settings['homelang'] = ''; |
377 add_action ($action, array (&$this, $function == '' ? $action : $function), $priority, $accepted_args); |
103 $this->xili_settings['version'] = '0.4'; |
378 $this->idx[$action] = _wp_filter_build_unique_id($action, array (&$this, $function == '' ? $action : $function), $priority); /* unique id of this filter from object */ |
104 update_option('xili_language_settings', $this->xili_settings); |
379 } |
105 } |
380 |
106 define('TAXOLANGSGROUP',$this->xili_settings['taxolangsgroup']); |
381 function add_filter ( $filter, $function = '', $priority = 10, $accepted_args = 1 ) |
107 } |
382 { |
108 define('XILIFUNCTIONSPATH',WP_PLUGIN_DIR.'/xilidev-libraries'); /* since 1.0 to add xili-libraries */ |
383 add_filter ($filter, array (&$this, $function == '' ? $filter : $function), $priority, $accepted_args); |
109 |
384 $this->idx[$filter] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), $priority); /* unique id of this filter from object fixed 1.0.1 */ |
|
385 } |
|
386 |
|
387 /** |
|
388 * for wpmu |
|
389 * register functions must be called by init |
|
390 * |
|
391 * @since 1.5.1 |
|
392 * |
|
393 */ |
|
394 function init_and_register_language_post_taxonomy () { |
110 /** add new taxonomy in available taxonomies |
395 /** add new taxonomy in available taxonomies |
111 * 1.0.2 - add label false as http://core.trac.wordpress.org/ticket/10437 |
396 * 1.0.2 - add label false as http://core.trac.wordpress.org/ticket/10437 |
112 * to avoid metabox as tag displayed |
397 * to avoid metabox as tag displayed , 'query_var' => QUETAG |
|
398 * @updated 1.4.1 |
113 */ |
399 */ |
114 register_taxonomy( TAXONAME, 'post',array('hierarchical' => false, 'label'=>false, 'rewrite' => false, 'update_count_callback' => array(&$this,'_update_post_lang_count'))); |
400 |
115 register_taxonomy( TAXOLANGSGROUP, 'term',array('hierarchical' => false, 'update_count_callback' => '')); |
401 if ( !$this->class_admin ) { |
116 $thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group')); |
402 if ( $this->xili_settings['wp_locale'] == 'wp_locale' ) |
117 if (!$thegroup) { /* update langs group 0.9.8 */ |
403 xiliml_declare_xl_wp_locale (); |
118 $args = array( 'alias_of' => '', 'description' => 'the group of languages', 'parent' => 0, 'slug' =>'the-langs-group'); |
404 |
119 wp_insert_term( 'the-langs-group', TAXOLANGSGROUP, $args); /* create and link to existing langs */ |
405 if ( $this->lang_perma ) { |
120 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
406 |
121 foreach($listlanguages as $language) { |
407 register_taxonomy( TAXONAME, 'post', array('hierarchical' => false, 'label' => false, 'rewrite' => false , 'update_count_callback' => array(&$this, '_update_post_lang_count'), 'show_ui' => false, '_builtin' => false, 'query_var' => QUETAG )); |
122 wp_set_object_terms($language->term_id, 'the-langs-group', TAXOLANGSGROUP); |
408 $this->lpr = "-"; // 2.3.2 |
123 } |
409 } else { |
124 $thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group')); |
410 add_filter('query_vars', array(&$this,'keywords_addQueryVar')); // now in taxonomy decl. // 2.1.1 |
125 } |
411 register_taxonomy( TAXONAME, 'post', array('hierarchical' => false, 'label' => false, 'rewrite' => false , 'update_count_callback' => array(&$this, '_update_post_lang_count'), 'show_ui' => false, '_builtin' => false )); |
126 $this->langs_group_id = $thegroup[0]->term_id; |
412 |
127 $this->langs_group_tt_id = $thegroup[0]->term_taxonomy_id; |
413 } |
128 |
414 |
|
415 register_taxonomy( TAXOLANGSGROUP, 'term', array('hierarchical' => false, 'update_count_callback' => '', 'show_ui' => false, 'label'=>false, 'rewrite' => false, '_builtin' => false )); |
|
416 } |
|
417 |
|
418 } |
|
419 |
|
420 /** |
|
421 * since 2.6 |
|
422 * |
|
423 */ |
|
424 function init_vars () { |
|
425 |
|
426 $this->examples_list = array( |
|
427 'af' => __('afrikaans','xili-language'), |
|
428 'ar_AR' => __('arabic', 'xili-language'), |
|
429 'be_BY' => __('belarusian', 'xili-language'), |
|
430 'bs_BA' => __('bosnian', 'xili-language'), |
|
431 'bg_BG' => __('bulgarian', 'xili-language'), |
|
432 'bn_BD' => __('bangla', 'xili-language'), |
|
433 'ca' => __('catalan', 'xili-language'), |
|
434 'cs_CZ' => __('czech', 'xili-language'), |
|
435 'cy' => __('welsh', 'xili-language'), |
|
436 'da_DK' => __('danish', 'xili-language'), |
|
437 'de_DE' => __('german', 'xili-language'), |
|
438 'el' => __('greek', 'xili-language'), |
|
439 'en_GB' => __('british english', 'xili-language'), |
|
440 'en_US' => __('english', 'xili-language'), |
|
441 'eo' => __('esperanto', 'xili-language'), |
|
442 'es_ES' => __('spanish', 'xili-language'), |
|
443 'es_CL' => __('chilean', 'xili-language'), |
|
444 'et' => __('estonian', 'xili-language'), |
|
445 'eu' => __('euskara', 'xili-language'), |
|
446 'fa_IR' => __('persian', 'xili-language'), |
|
447 'fi_FI' => __('finnish', 'xili-language'), |
|
448 'fo' => __('faroese', 'xili-language'), |
|
449 'fr_FR' => __('french', 'xili-language'), |
|
450 'ge_GE' => __('georgian', 'xili-language'), |
|
451 'gl_ES' => __('galician', 'xili-language'), |
|
452 'he_IL' => __('hebrew', 'xili-language'), |
|
453 'hr' => __('croatian', 'xili-language'), |
|
454 'hu_HU' => __('hungarian', 'xili-language'), |
|
455 'id_ID' => __('indonesian', 'xili-language'), |
|
456 'is_IS' => __('icelandic', 'xili-language'), |
|
457 'it_IT' => __('italian', 'xili-language'), |
|
458 'ja' => __('japanese', 'xili-language'), |
|
459 'km_KH' => __('khmer', 'xili-language'), |
|
460 'ko_KR' => __('korean', 'xili-language'), |
|
461 'lt_LT' => __('lithuanian', 'xili-language'), |
|
462 'lv' => __('latvian', 'xili-language'), |
|
463 'mg_MG' => __('malagasy', 'xili-language'), |
|
464 'mk_MK' => __('macedonian', 'xili-language'), |
|
465 'mn_MN' => __('mongolian', 'xili-language'), |
|
466 'ms_MY' => __('malay', 'xili-language'), |
|
467 'nb_NO' => __('norwegian', 'xili-language'), |
|
468 'ni_ID' => __('nias', 'xili-language'), |
|
469 'nl_NL' => __('dutch', 'xili-language'), |
|
470 'pl_PL' => __('polish', 'xili-language'), |
|
471 'pt_BR' => __('brazilian portuguese', 'xili-language'), |
|
472 'pt_PT' => __('portuguese', 'xili-language'), |
|
473 'ro_RO' => __('romanian', 'xili-language'), |
|
474 'ru_RU' => __('russian', 'xili-language'), |
|
475 'si_LK' => __('sinhala', 'xili-language'), |
|
476 'sk_SK' => __('slovak', 'xili-language'), |
|
477 'sl_SI' => __('slovenian', 'xili-language'), |
|
478 'sq_AL' => __('albanian', 'xili-language'), |
|
479 'sr_CS' => __('serbian', 'xili-language'), |
|
480 'sv_SE' => __('swedish', 'xili-language'), |
|
481 'su_ID' => __('sundanese', 'xili-language'), |
|
482 'tg' => __('tajik', 'xili-language'), |
|
483 'th' => __('thai', 'xili-language'), |
|
484 'tr' => __('turkish', 'xili-language'), |
|
485 'uk_UA' => __('ukrainian', 'xili-language'), |
|
486 'uz_UZ' => __('uzbek', 'xili-language'), |
|
487 'vi' => __('vietnamese', 'xili-language'), |
|
488 'zh_CN' => __('chinese', 'xili-language'), |
|
489 'zh_TW' => __('taiwan chinese', 'xili-language'), |
|
490 'zh_HK' => __('hong kong chinese', 'xili-language') |
|
491 ); |
129 /* default values */ |
492 /* default values */ |
130 if (''!= WPLANG && strlen(WPLANG)==5) : |
493 if ( ''!= WPLANG && ( strlen( WPLANG )==5 || strlen( WPLANG ) == 2 ) ) : // for japanese |
131 $this->default_lang = WPLANG; |
494 $this->default_lang = WPLANG; |
132 else: |
495 else: |
133 $this->default_lang = 'en_US'; |
496 $this->default_lang = 'en_US'; |
134 endif; |
497 endif; |
135 define('DEFAULTSLUG', $this->get_default_slug()); |
498 |
|
499 $thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group')); |
|
500 if ( array() == $thegroup ) { /* update langs group 0.9.8 and if from start 2.3.1 */ |
|
501 $args = array( 'alias_of' => '', 'description' => 'the group of languages', 'parent' => 0, 'slug' =>'the-langs-group'); |
|
502 wp_insert_term( 'the-langs-group', TAXOLANGSGROUP, $args); /* create and link to existing langs */ |
|
503 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false, 'get' => 'all')); |
|
504 if ( array() == $listlanguages ) { /*create two default lines with the default language (as in config)*/ |
|
505 /* language of WP */ |
|
506 |
|
507 $term = 'en_US'; |
|
508 $args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'en_us'); |
|
509 |
|
510 $theids = $this->safe_lang_term_creation ( $term, $args ); |
|
511 if ( ! is_wp_error($theids) ) { |
|
512 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
|
513 $this->xili_settings['lang_features']['en_us'] = array('charset'=>"",'hidden'=>""); |
|
514 } |
|
515 $term = $this->default_lang; |
|
516 $desc = ( isset($this->examples_list[$term]) ) ? $this->examples_list[$term] : $this->default_lang; |
|
517 $slug = strtolower( $this->default_lang ) ; // 2.3.1 |
|
518 if (!defined('WPLANG') || $this->default_lang == 'en_US' || $this->default_lang == '' ) { |
|
519 $term = 'fr_FR'; $desc = 'french'; $slug = 'fr_fr' ; |
|
520 } |
|
521 $args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug); |
|
522 |
|
523 $theids = $this->safe_lang_term_creation ( $term, $args ) ; |
|
524 if ( ! is_wp_error($theids) ) { |
|
525 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
|
526 $this->xili_settings['lang_features'][$slug] = array('charset'=>"",'hidden'=>""); |
|
527 } |
|
528 update_option('xili_language_settings', $this->xili_settings); |
|
529 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false, 'get' => 'all')); |
|
530 } |
|
531 foreach( $listlanguages as $language ) { |
|
532 wp_set_object_terms( $language->term_id, 'the-langs-group', TAXOLANGSGROUP ); |
|
533 } |
|
534 $thegroup = get_terms( TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group', 'get' => 'all') ); |
|
535 } |
|
536 |
|
537 if (function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 - 1.8.5 |
|
538 if ( $this->xili_settings['langs_in_root_theme'] == 'root' ) { |
|
539 $this->get_template_directory = get_template_directory(); |
|
540 } else { |
|
541 $this->get_template_directory = get_stylesheet_directory(); |
|
542 } |
|
543 } else { |
|
544 $this->get_template_directory = get_template_directory(); |
|
545 } |
|
546 |
|
547 $this->langs_group_id = $thegroup[0]->term_id; |
|
548 $this->langs_group_tt_id = $thegroup[0]->term_taxonomy_id; |
|
549 |
|
550 $this->get_lang_slug_ids(); // default array of languages slug=>id and slug=>name // 2.4.2 |
|
551 |
|
552 if ( $this->show_page_on_front ) $this->get_show_page_on_front_array(); |
|
553 /* here because taxonomy is registered : since 1.5.3 */ |
|
554 |
|
555 $this->default_slug = $this->get_default_slug(); /*no constant for wpmu */ |
|
556 if (!is_multisite() && !defined('DEFAULTSLUG')) define('DEFAULTSLUG',$this->default_slug); /* for backward compatibility */ |
|
557 |
|
558 |
136 if ( $dir = get_bloginfo('text_direction') ) /* if present in blog options @since 0.9.9 */ |
559 if ( $dir = get_bloginfo('text_direction') ) /* if present in blog options @since 0.9.9 */ |
137 $this->default_dir = $dir; |
560 $this->default_dir = $dir; |
138 |
561 |
139 add_filter('query_vars', array(&$this,'keywords_addQueryVar')); |
562 // 1.8.4 |
140 add_filter('posts_join', array(&$this,'with_lang')); |
563 if ( isset($this->xili_settings['available_langs']) && array() != $this->xili_settings['available_langs'] ) { |
141 add_filter('posts_where', array(&$this,'where_lang')); |
564 $this->available_langs = $this->xili_settings['available_langs']; |
142 |
565 } else { |
143 add_action('wp', array(&$this,'xiliml_language_wp')); |
566 $this->available_langs = $this->get_lang_ids() ; |
144 /* 'wp' = where theme's language is defined just after query */ |
567 $this->xili_settings['available_langs'] = $this->available_langs; |
145 if ($this->locale_method) |
568 update_option('xili_language_settings', $this->xili_settings); |
146 add_filter('locale', array(&$this,'xiliml_setlocale'), 10); |
569 } |
147 /* to be compatible with l10n cache from Johan since 1.1.9 */ |
570 |
148 add_filter('language_attributes', array(&$this,'head_language_attributes')); |
571 // 2.2.0 - add_roles - |
149 add_action('wp_head', array(&$this,'head_insert_language_metas'),10,2); |
572 |
150 |
573 if ( is_admin() ) { |
151 add_filter('widget_title', array(&$this,'widget_texts')); /* added 0.9.8.1 */ |
574 global $wp_roles; |
152 add_filter('widget_text', array(&$this,'widget_texts')); |
575 |
153 add_filter('list_cats', array(&$this,'xiliml_cat_language'),10,2); /* mode 2 : content = name */ |
576 if ( current_user_can ('activate_plugins') ) { |
154 |
577 $wp_roles->add_cap ('administrator', 'xili_language_set'); |
155 add_filter('category_link', array(&$this,'xiliml_link_append_lang')); |
578 $wp_roles->add_cap ('administrator', 'xili_language_menu'); |
156 $filter = 'category_link'; |
579 $wp_roles->add_cap ('administrator', 'xili_language_clone_tax'); |
157 $function = 'xiliml_link_append_lang'; |
580 } elseif ( current_user_can ('editor') ) { |
158 $this->idx['xiliml_link_append_lang'] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), 10); /* unique id of this filter from object fixed 1.0.1 */ |
581 $wp_roles->add_cap ('editor', 'xili_language_menu'); |
159 |
582 $wp_roles->add_cap ('editor', 'xili_language_clone_tax'); // able to clone taxonomy ('categeory') during propagate or create post |
160 add_filter('category_description',array(&$this,'xiliml_link_translate_desc')); |
583 } |
161 add_filter('single_cat_title',array(&$this,'xiliml_single_cat_title_translate')); /* 1.4.1 wp_title() */ |
584 } |
162 add_filter('tag_link', array(&$this,'xiliml_taglink_append_lang' )); |
585 } |
163 |
586 |
164 add_action('pre_get_posts', array(&$this,'xiliml_modify_querytag')); |
587 /** |
165 /* filters for archives since 0.9.9.4 */ |
588 * Safe language term creation |
166 add_filter('getarchives_join', array(&$this,'xiliml_getarchives_join'),10,2); |
589 * |
167 add_filter('getarchives_where', array(&$this,'xiliml_getarchives_where'),10,2); |
590 * @since 2.4.1 |
168 add_filter('get_archives_link', array(&$this,'xiliml_get_archives_link')); |
591 */ |
169 /* actions for post and page admin UI */ |
592 function safe_lang_term_creation ( $term, $args ) { |
170 add_action('save_post', array(&$this,'xili_language_add')); |
593 global $wpdb ; |
171 //add_action('publish_post', array(&$this,'xili_language_add')); /* only set when published !*/ |
594 // test if exists with other slug or name |
172 add_action('save_page', array(&$this,'xili_language_add')); |
595 if ( $term_id = term_exists( $term ) ) { |
173 //add_action('publish_page', array(&$this,'xili_language_add')); |
596 $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name, slug FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); |
174 if ($this->post_ajax) { |
597 if ( $existing_term['slug'] != $args['slug'] ) { |
175 add_action( 'wp_ajax_oklinked', array(&$this,'ok_linked') ); |
598 $res = wp_insert_term( $term.'xl', TAXONAME, $args); // temp insert with temp other name |
176 add_action( 'wp_ajax_customrefresh', array(&$this,'custom_refresh') ); |
599 $args['name'] = $term ; |
177 } |
600 $res = wp_update_term( $res['term_id'], TAXONAME, $args); |
178 /* admin settings UI*/ |
601 } else { |
179 add_action('init', array(&$this, 'init_textdomain')); |
602 return new WP_Error('term_exists', __('A term with the name provided already exists.'), $term_id ); |
180 add_filter('plugin_action_links', array(&$this,'xililang_filter_plugin_actions'), 10, 2); |
603 } |
181 |
604 } else { |
182 add_action('admin_menu', array(&$this,'myplugin_add_custom_box')); |
605 $res = wp_insert_term( $term, TAXONAME, $args); |
183 add_action('admin_menu', array(&$this,'xili_add_pages')); |
606 } |
184 /* special to detect theme changing since 1.1.9 */ |
607 if (is_wp_error($res)) { |
185 add_action('switch_theme', array(&$this,'theme_switched')); |
608 return $res ; |
186 /* inspired from custax */ |
609 } else { |
187 add_action('manage_posts_custom_column', array(&$this,'xili_manage_column'), 10, 2); |
610 $theids = $res; |
188 add_filter('manage_edit_columns', array(&$this,'xili_manage_column_name')); |
611 } |
189 |
612 return $theids ; |
190 add_action('manage_pages_custom_column', array(&$this,'xili_manage_column'), 10, 2); |
613 } |
191 add_filter('manage_edit-pages_columns', array(&$this,'xili_manage_column_name')); |
614 |
192 |
615 /** |
193 /* new actions for xili-language theme's templates tags */ |
616 * Get list language Objects - designed and used to avoid query by using settings |
194 |
617 * |
195 $this->add_action('xili_language_list','xili_language_list',10,3); /* add third param 0.9.7.4*/ |
618 * @since 1.6.0 |
196 $this->add_action('xili_post_language','xili_post_language',10,2); |
619 * @param $force to avoid buffer |
197 |
620 * @return array of objects |
198 $this->add_action('xiliml_the_other_posts','xiliml_the_other_posts',10,4); /* add a param 1.1 */ |
621 */ |
199 $this->add_action('xiliml_the_category','xiliml_the_category',10,3); |
622 function get_listlanguages( $force = false ) { |
200 $this->add_action('xiliml_langinsearchform','xiliml_langinsearchform',10,2); |
623 if ( $this->xili_settings['langs_list_status'] != "set" || $force === true ) { |
201 |
624 $listlanguages = get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); |
202 } |
625 if ( $listlanguages ) { |
203 |
626 $this->xili_settings['languages_list'] = $listlanguages; |
204 function add_action ($action, $function = '', $priority = 10, $accepted_args = 1) |
627 $this->xili_settings['langs_list_status'] = "set"; |
205 { |
628 if ( ! $this->class_admin ) { |
206 add_action ($action, array (&$this, $function == '' ? $action : $function), $priority, $accepted_args); |
629 update_option('xili_language_settings', $this->xili_settings); |
207 $this->idx[$action] = _wp_filter_build_unique_id($action, array (&$this, $function == '' ? $action : $function), $priority); /* unique id of this filter from object */ |
630 } |
208 } |
631 } |
209 |
632 return $listlanguages; |
210 function add_filter ($filter, $function = '', $priority = 10, $accepted_args = 1) |
633 } else { |
211 { |
634 return $this->xili_settings['languages_list']; |
212 add_filter ($filter, array (&$this, $function == '' ? $filter : $function), $priority, $accepted_args); |
635 } |
213 $this->idx[$filter] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), $priority); /* unique id of this filter from object fixed 1.0.1 */ |
636 } |
|
637 |
|
638 /** |
|
639 * Get list language IDs |
|
640 * |
|
641 * @since 1.8.4 |
|
642 */ |
|
643 function get_lang_ids() { |
|
644 |
|
645 $lang_ids = array() ; |
|
646 $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); |
|
647 foreach ( $listlanguages as $lang) { |
|
648 $lang_ids[] = $lang->term_id; |
|
649 } |
|
650 return $lang_ids ; |
|
651 } |
|
652 |
|
653 /** |
|
654 * Get list languages slug_IDs |
|
655 * |
|
656 * @since 2.1.1 |
|
657 */ |
|
658 function get_lang_slug_ids() { |
|
659 |
|
660 $lang_slugs = array() ; |
|
661 $lang_names = array() ; |
|
662 $lang_full_names = array() ; |
|
663 $listlanguages = $this->get_listlanguages( true ); |
|
664 foreach ( $listlanguages as $lang) { |
|
665 $key = $lang->slug; |
|
666 $lang_slugs[$key] = $lang->term_id; |
|
667 $lang_names[$key] = $lang->name; |
|
668 $lang_full_names[$key] = $lang->description; |
|
669 } |
|
670 $this->langs_ids_array = $lang_slugs; |
|
671 $this->langs_slug_name_array = $lang_names; |
|
672 $this->langs_slug_fullname_array = $lang_full_names; |
|
673 |
|
674 $this->xili_settings['langs_ids_array'] = $lang_slugs; |
|
675 if ( is_admin () && !$this->class_admin ) { |
|
676 update_option( 'xili_language_settings', $this->xili_settings ); |
|
677 |
|
678 }// if changing occurs... |
|
679 } |
|
680 |
|
681 /** |
|
682 * get show pages on front |
|
683 * |
|
684 * @since 2.1.1 |
|
685 * |
|
686 * |
|
687 * update $this->show_page_on_front_array array |
|
688 */ |
|
689 function get_show_page_on_front_array() { |
|
690 $front_pages_array = array(); |
|
691 $languages = $this->get_listlanguages( true ); |
|
692 $front_page_id = $this->get_option_wo_xili ('page_on_front'); |
|
693 foreach ( $languages as $lang) { |
|
694 $key = $lang->slug; |
|
695 $id = get_post_meta ( $front_page_id, QUETAG.'-'.$key, true ); |
|
696 $page_id = ( ''!= $id ) ? $id : $front_page_id ; |
|
697 $front_pages_array[$key] = $page_id; // |
|
698 } |
|
699 |
|
700 $this->show_page_on_front_array = $front_pages_array; |
|
701 $this->xili_settings['show_page_on_front_array'] = $front_pages_array; |
|
702 if ( is_admin () ) update_option( 'xili_language_settings', $this->xili_settings ); // if changing occurs... |
214 } |
703 } |
215 |
704 |
216 /** |
705 /** |
217 * More than one filter for the function. |
706 * More than one filter for the function. |
218 * |
707 * |
219 * @since 0.9.7 |
708 * @since 0.9.7 |
220 * |
709 * |
221 * @param $the_function (string). |
710 * @param $the_function (string). |
222 * @return true if more than one. |
711 * @return true if more than one. |
223 */ |
712 */ |
224 function this_has_filter($the_function) { |
713 function this_has_filter( $the_function ) { |
225 global $wp_filter; |
714 global $wp_filter; |
|
715 if ( !isset ( $wp_filter[$the_function]) ) return false; // avoid php warning 2.3.0 |
226 $has = $wp_filter[$the_function]; |
716 $has = $wp_filter[$the_function]; |
227 //print_r($has); |
717 |
|
718 if ( ! is_array( $has ) ) return false; // avoid php warning 2.1.0 |
228 $keys = array_keys($has); |
719 $keys = array_keys($has); |
229 //echo count($has[$keys[0]]); |
720 |
230 if (count($has[$keys[0]]) >= 2) { /*one from class others from functions.php or elsewhere*/ |
721 if (count($has[$keys[0]]) >= 2) { /*one from class others from functions.php or elsewhere*/ |
231 return true; |
722 return true; |
232 } else { |
723 } else { |
233 return false; |
724 return false; |
234 } |
725 } |
235 } |
726 } |
236 |
727 |
237 function myplugin_add_custom_box() { |
728 /** |
238 add_meta_box('xilil-2', __("Page's language",'xili-language'), array(&$this,'xili_language_checkboxes_n'), 'page', 'side','high'); |
729 * |
239 add_meta_box('xilil-2', __("Post's language",'xili-language'), array(&$this,'xili_language_checkboxes_n'), 'post', 'side','high'); |
730 * |
240 if ($this->is_metabox) { |
731 */ |
241 add_meta_box('xilil-1', __('Linked posts','xili-language'), array(&$this,'xili_language_linked_posts'), 'post', 'side','high'); |
732 function get_post_language ( $post_ID, $result = 'slug' ) { |
242 add_meta_box('xilil-1', __('Linked pages','xili-language'), array(&$this,'xili_language_linked_posts'), 'page', 'side','high'); |
733 $ress = wp_get_object_terms($post_ID, TAXONAME); |
243 } |
734 if ( $ress ) { |
|
735 $obj_term = $ress[0]; // today only one language per post |
|
736 |
|
737 switch ( $result ) { |
|
738 case 'iso': |
|
739 $postlang = ('' != $obj_term->name) ? $obj_term->name : ""; |
|
740 break; |
|
741 case 'name': |
|
742 $postlang = ('' != $obj_term->description) ? $obj_term->description : ""; |
|
743 break; |
|
744 default: // slug |
|
745 $postlang = ('' != $obj_term->slug) ? $obj_term->slug : ""; |
|
746 } |
|
747 } else { |
|
748 $postlang = ""; |
|
749 } |
|
750 return $postlang; |
|
751 } |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 /** |
|
757 * Create a linked copy of current post in target language |
|
758 * |
|
759 * @since 2.5 |
|
760 * |
|
761 */ |
|
762 function create_initial_translation ( $target_lang, $from_post_title = "" , $frompostlang = "", $from_post_ID ) { |
|
763 global $user_ID; |
|
764 |
|
765 $post_title_prefix = sprintf ( __('Please translate in %s:', 'xili-language' ), $target_lang ); |
|
766 $target_post_title = ( $from_post_title == '' ) ? $post_title_prefix . ' ' . $from_post_ID : $post_title_prefix . ' ' . $from_post_title ; |
|
767 |
|
768 $post_type = get_post_type( $from_post_ID ); |
|
769 |
|
770 $params = array('post_status' => 'draft', 'post_type' => $post_type, 'post_author' => $user_ID, |
|
771 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, |
|
772 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', |
|
773 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, |
|
774 'post_content' => $target_post_title, 'post_title' => $target_post_title); |
|
775 |
|
776 $post_ID = wp_insert_post( $params ) ; |
|
777 |
|
778 if ( $post_ID != 0 ) { |
|
779 // taxonomy |
|
780 wp_set_object_terms( $post_ID, $target_lang, TAXONAME ); |
|
781 // metas |
|
782 // from |
|
783 update_post_meta( $from_post_ID, QUETAG.'-'.$target_lang, $post_ID ); |
|
784 |
|
785 // this with other target of from |
|
786 $listlanguages = $this->get_listlanguages () ; |
|
787 foreach ( $listlanguages as $language ) { |
|
788 if ( $language->slug != $target_lang && $language->slug != $frompostlang ) { |
|
789 $id = get_post_meta( $from_post_ID, QUETAG.'-'.$language->slug, true ); |
|
790 if ( $id != "" ) { |
|
791 update_post_meta( $post_ID, QUETAG.'-'.$language->slug, $id ); |
|
792 } |
|
793 } |
|
794 } |
|
795 // this |
|
796 update_post_meta( $post_ID, QUETAG.'-'.$frompostlang, $from_post_ID ); |
|
797 update_post_meta( $post_ID, $this->translation_state, "initial" ); // to update further slug - post_name |
|
798 |
|
799 // categories of from_post |
|
800 $this->propagate_categories ( $from_post_ID, $post_ID ); |
|
801 return $post_ID; |
|
802 } |
|
803 } |
|
804 |
|
805 /** |
|
806 * propagate categories from a reference post to another (loop is in class admin) |
|
807 * if cat is not in target, cat will be unassigned in target if mode is 'erase' |
|
808 * |
|
809 * @since 2.6 |
|
810 * |
|
811 */ |
|
812 function propagate_categories ( $from_post_ID, $post_ID, $mode = '' ) { |
|
813 // categories of from_post |
|
814 // get |
|
815 $categories = get_the_category( $from_post_ID ); |
|
816 if ( ! empty( $categories ) ) { |
|
817 if ( is_object_in_taxonomy( get_post_type( $from_post_ID ), 'category' ) ) { |
|
818 // set |
|
819 $the_cats = array(); |
|
820 foreach ( $categories as $category ) { |
|
821 $the_cats[] = $category->slug; // wp_set_object_terms don't like loop |
|
822 } |
|
823 // prepare target (erase all) |
|
824 if ( $mode == 'erase' ) wp_delete_object_term_relationships ( $post_ID, 'category' ); |
|
825 wp_set_object_terms( $post_ID, $the_cats, 'category' ); |
|
826 } |
|
827 } |
|
828 } |
|
829 |
|
830 |
|
831 /** |
|
832 * return post object |
|
833 * |
|
834 * @since 2.5 |
|
835 * |
|
836 */ |
|
837 function temp_get_post ( $post_id ) { |
|
838 global $wpdb ; |
|
839 $res = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id)); |
|
840 if ( $res && !is_wp_error($res) ) |
|
841 return $res; |
|
842 else |
|
843 return false; |
|
844 } |
|
845 |
|
846 /** |
|
847 * return saved list of post_type and custom_post_type |
|
848 * |
|
849 * @since 2.5 |
|
850 * |
|
851 */ |
|
852 function authorized_custom_post_type () { |
|
853 |
|
854 $custompoststype = $this->xili_settings['multilingual_custom_post'] ; |
|
855 $custom = get_post_type_object ('post'); |
|
856 $clabels = $custom->labels; |
|
857 $custompoststype['post'] = array( 'name' => $custom->label , 'singular_name' => $clabels->singular_name , 'multilingual' => 'enable'); |
|
858 $custom = get_post_type_object ('page'); |
|
859 $clabels = $custom->labels; |
|
860 $custompoststype['page'] = array( 'name' => $custom->label, 'singular_name' => $clabels->singular_name , 'multilingual' => 'enable'); |
|
861 return $custompoststype; |
244 } |
862 } |
245 |
863 |
246 /** |
864 /** |
247 * Will update term count based on posts AND pages. |
865 * Will update term count based on posts AND pages. |
248 * |
866 * |
259 $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); |
877 $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); |
260 } |
878 } |
261 } |
879 } |
262 |
880 |
263 /** |
881 /** |
264 * set language when post or page is saved or changed |
|
265 * |
|
266 * @since 0.9.0 |
|
267 * @completed 0.9.7.1 to record postmeta of linked posts in other languages |
|
268 * @updated 0.9.7.5 to delete relationship when undefined |
|
269 * @updated 0.9.9 to avoid delete relationship when in quick_edit |
|
270 * @updated 1.3.0 to avoid delete relationship when trashing - 1.4.1 - create post-meta xl-search-linked |
|
271 * @param $post_ID |
|
272 */ |
|
273 function xili_language_add($post_ID) { |
|
274 if (!isset($_POST['_inline_edit'])) { /* to avoid delete relationship when in quick_edit (edit.php) */ |
|
275 $sellang = $_POST['xili_language_set']; |
|
276 if ("" != $sellang) { |
|
277 wp_set_object_terms($post_ID, $sellang, TAXONAME); |
|
278 } else { |
|
279 if ($_GET['action'] != 'trash' && $_GET['action'] != 'untrash') |
|
280 wp_delete_object_term_relationships( $post_ID, TAXONAME ); |
|
281 } |
|
282 if ($this->is_metabox) { |
|
283 /* the linked posts set by author */ |
|
284 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
|
285 foreach ($listlanguages as $language) { |
|
286 $inputid = 'xili_language_'.QUETAG.'-'.$language->slug ; |
|
287 $recinputid = 'xili_language_rec_'.QUETAG.'-'.$language->slug ; |
|
288 $linkid = $_POST[$inputid]; |
|
289 $reclinkid = $_POST[$recinputid]; /* hidden previous value */ |
|
290 $langslug = QUETAG.'-'.$language->slug ; |
|
291 |
|
292 if ($reclinkid != $linkid) { /* only if changed value or created since 1.3.0 */ |
|
293 if ((is_numeric($linkid) && $linkid == 0) || '' == $linkid ) { |
|
294 delete_post_meta($post_ID, $langslug); |
|
295 } elseif (is_numeric($linkid) && $linkid > 0) { |
|
296 update_post_meta($post_ID, $langslug, $linkid); |
|
297 if ($reclinkid == "-1") update_post_meta($linkid, QUETAG.'-'.$sellang, $post_ID); |
|
298 } |
|
299 } |
|
300 } |
|
301 //if (isset($_POST['xili_language_search_lang'])) { |
|
302 if ('' != $_POST['xili_language_search_lang']) { |
|
303 update_post_meta($post_ID, '_xl-search-linked', $_POST['xili_language_search_lang']); |
|
304 } else { |
|
305 if ($_GET['action'] != 'trash' && $_GET['action'] != 'untrash') |
|
306 delete_post_meta($post_ID, '_xl-search-linked'); |
|
307 } |
|
308 //} |
|
309 |
|
310 } |
|
311 } /* quick edit */ |
|
312 } |
|
313 |
|
314 /** |
|
315 * Return language dir |
882 * Return language dir |
316 * |
883 * |
317 * @since 0.9.9 |
884 * @since 0.9.9 |
318 * @param slug of lang |
885 * @param slug of lang |
319 */ |
886 */ |
320 function get_dir_of_cur_language($lang_slug) { |
887 function get_dir_of_cur_language( $lang_slug ) { |
321 $rtlarray = explode ('-',$this->rtllanglist); |
888 $rtlarray = explode ('-',$this->rtllanglist); |
322 $dir = (in_array(substr(strtolower($lang_slug),0,2),$rtlarray)) ? 'rtl' : 'ltr'; |
889 $dir = ( in_array(substr(strtolower($lang_slug), 0, 2 ),$rtlarray) ) ? 'rtl' : 'ltr'; |
323 return $dir; |
890 return $dir; |
324 } |
891 } |
|
892 |
|
893 /** |
|
894 * Insert rtl.css if exists (default filter of wp_head) - see theme.php (Thanks Sam R.) |
|
895 * |
|
896 * @since 2.4.0 |
|
897 */ |
|
898 function change_locale_stylesheet_uri ( $stylesheet_uri, $stylesheet_dir_uri ) { |
|
899 $rtlarray = explode ('-', $this->rtllanglist); |
|
900 $dir = ( in_array( substr( strtolower( $this->curlang ), 0, 2 ), $rtlarray ) ) ? 'rtl' : 'ltr'; |
|
901 $dircss = get_stylesheet_directory(); |
|
902 // avoid with locale.css |
|
903 if ( $stylesheet_uri == '' || false !== strpos($stylesheet_uri, 'rtl.css' ) || false !== strpos($stylesheet_uri, 'ltr.css' ) ) { |
|
904 if ( in_array ( substr( $this->curlang, 0, 2 ) , $rtlarray ) ) { |
|
905 |
|
906 if ( file_exists("$dircss/{$dir}.css") ) { |
|
907 return $stylesheet_dir_uri."/{$dir}.css"; |
|
908 } else { |
|
909 return ''; |
|
910 } |
|
911 |
|
912 } |
|
913 } |
|
914 return $stylesheet_uri ; // non filtered value |
|
915 } |
|
916 |
325 |
917 |
326 /** |
918 /** |
327 * Return language of post. |
919 * Return language of post. |
328 * |
920 * |
329 * @since 0.9.0 |
921 * @since 0.9.0 |
330 * @updated 0.9.7.6, 0.9.9 |
922 * @updated 0.9.7.6, 0.9.9 |
331 * |
923 * |
332 * @param $post_ID. |
924 * @param $post_ID. |
333 * @return slug of language of post or false if var langstate is false. |
925 * @return slug of language of post or false if var langstate is false. |
334 */ |
926 */ |
335 function get_cur_language($post_ID) { |
927 function get_cur_language( $post_ID ) { |
336 $ress = wp_get_object_terms($post_ID, TAXONAME); |
928 $ress = wp_get_object_terms($post_ID, TAXONAME); |
337 if ($ress) { |
929 if ($ress) { |
338 if (is_a($ress, 'WP_Error')){ |
930 if (is_a($ress, 'WP_Error')){ |
339 echo "Language table not created ! see plug-in admin"; |
931 echo "Language table not created ! see plug-in admin"; |
340 $this->langstate = false; |
932 $this->langstate = false; |
341 } else { |
933 } else { |
342 $obj_term = $ress[0]; |
934 $obj_term = $ress[0]; |
343 $this->langstate = true; |
935 $this->langstate = true; |
344 $postlang = $obj_term->slug; |
936 $postlang = $obj_term->slug; |
345 $postlangdir = $this->get_dir_of_cur_language($postlang); |
937 $postlangdir = $this->get_dir_of_cur_language($postlang); |
346 return array('lang'=>$postlang,'direction'=>$postlangdir); |
938 return array( QUETAG => $postlang, 'direction' => $postlangdir); |
347 } |
939 } |
348 } else { |
940 } else { |
349 $this->langstate = false; /* can be used in language attributes for header */ |
941 $this->langstate = false; /* can be used in language attributes for header */ |
350 return false; /* undefined state */ |
942 return false; /* undefined state */ |
351 } |
943 } |
352 } |
944 } |
353 |
945 |
354 /* first activation of plugin */ |
946 /** enable the new query tag associated with new taxonomy */ |
355 function xili_language_activate() { |
947 function keywords_addQueryVar( $vars ) { |
356 $this->xili_settings = get_option('xili_language_settings'); |
|
357 if(empty($this->xili_settings)) { |
|
358 $this->xili_settings = array( |
|
359 'taxonomy' => 'language', |
|
360 'version' => '0.4', |
|
361 'reqtag' => 'lang', |
|
362 'browseroption' => '', |
|
363 'authorbrowseroption' => '', |
|
364 'taxolangsgroup' => 'languages_group', |
|
365 'functions_enable' => '', |
|
366 'langs_folder' => '', |
|
367 'theme_domain' => '', |
|
368 'homelang' => '' |
|
369 ); |
|
370 update_option('xili_language_settings', $this->xili_settings); |
|
371 } |
|
372 } |
|
373 |
|
374 /*enable the new query tag associated with new taxonomy*/ |
|
375 function keywords_addQueryVar($vars) { |
|
376 $vars[] = QUETAG; |
948 $vars[] = QUETAG; |
377 return $vars ; |
949 return $vars ; |
378 } |
950 } |
379 |
951 |
380 function get_default_slug() { |
952 function get_default_slug() { |
381 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
953 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
382 $default_slug = 'en_us'; |
954 $default_slug = 'en_us'; |
383 foreach ($listlanguages as $language) { |
955 foreach ($listlanguages as $language) { |
384 if ($language->name == $this->default_lang ) return $language->slug; |
956 if ($language->name == $this->default_lang ) return $language->slug; |
385 } |
957 } |
386 return $default_slug ; |
958 return $default_slug ; |
387 } |
959 } |
388 |
960 |
389 /** |
961 /** |
390 * filters used when querytag is used - |
962 * Query join filter used when querytag is used or home |
391 * see below and functions.php where rules depend from theme |
963 * |
392 */ |
964 * @updated 1.7.0 modify page on front and home query |
393 function with_lang($join) { |
965 * @updated 1.8.4 * to select posts with undefined lang |
394 global $wp_query, $wpdb; |
966 * @updated 2.2.3 LANG_UNDEF = . and no * |
395 if ( '' != $wp_query->query_vars[QUETAG] ) { |
967 * |
396 $join .= " LEFT JOIN $wpdb->term_relationships as tr ON ($wpdb->posts.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) "; |
968 */ |
397 } |
969 function posts_join_with_lang( $join, $query_object = null ) { |
398 |
970 global $wpdb, $wp_query; |
399 return $join; |
971 |
400 } |
972 |
401 |
973 $insert_join = false ; |
402 /** |
974 if ( isset ( $query_object->query_vars[QUETAG] ) && '' != $query_object->query_vars[QUETAG] ) { |
403 * Setup global post data. |
975 if ( ( isset ( $query_object->query_vars['caller_get_posts'] ) && $query_object->query_vars['caller_get_posts']) || ( isset ( $query_object->query_vars['ignore_sticky_posts'] ) && $query_object->query_vars['ignore_sticky_posts']) ) { |
|
976 if ( isset ( $query_object->query_vars['xlrp'] ) && $query_object->query_vars['xlrp'] == 1 ) $insert_join = true ; // called by xili recent posts |
|
977 } else { |
|
978 $a = $query_object->query_vars['page_id']; |
|
979 $b = get_option('page_on_front'); |
|
980 |
|
981 if ( !($query_object->is_home && $this->show_page_on_front ) ) { // join if no front-page and other page |
|
982 if ( $a == $b && $a !='' ) { |
|
983 // 1.8.1 - two pages in results when language is selected at front !! |
|
984 // 1.8.4 - home as home + lang |
|
985 $insert_join = false ; |
|
986 } else { |
|
987 |
|
988 $insert_join = true ; // as in cat or home+lang |
|
989 } |
|
990 } elseif ( $query_object->is_home && !$this->show_page_on_front ) { // home and lang |
|
991 $insert_join = true ; |
|
992 } else { |
|
993 $insert_join = true ; |
|
994 } |
|
995 |
|
996 if ( $this->lang_perma ) { |
|
997 |
|
998 if ( $query_object->query_vars['category_name'] == "" && isset( $query_object->query_vars[QUETAG]) && $this->show_page_on_front && !is_admin()) { |
|
999 $join = ''; |
|
1000 $insert_join = false ; |
|
1001 unset($wp_query->queried_object); // to avoid notice in get_page_template and force get_queried_object -2.3.2 |
|
1002 } |
|
1003 if ( $query_object->is_tax && $query_object->query_vars['category_name'] != '' ) $insert_join = true ; |
|
1004 } |
|
1005 } |
|
1006 |
|
1007 } else { // join if home and modify home according rule ignore_sticky_posts |
|
1008 |
|
1009 if ( ''== $this->sublang ) { |
|
1010 if ( ( isset ( $query_object->query_vars['caller_get_posts'] ) && $query_object->query_vars['caller_get_posts']) || ( isset ( $query_object->query_vars['ignore_sticky_posts'] ) && $query_object->query_vars['ignore_sticky_posts']) ) { |
|
1011 if ( isset( $query_object->query_vars['xlrp'] ) && $query_object->query_vars['xlrp'] == 1 ) $insert_join = true ; // called by xili recent posts |
|
1012 |
|
1013 } else { |
|
1014 if ( ( $query_object->is_home && $this->xili_settings['homelang'] == 'modify') || $query_object->query_vars['ignore_sticky_posts']) { |
|
1015 |
|
1016 $insert_join = true ; //error_log ('************ join ************' . serialize ( $query_object->query_vars['post_type'])); |
|
1017 |
|
1018 } |
|
1019 } |
|
1020 } |
|
1021 } |
|
1022 |
|
1023 |
|
1024 if ( $insert_join ) { |
|
1025 $join .= " LEFT JOIN $wpdb->term_relationships as xtr ON ($wpdb->posts.ID = xtr.object_id) LEFT JOIN $wpdb->term_taxonomy as xtt ON (xtr.term_taxonomy_id = xtt.term_taxonomy_id) "; |
|
1026 } |
|
1027 return $join; |
|
1028 } |
|
1029 /** |
|
1030 * to detect undefined query and unset language tax query |
|
1031 * @since 2.2.3 - LANG_UNDEF |
|
1032 * |
|
1033 */ |
|
1034 |
|
1035 function posts_search_filter ( $search, $the_query) { |
|
1036 $this->sublang = ""; |
|
1037 |
|
1038 if ( isset( $the_query->query_vars[QUETAG] ) && false !== strpos( $the_query->query_vars[QUETAG] , LANG_UNDEF ) ) { |
|
1039 |
|
1040 |
|
1041 if ( array() != $the_query->tax_query->queries ) { |
|
1042 $new_queries = array(); |
|
1043 foreach ( $the_query->tax_query->queries as $query ) { |
|
1044 if ( $query['taxonomy'] != TAXONAME ) { |
|
1045 $new_queries[] = $query ; |
|
1046 } |
|
1047 } |
|
1048 $the_query->tax_query->queries = $new_queries; |
|
1049 } |
|
1050 $this->sublang = $the_query->query_vars[QUETAG]; // to adapt in where filter below |
|
1051 unset ( $the_query->query_vars[QUETAG] ); |
|
1052 unset ( $the_query->tax_query->relation ); |
|
1053 if ( array() == $the_query->tax_query->queries ) { |
|
1054 $the_query->is_tax = false ; |
|
1055 } |
|
1056 } |
|
1057 return $search; |
|
1058 } |
|
1059 |
|
1060 |
|
1061 /** |
|
1062 * Modify the query including lang or home |
404 * |
1063 * |
405 * @since 0.9.0 |
1064 * @since 0.9.0 |
406 * @updated 0.9.4 (OR added) lang=xx_xx,yy_yy,.. |
1065 * @updated 0.9.4 (OR added) lang=xx_xx,yy_yy,.. |
|
1066 * @updated 1.7.0 modify page on front and home query |
|
1067 * @updated 2.2.3 LANG_UNDEF |
407 * |
1068 * |
408 * @param object $where. |
1069 * @param object $where. |
409 * @return $where. |
1070 * @return $where. |
410 */ |
1071 */ |
411 function where_lang($where) { |
1072 function posts_where_lang( $where, $query_object = null ) { |
412 global $wp_query , $wpdb; |
1073 global $wpdb, $wp_query; |
413 $reqtags = array(); |
1074 $reqtags = array(); |
414 $thereqtags = array(); |
1075 $thereqtags = array(); |
415 if ( '' != $wp_query->query_vars[QUETAG] ) { |
1076 |
416 /* one or more lang - no + because only one lang per post now */ |
1077 |
417 if ( strpos($wp_query->query_vars[QUETAG], ',') !== false ) { |
1078 if ( "" != $this->sublang ) { // see above |
418 $langs = preg_split('/[,\s]+/', $wp_query->query_vars[QUETAG]); |
1079 |
419 foreach ( (array) $langs as $lang ) { |
1080 $lang = str_replace ( LANG_UNDEF, '' , $this->sublang ); //$query_object->query_vars[QUETAG] ) ; |
420 $lang = sanitize_term_field('slug', $lang, 0, 'post_tag', 'db'); |
1081 if ( "" == $lang ) { |
421 $reqtags[]= $lang; |
1082 $lang_string = implode( ", ", $this->available_langs ); |
|
1083 } else { |
|
1084 $id = $this->langs_ids_array[ $lang ]; |
|
1085 $remain = array_diff( $this->available_langs, array($id)); |
|
1086 $lang_string = implode( ", ", $remain ); |
|
1087 } |
|
1088 |
|
1089 $where .= " AND $wpdb->posts.ID NOT IN ( SELECT xtr.object_id FROM $wpdb->term_relationships AS xtr INNER JOIN $wpdb->term_taxonomy AS xtt ON xtr.term_taxonomy_id = xtt.term_taxonomy_id WHERE xtt.taxonomy = '".TAXONAME."' AND xtt.term_id IN ($lang_string) )"; |
|
1090 |
|
1091 } elseif ( isset ($query_object->query_vars[QUETAG]) && '' != $query_object->query_vars[QUETAG] ) { |
|
1092 |
|
1093 $do_it = false; |
|
1094 if ( (isset ( $query_object->query_vars['caller_get_posts'] ) && $query_object->query_vars['caller_get_posts']) || ( isset ( $query_object->query_vars['ignore_sticky_posts'] ) && $query_object->query_vars['ignore_sticky_posts']) ) { |
|
1095 |
|
1096 if ( isset ( $query_object->query_vars['xlrp'] ) && $query_object->query_vars['xlrp'] == 1) $do_it = true; |
|
1097 |
|
1098 } else { |
|
1099 |
|
1100 if ( $this->lang_perma && !is_admin ()) { |
|
1101 if ( $query_object->is_page && isset( $query_object->query_vars[QUETAG]) ) { |
|
1102 $do_it == false; |
|
1103 } elseif (!($query_object->is_home && $this->show_page_on_front )) { |
|
1104 |
|
1105 $do_it = true; |
|
1106 } |
|
1107 if ( $query_object->is_tax && $query_object->query_vars['taxonomy'] == 'category' ) { |
|
1108 $do_it = true; |
|
1109 } |
|
1110 if ( $query_object->is_tax && $query_object->query_vars['taxonomy'] == TAXONAME && "" == $query_object->query_vars['category_name'] ) { |
|
1111 $do_it = false; |
|
1112 if ( !$query_object->is_page ) { |
|
1113 $where .= " AND $wpdb->posts.post_type = 'post'"; |
|
1114 } |
|
1115 } |
|
1116 } else { |
|
1117 if ( !( $query_object->is_home && $this->show_page_on_front ) ) { |
|
1118 $do_it = true; // all but not home |
|
1119 } |
|
1120 } |
|
1121 } |
|
1122 |
|
1123 |
|
1124 if ($do_it) { // insertion of selection |
|
1125 |
|
1126 if ( strpos($query_object->query_vars[QUETAG], ',') !== false ) { |
|
1127 $langs = preg_split('/[,\s]+/', $query_object->query_vars[QUETAG]); |
|
1128 foreach ( (array) $langs as $lang ) { |
|
1129 $lang = sanitize_term_field('slug', $lang, 0, 'post_tag', 'db'); |
|
1130 $reqtags[]= $lang; |
|
1131 } |
|
1132 foreach ($reqtags as $reqtag){ |
|
1133 $thereqtagids[] = $this->langs_ids_array[$reqtag]; |
|
1134 } |
|
1135 $wherereqtag = implode(", ", $thereqtagids); |
|
1136 $where .= " AND xtt.taxonomy = '".TAXONAME."' "; |
|
1137 $where .= " AND xtt.term_id IN ( $wherereqtag )"; |
|
1138 |
|
1139 } else { |
|
1140 /* only one lang */ |
|
1141 $query_object->query_vars[QUETAG] = sanitize_term_field('slug', $query_object->query_vars[QUETAG], 0, 'post_tag', 'db'); |
|
1142 $reqtag = $query_object->query_vars[QUETAG]; |
|
1143 |
|
1144 $wherereqtag = $this->langs_ids_array[$reqtag]; |
|
1145 $where .= " AND xtt.taxonomy = '".TAXONAME."' "; |
|
1146 $where .= " AND xtt.term_id = $wherereqtag "; |
|
1147 } |
|
1148 |
|
1149 } else { // is_home and page |
|
1150 |
|
1151 if ( $query_object->is_home && $this->show_page_on_front ) { |
|
1152 $query_object->is_home = false ; // renew the values because the query contains lang= |
|
1153 $query_object->is_page = true ; |
|
1154 $query_object->is_singular = true ; |
|
1155 $query_object->query = array(); |
|
1156 $query_object->query_vars['page_id'] = get_option('page_on_front'); // new filtered value |
|
1157 //$query_object->query_vars['p'] = $query_object->query_vars['page_id']; |
|
1158 |
|
1159 $where = str_replace ("'post'","'page'",$where); // post_type = |
|
1160 $where .= " AND 3=3 AND {$wpdb->posts}.ID = " . $query_object->query_vars['page_id']; |
|
1161 |
422 } |
1162 } |
423 |
1163 |
424 foreach ($reqtags as $reqtag){ |
1164 if ( $this->lang_perma && $this->show_page_on_front) { // 2.1.1 |
425 $reqtagt = is_term( $reqtag, TAXONAME ); |
1165 if ( $query_object->query_vars[QUETAG] != "" && $query_object->query_vars['taxonomy'] == TAXONAME ) { |
426 if ($reqtagt) |
1166 $query_object->is_page = true ; |
427 $thereqtags[] = $reqtagt['term_id']; |
1167 $query_object->is_tax = false ; |
|
1168 $query_object->is_archive = false ; |
|
1169 $query_object->is_singular = true ; |
|
1170 |
|
1171 $query_object->query = array(); |
|
1172 $pid = $this->get_option_wo_xili ('page_on_front') ; |
|
1173 $lang = ( isset ( $query_object->query_vars[QUETAG] ) ? $query_object->query_vars[QUETAG] : 'en_us' ); |
|
1174 $id = get_post_meta ( $pid, QUETAG.'-'.$lang, true ); |
|
1175 $pagid = ( ''!= $id ) ? $id : $pid ; |
|
1176 $query_object->query_vars['page_id'] = $pagid ; |
|
1177 |
|
1178 unset ( $query_object->query_vars['taxonomy'] ); |
|
1179 |
|
1180 $where = str_replace ("'post'","'page'",$where); // post_type = |
|
1181 $where = "AND {$pagid} = {$pagid} "." AND {$wpdb->posts}.ID = " . $query_object->query_vars['page_id'] . " AND {$wpdb->posts}.post_type = 'page'"; |
|
1182 |
|
1183 $query_object->query_vars['page_id'] = get_option ('page_on_front') ; |
|
1184 //$query_object->query_vars['p'] = $query_object->query_vars['page_id']; |
|
1185 |
|
1186 unset($wp_query->queried_object); |
|
1187 $wp_query->queried_object_id = $query_object->query_vars['page_id']; |
|
1188 $wp_query->queried_object->ID = $query_object->query_vars['page_id']; |
|
1189 //$this->first_change = $lang ; |
|
1190 //update_option('xili_language_settings_test', $this->first_change); |
|
1191 } |
428 } |
1192 } |
|
1193 } |
|
1194 |
|
1195 |
|
1196 } else { // no query tag |
|
1197 //error_log ( "****** join ******" ); |
|
1198 if ( ( isset ( $query_object->query_vars['caller_get_posts'] ) && $query_object->query_vars['caller_get_posts']) || ( isset ( $query_object->query_vars['ignore_sticky_posts'] ) && $query_object->query_vars['ignore_sticky_posts']) ) { |
429 |
1199 |
430 $wherereqtag = implode(", ", $thereqtags); |
1200 if ( isset($query_object->query_vars['xlrp']) && $query_object->query_vars['xlrp'] == 1) { |
431 $where .= " AND tt.taxonomy = '".TAXONAME."' "; |
1201 $reqtag = $query_object->query_vars[QUETAG]; |
432 $where .= " AND tt.term_id IN ( $wherereqtag )"; |
1202 |
433 |
1203 $wherereqtag = $this->langs_ids_array[$reqtag]; |
|
1204 $where .= " AND xtt.taxonomy = '".TAXONAME."' "; |
|
1205 $where .= " AND xtt.term_id = $wherereqtag "; |
|
1206 |
|
1207 } |
|
1208 } else { //error_log ( "****** ici ******" . serialize ( $query_object->query_vars['post_type']) ); |
|
1209 if ( $query_object->is_home && !$this->show_page_on_front && $this->xili_settings['homelang'] == 'modify' ) { |
|
1210 |
|
1211 // force change if loop |
|
1212 $curlang = $this->choice_of_browsing_language(); |
|
1213 |
|
1214 $wherereqtag = $this->langs_ids_array[$curlang]; |
|
1215 $where .= " AND xtt.taxonomy = '".TAXONAME."' "; |
|
1216 $where .= " AND xtt.term_id = $wherereqtag "; |
|
1217 |
|
1218 } |
|
1219 } |
|
1220 } |
|
1221 //error_log ( "****** join ******".$where ); |
|
1222 return $where; |
|
1223 } |
|
1224 |
|
1225 /******** template theme live modifications ********/ |
|
1226 |
|
1227 /** |
|
1228 * wp action for theme at end of query |
|
1229 * |
|
1230 * @since 0.9.0 |
|
1231 * @updated 1.1.9, 1.4.2a |
|
1232 * call by wp hook |
|
1233 * |
|
1234 */ |
|
1235 function xiliml_language_wp() { |
|
1236 if ( !is_admin() ) { |
|
1237 $this->curlang = $this->get_curlang_action_wp(); // see hooks in that function |
|
1238 //$this->curlang = 'en_us'; |
|
1239 |
|
1240 $this->curlang_dir = $this->get_dir_of_cur_language( $this->curlang ); /* general dir of the theme */ |
|
1241 if ( $this->locale_method ) { |
|
1242 $this->xiliml_load_theme_textdomain ( $this->thetextdomain ); /* new method for cache compatibility - tests */ |
434 } else { |
1243 } else { |
435 /* only one lang */ |
1244 $this->set_mofile( $this->curlang ); |
436 $wp_query->query_vars[QUETAG] = sanitize_term_field('slug', $wp_query->query_vars[QUETAG], 0, 'post_tag', 'db'); |
1245 } |
437 $reqtag = $wp_query->query_vars[QUETAG]; |
1246 } |
438 $reqtag = is_term( $reqtag, TAXONAME ); |
1247 } |
439 if (''!= $reqtag) { |
1248 |
440 $wherereqtag = $reqtag['term_id']; |
1249 |
441 } else { |
1250 |
442 $wherereqtag = 0; |
1251 /** |
443 } |
1252 * wp action to switch wp_locale only on front-end |
444 $where .= " AND tt.taxonomy = '".TAXONAME."' "; |
1253 * |
445 $where .= " AND tt.term_id = $wherereqtag "; |
1254 * @since 2.4.0 |
446 } |
1255 * |
447 |
1256 * call by wp hook after theme cur_lang set |
448 } |
|
449 return $where; |
|
450 } |
|
451 |
|
452 /******** template theme live modifications ********/ |
|
453 |
|
454 /** |
|
455 * wp action for theme at end of query |
|
456 * |
|
457 * @since 0.9.0 |
|
458 * @updated 1.1.9 |
|
459 * can be hooked in functions.php xiliml_cur_lang_head |
|
460 * call by wp hook |
|
461 * |
1257 * |
462 */ |
1258 */ |
463 function xiliml_language_wp() { |
1259 function xili_locale_setup ( ) { |
464 $this->curlang = $this->xiliml_cur_lang_head(); |
1260 if ( !is_admin() ) { |
465 $this->curlang_dir = $this->get_dir_of_cur_language($this->curlang); /* general dir of the theme */ |
1261 unset($GLOBALS['wp_locale']); |
466 if (!defined('THEME_TEXTDOMAIN')) _e('xili-language plugin : THEME_TEXTDOMAIN UNDEFINED','xili-language'); /* here because not visible in admin UI */ |
1262 global $wp_locale; |
467 |
1263 $wp_locale = new xl_WP_Locale(); |
468 if ($this->locale_method) { |
1264 } |
469 $this->xiliml_load_theme_textdomain (THEME_TEXTDOMAIN); /* new method for cache compatibility - tests */ |
1265 } |
470 } else { |
1266 |
471 $this->set_mofile($this->curlang); |
1267 /** |
472 } |
1268 * only called in front-end |
|
1269 * |
|
1270 * @since 2.4.0 |
|
1271 * |
|
1272 */ |
|
1273 function translate_date_format ( $format ) { |
|
1274 if ( $this->xili_settings['wp_locale'] == 'wp_locale' ) |
|
1275 return __( $format , $this->thetextdomain ); |
|
1276 else |
|
1277 return $format; |
|
1278 } |
|
1279 |
|
1280 /** |
|
1281 * fixes feed link if not permalinks because called after category filter |
|
1282 * |
|
1283 * @since 2.8.1 |
|
1284 * |
|
1285 */ |
|
1286 function category_feed_link ( $link, $feed = '' ) { |
|
1287 $permalink_structure = get_option( 'permalink_structure' ); |
|
1288 |
|
1289 if ( '' != $permalink_structure ) { |
|
1290 if ( $feed == get_default_feed() ) |
|
1291 $feed_link = 'feed'; |
|
1292 else |
|
1293 $feed_link = "feed/$feed"; |
|
1294 // clean current link |
|
1295 $root_link = str_replace ( user_trailingslashit( $feed_link, 'feed' ), '', $link ); |
|
1296 // get part after ?lang= |
|
1297 $parts = explode ( '?'.QUETAG.'=', $root_link ); |
|
1298 if ( isset( $parts[1] ) ) { |
|
1299 // recreate current link |
|
1300 $link = trailingslashit( $parts[0] ) . user_trailingslashit( $feed_link, 'feed' ) . '?'.QUETAG.'='. str_replace ( '/','',$parts[1] ); |
|
1301 } |
|
1302 } |
|
1303 return $link; |
|
1304 |
|
1305 } |
|
1306 |
|
1307 /** |
|
1308 * 'theme_locale' filter to detect theme and don't load theme_domain in functions.php |
|
1309 * |
|
1310 * @since 1.5.0 |
|
1311 * |
|
1312 * call by 'theme_locale' filter |
|
1313 */ |
|
1314 function xiliml_theme_locale ( $locale, $domain ) { |
|
1315 $this->xili_settings['theme_domain'] = $domain; |
|
1316 $this->thetextdomain = $domain; |
|
1317 |
|
1318 //if ( defined ( "WP_DEBUG" ) && WP_DEBUG == true ) error_log ( $this->class_admin . ' < domain = ' . $domain ) ; |
|
1319 |
|
1320 return 'wx_YZ'; // dummy local |
|
1321 } |
|
1322 |
|
1323 /** |
|
1324 * 'override_load_textdomain' filter to avoid dummy load |
|
1325 * |
|
1326 * @since 1.5.0 |
|
1327 * @updated 1.8.1 - 1.8.5 |
|
1328 * |
|
1329 */ |
|
1330 function xiliml_override_load ( $falseval, $domain, $mofile ) { |
|
1331 if ( $this->show ) { |
|
1332 if ( !in_array( $domain , $this->arraydomains ) ) |
|
1333 $this->arraydomains[] = $domain; |
|
1334 } |
|
1335 if (false === strpos ($mofile ,'wx_YZ.mo')) {// |
|
1336 return false; |
|
1337 } else { |
|
1338 if ( str_replace( get_stylesheet_directory(), '', $mofile ) == $mofile ) { // no effect |
|
1339 $this->get_template_directory = get_template_directory(); |
|
1340 $this->xili_settings['langs_in_root_theme'] = 'root'; |
|
1341 } else { |
|
1342 $this->get_template_directory = get_stylesheet_directory(); // a load is in child |
|
1343 $this->xili_settings['langs_in_root_theme'] = ''; |
|
1344 |
|
1345 } |
|
1346 $this->ltd = true ; |
|
1347 |
|
1348 $langs_folder = str_replace('/wx_YZ.mo','',str_replace( $this->get_template_directory, '', $mofile )); |
|
1349 // in wp3 the detection is only done here (end user side by theme domain) so updated is mandatory for xili-dico |
|
1350 if ( $this->xili_settings['langs_folder'] != $langs_folder ) { |
|
1351 $this->xili_settings['langs_folder'] = $langs_folder ; |
|
1352 update_option( 'xili_language_settings', $this->xili_settings ); |
|
1353 } |
|
1354 // to restore theme mo if theme datas and terms in admin ui…. |
|
1355 if ( is_admin() ) load_textdomain( $domain, str_replace('wx_YZ', get_locale(), $mofile )); // 2.3.1 - 18h18 |
|
1356 return true; |
|
1357 |
|
1358 } |
|
1359 } |
|
1360 |
|
1361 /** |
|
1362 * |
|
1363 * Introduced only in visitors side (not in admin) to change domain of plugin or other |
|
1364 * gettext filter from function translate() in wp-includes/I10n.php |
|
1365 * |
|
1366 * @since 1.8.7 - 1.8.8 |
|
1367 */ |
|
1368 function change_plugin_domain ($translation, $text, $domain ) { |
|
1369 |
|
1370 $domain = $this->switching_domain ( $domain ); |
|
1371 |
|
1372 $translations = &get_translations_for_domain( $domain ); |
|
1373 return $translations->translate( $text ); |
|
1374 } |
|
1375 function change_plugin_domain_with_context ($translation, $text, $context, $domain ) { |
|
1376 |
|
1377 $domain = $this->switching_domain ( $domain ); |
|
1378 |
|
1379 $translations = &get_translations_for_domain( $domain ); |
|
1380 return $translations->translate( $text, $context ); |
|
1381 } |
|
1382 function change_plugin_domain_plural ($translation, $single, $plural, $number, $domain ) { |
|
1383 |
|
1384 $domain = $this->switching_domain ( $domain ); |
|
1385 |
|
1386 $translations = &get_translations_for_domain( $domain ); |
|
1387 $translation = $translations->translate_plural( $single, $plural, $number ); |
|
1388 return $translation ; |
|
1389 } |
|
1390 function change_plugin_domain_plural_with_context ($translation, $single, $plural, $number, $context, $domain ) { |
|
1391 |
|
1392 $domain = $this->switching_domain ( $domain ); |
|
1393 |
|
1394 $translations = &get_translations_for_domain( $domain ); |
|
1395 $translation = $translations->translate_plural( $single, $plural, $number, $context ); |
|
1396 return $translation ; |
|
1397 } |
|
1398 |
|
1399 /** |
|
1400 * domain switching |
|
1401 */ |
|
1402 function switching_domain ( $domain ) { |
|
1403 $ok = false ; |
|
1404 if ( $domain != $this->thetextdomain ) { |
|
1405 if ( in_array ( $domain, array_keys( $this->xili_settings['domains'] ) ) ) { |
|
1406 if ( $this->xili_settings['domains'][$domain] == 'enable' ) $ok = true ; |
|
1407 } else { |
|
1408 if ( $this->xili_settings['domains']['all'] == 'enable' ) $ok = true ; |
|
1409 } |
|
1410 if ( $ok ) |
|
1411 $domain = $this->thetextdomain ; |
|
1412 } |
|
1413 return $domain; |
473 } |
1414 } |
474 |
1415 |
475 /** |
1416 /** |
476 * locale hook when load_theme_textdomain is present in functions.php |
1417 * locale hook when load_theme_textdomain is present in functions.php |
477 * |
1418 * |
478 * @since 1.1.9 |
1419 * @since 1.1.9 |
479 * |
1420 * |
480 * call by locale hook |
1421 * call by locale hook |
481 */ |
1422 */ |
482 function xiliml_setlocale ($locale) { |
1423 function xiliml_setlocale ( $locale ) { |
483 if ($this->theme_locale === true) { |
1424 if ($this->theme_locale === true) { |
484 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $this->curlang)); |
1425 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $this->curlang)); |
485 return $listlanguages[0]->name; |
1426 return $listlanguages[0]->name; |
486 } else { |
1427 } else { |
487 return $locale; |
1428 return $locale; |
926 if (str_replace('-','_',$browserlanguage) == substr($sitelanguage->slug,0,2)) return $sitelanguage; |
2117 if (str_replace('-','_',$browserlanguage) == substr($sitelanguage->slug,0,2)) return $sitelanguage; |
927 } |
2118 } |
928 } |
2119 } |
929 } |
2120 } |
930 |
2121 |
931 /********************************** ADMIN UI ***********************************/ |
2122 /** |
932 |
2123 * Choice of language when is_category and all languages |
933 /** |
2124 * |
934 * add admin menu and associated pages of admin UI |
2125 * @since 1.8.9.1 |
935 * |
2126 * called by get_curlang_action_wp |
936 * @since 0.9.0 |
2127 * |
937 * @updated 0.9.6 - only for WP 2.7.X - do registering of new meta boxes and JS |
2128 */ |
938 * |
2129 function choice_of_categories_all_languages( $curlang ) { |
939 */ |
2130 $choice = $this->xili_settings['allcategories_lang']; |
940 function xili_add_pages() { |
2131 if ( $choice == "browser" ) { |
941 $this->thehook = add_options_page(__('Languages','xili-language'), __('Languages','xili-language'), 'manage_options', 'language_page', array(&$this,'languages_settings')); |
2132 return $this->choice_of_browsing_language(); |
942 add_action('load-'.$this->thehook, array(&$this,'on_load_page')); |
2133 } elseif ( $choice == "firstpost" ) { |
943 } |
2134 return $curlang ; |
944 |
2135 } elseif ( $choice == "" ) { |
945 function on_load_page() { |
2136 if ( function_exists('xl_choice_of_categories_all_languages') ) { |
946 wp_enqueue_script('common'); |
2137 return xl_choice_of_categories_all_languages () ; |
947 wp_enqueue_script('wp-lists'); |
2138 } else { |
948 wp_enqueue_script('postbox'); |
2139 return ''; // return without mo |
949 add_meta_box('xili-language-sidebox-1', __('Message','xili-language'), array(&$this,'on_sidebox_1_content'), $this->thehook , 'side', 'core'); |
2140 } |
950 add_meta_box('xili-language-sidebox-2', __('Info','xili-language'), array(&$this,'on_sidebox_2_content'), $this->thehook , 'side', 'core'); |
2141 } |
951 add_meta_box('xili-language-sidebox-4', __('Special','xili-language'), array(&$this,'on_sidebox_4_content'), $this->thehook , 'side', 'core'); |
2142 return $choice; |
952 |
2143 } |
953 } |
2144 |
954 |
2145 /** |
955 /** |
2146 * to encapsulate future method |
956 * Add action link(s) to plugins page |
2147 * |
957 * |
2148 * @since 1.8.9.1 |
958 * @since 0.9.3 |
2149 * @param post_ID and lang slug |
959 * @author MS |
2150 */ |
960 * @copyright Dion Hulse, http://dd32.id.au/wordpress-plugins/?configure-link and scripts@schloebe.de |
2151 function linked_post_in ( $fromID, $lang_slug ) { |
961 */ |
2152 return get_post_meta( $fromID, QUETAG.'-'.$lang_slug, true ); // will be soon changed |
962 function xililang_filter_plugin_actions($links, $file){ |
2153 } |
963 static $this_plugin; |
2154 |
964 if( !$this_plugin ) $this_plugin = plugin_basename(__FILE__); |
2155 /** |
965 if( $file == $this_plugin ){ |
2156 * if possible, translate the array of ID of sticky posts |
966 $settings_link = '<a href="options-general.php?page=language_page">' . __('Settings') . '</a>'; |
2157 * |
967 $links = array_merge( array($settings_link), $links); // before other links |
2158 * @since 1.6.1 |
968 } |
2159 * called by hook option_sticky_posts |
969 return $links; |
2160 * @updated 2.8.1 |
970 } |
2161 */ |
971 |
2162 function translate_sticky_posts_ID( $original_array ) { |
972 /* UI added in sidebar of post admin (write , edit) |
2163 global $wp_query ; |
973 * |
2164 if ( !is_admin() && is_home() ) { // because impossible to register the value in admin UI - |
974 * @since 0.9.0 |
2165 // and because tracs http://core.trac.wordpress.org/ticket/14115 |
975 * @updated 0.9.5 : add a no-lang radio - again in top of sidebar admin post's UI |
2166 if ($original_array != array()) { |
976 * @updated 0.9.8.3 : if new post and checked in settings : default language = author's browser's language ! |
2167 $translated_array = array(); |
977 * @updated 1.3.0 |
2168 if ( isset( $wp_query->query_vars[QUETAG] )) { //if (isset($_GET[QUETAG])) { // $_GET not usable by lang perma mode 2.8.1 |
978 */ |
2169 $curlang = $wp_query->query_vars[QUETAG]; // $_GET[QUETAG]; |
979 function xili_language_checkboxes_n() { |
|
980 global $post_ID ; |
|
981 //$listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
|
982 $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); |
|
983 if ($this->authorbrowseroption == 'authorbrowser') { // setting = select language of author's browser |
|
984 $listofprefs = $this->the_preferred_languages(); |
|
985 if (is_array($listofprefs)) { |
|
986 arsort($listofprefs, SORT_NUMERIC); |
|
987 $sitelanguage = $this->match_languages ($listofprefs,$listlanguages); |
|
988 if ($sitelanguage) { |
|
989 $defaultlanguage = $sitelanguage->name; |
|
990 } else { |
2170 } else { |
991 $defaultlanguage = ""; |
2171 $curlang = $this->choice_of_browsing_language(); // rule defined in admin UI |
992 } |
2172 } |
993 $mention = '('.__('Browser language', 'xili-language').')'; |
2173 foreach ($original_array as $id) { |
|
2174 $langpost = $this->get_cur_language($id); |
|
2175 $post_lang = $langpost[QUETAG]; |
|
2176 if ($post_lang != $curlang) { // only if necessary |
|
2177 $trans_id = $this-> linked_post_in( $id, $curlang ) ; // get_post_meta($id, 'lang-'.$curlang, true); |
|
2178 if ( '' != $trans_id ) { |
|
2179 $translated_array[] = $trans_id; |
|
2180 } else { |
|
2181 if ( $this->sticky_keep_original === true ) $translated_array[] = $id; |
|
2182 // set by webmaster in theme functions |
|
2183 |
|
2184 } |
|
2185 } else { |
|
2186 $translated_array[] = $id; |
|
2187 } |
|
2188 } |
|
2189 return $translated_array; |
994 } else { |
2190 } else { |
995 $defaultlanguage = ""; /* undefined */ |
2191 return $original_array; |
996 } |
2192 } |
997 } else { |
2193 } else { |
998 $defaultlanguage = ""; /* undefined */ |
2194 return $original_array; |
999 $mention = ""; |
2195 } |
1000 } |
2196 } |
1001 |
2197 |
1002 if(0 != $post_ID){ |
2198 /** |
1003 $ress = wp_get_object_terms($post_ID, TAXONAME); |
2199 * cancel default filtering when page on front |
1004 |
2200 * |
1005 /*Array ( [0] => stdClass Object ( [term_id] => 18 [name] => [slug] => 18 [term_group] => 0 [term_taxonomy_id] => 19 [taxonomy] => language [description] => [parent] => 0 [count] => 1 ) )*/ |
2201 * |
1006 $obj_term = $ress[0]; |
2202 * @updated 2.6.3 |
1007 if ('' != $obj_term->name) : |
2203 */ |
1008 $curlangname = $obj_term->name; |
2204 function get_option_wo_xili ( $option ) { |
1009 else : |
2205 if ( $option == 'page_on_front' && isset( $this->idx['translate_page_on_front_ID'] ) ) { // 2.6.3 |
1010 $curlangname = ""; /* when created before plugin */ |
2206 remove_filter ( 'option_'.$option, $this->idx['translate_page_on_front_ID'] ); |
1011 endif; |
2207 $value = get_option ( $option ) ; |
1012 |
2208 add_filter ( 'option_'.$option, array(&$this, 'translate_page_on_front_ID') ); |
1013 } else { |
2209 } else { |
1014 if (isset($_GET['xltgt_lang'])) { |
2210 $value = get_option ( $option ) ; |
1015 $curlangname = $_GET['xltgt_lang']; /* since 1.3.0 */ |
2211 } |
1016 $mention = '<br />('.__('From other post', 'xili-language').': '.$_GET['xlfrom_id'].' '.$_GET['xlfrom_lang'].')'; |
2212 return $value ; |
|
2213 } |
|
2214 |
|
2215 /** |
|
2216 * if possible, translate the ID of front_page post |
|
2217 * |
|
2218 * @since 1.7.0 |
|
2219 * called by hook option_page_on_front |
|
2220 * |
|
2221 */ |
|
2222 function translate_page_on_front_ID ( $original_id ) { |
|
2223 |
|
2224 if ( $this->lang_perma ) { |
|
2225 global $wp_query ; |
|
2226 |
|
2227 if ( !is_admin() && $this->show_page_on_front ) { |
|
2228 if ( isset( $wp_query->query_vars[QUETAG] ) && in_array ( $wp_query->query_vars[QUETAG], array_keys ( $this->show_page_on_front_array ) ) && '' != $wp_query->query_vars['page_id'] ) { |
|
2229 $curlang = $wp_query->query_vars[QUETAG]; |
|
2230 |
|
2231 |
|
2232 } elseif ( isset( $wp_query->query_vars[QUETAG] ) && in_array ( $wp_query->query_vars[QUETAG], array_keys ( $this->show_page_on_front_array ) ) ){ |
|
2233 |
|
2234 $curlang = $wp_query->query_vars[QUETAG]; // to verify |
|
2235 } else { |
|
2236 //$first_query = get_option('xili_language_settings_test') ; |
|
2237 //if ( $first_query ) { |
|
2238 //$curlang = $first_query ; |
|
2239 //} else { |
|
2240 $curlang = $this->choice_of_browsing_language(); // rule defined in admin UI |
|
2241 |
|
2242 //} |
|
2243 } |
|
2244 $trans_id = $this->linked_post_in( $original_id, $curlang ) ; |
|
2245 |
|
2246 if ( '' != $trans_id ) { |
|
2247 return $trans_id; |
|
2248 } else { |
|
2249 return $original_id; |
|
2250 } |
1017 } else { |
2251 } else { |
1018 $curlangname = $defaultlanguage; /* new post */ |
2252 return $original_id; |
1019 } |
2253 } |
1020 } |
2254 |
1021 echo __('Selected language', 'xili-language').' : <strong>'.$curlangname.'</strong> '.((0 == $post_ID) ? $mention : "").'<br /><br />' ; /*link to bottom of sidebar*/ |
|
1022 foreach ($listlanguages as $language) { ?> |
|
1023 <label for="xili_language_check_<?php echo $language->slug ; ?>" class="selectit"><input id="xili_language_check_<?php echo $language->slug ; ?>" name="xili_language_set" type="radio" value="<?php echo $language->slug ; ?>" <?php if($curlangname==$language->name) echo 'checked="checked"' ?> /> <?php echo _e($language->description, 'xili-language'); ?></label> |
|
1024 |
|
1025 <?php } /*link to top of sidebar*/?> |
|
1026 <label for="xili_language_check" class="selectit"><input id="xili_language_check" name="xili_language_set" type="radio" value="" <?php if($curlangname=="") echo 'checked="checked"' ?> /> <?php _e('undefined','xili-language') ?></label><br /> |
|
1027 <br /><small>© xili-language</small> |
|
1028 <?php |
|
1029 } |
|
1030 |
|
1031 /** |
|
1032 * to display the linked posts in post edit UI |
|
1033 * |
|
1034 * @since 0.9.8 |
|
1035 * @updated 1.3.0 |
|
1036 * |
|
1037 */ |
|
1038 function xili_language_linked_posts() { |
|
1039 global $post_ID, $post; |
|
1040 $update_nonce = wp_create_nonce('oklinked'); |
|
1041 $postlang = ''; |
|
1042 if(0 != $post_ID){ |
|
1043 $ress = wp_get_object_terms($post_ID, TAXONAME); |
|
1044 $obj_term = $ress[0]; |
|
1045 $postlang = ('' != $obj_term->slug) ? $obj_term->slug : ""; /* when created before plugin */ |
|
1046 } else { |
2255 } else { |
1047 $postlang = ""; /* new post */ |
2256 //$showpage = get_option('show_on_front'); |
1048 } |
2257 if ( !is_admin() && $this->show_page_on_front ) { |
1049 //$listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
2258 if ( isset( $_GET[QUETAG]) ) { // $this_curlang is not yet set |
1050 $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); |
2259 $curlang = $_GET[QUETAG]; |
1051 if ($post->post_type == 'post') { ?> |
2260 } else { |
1052 <p><em><?php _e('ID of posts in other languages:','xili-language'); ?></em></p> |
2261 $curlang = $this->choice_of_browsing_language(); // rule defined in admin UI |
1053 <?php $theid = 'Post ID'; |
2262 } |
1054 $autosearchmess = __('to auto search linked posts. (read docs)','xili-language'); |
2263 |
1055 $post_type = 'post'; |
2264 $trans_id = $this-> linked_post_in( $original_id, $curlang ) ; // get_post_meta($original_id, 'lang-'.$curlang, true); |
1056 } else { |
|
1057 ?> <p><em><?php _e('ID of pages in other languages:','xili-language'); ?></em></p> |
|
1058 <?php $theid = 'Page ID'; |
|
1059 $autosearchmess = __('to auto search linked pages. (read docs)','xili-language'); |
|
1060 $post_type = 'page'; |
|
1061 } |
|
1062 ?> |
|
1063 <table width="100%" cellspacing="4" cellpadding="2"> |
|
1064 <thead> |
|
1065 <tr ><th><?php _e('Language','xili-language'); ?></th><th align="left"><?php _e($theid,'xili-language'); ?></th><th align="left"><?php _e('Display','xili-language'); ?></th><th align="left"><?php _e('Edit'); ?></th></tr> |
|
1066 </thead> |
|
1067 <tbody id='the-linked' class='list:linked'> |
|
1068 <?php |
|
1069 if (0 != $post_ID) $autosearch = get_post_meta($post_ID,'_xl-search-linked',true); |
|
1070 foreach ($listlanguages as $language) { |
|
1071 $output = ""; |
|
1072 $otherpost = ""; |
|
1073 $line = true; |
|
1074 if ($language->slug == $postlang ) { |
|
1075 if ($post->post_status == 'publish' || $post->post_status == 'pending') { |
|
1076 $line = false; |
|
1077 } else { |
|
1078 $line = true; |
|
1079 } |
|
1080 } |
|
1081 if ($line) { |
|
1082 if (0 != $post_ID) { |
|
1083 $otherpost = get_post_meta($post_ID, QUETAG.'-'.$language->slug, true); |
|
1084 $otherpostr = $otherpost; |
|
1085 /* since 1.3.0 - 1.4.1 */ |
|
1086 if ('' != $autosearch && "" != $postlang) { |
|
1087 $source_ID = $this->search_pinger_post($post_ID,QUETAG.'-'.$postlang,$language->term_id, $post_type); |
|
1088 if (0 != $source_ID) { |
|
1089 $otherpost = $source_ID; |
|
1090 $otherpostr = "-1"; /* to be refreshed */ |
|
1091 } |
|
1092 } |
|
1093 } else { /* since 1.3.0 */ |
|
1094 if (isset($_GET['xlfrom_id'])) { |
|
1095 if ($_GET['xlfrom_lang'] == $language->slug) { |
|
1096 $otherpost = $_GET['xlfrom_id']; |
|
1097 $otherpostr = "-1"; |
|
1098 } else { |
|
1099 /* pre-fill linked posts from source post */ |
|
1100 $otherpost = get_post_meta($_GET['xlfrom_id'], QUETAG.'-'.$language->slug, true); |
|
1101 $otherpostr = "-1"; |
|
1102 } |
|
1103 } |
|
1104 } |
|
1105 |
2265 |
1106 ?> |
2266 if ( '' != $trans_id ) { |
1107 <tr ><th> |
2267 return $trans_id; |
1108 <label for="xili_language_<?php echo QUETAG.'-'.$language->slug ; ?>"><?php _e($language->description,'xili-language') ; ?> </label></th><td align="left"><input id="xili_language_<?php echo QUETAG.'-'.$language->slug ; ?>" name="xili_language_<?php echo QUETAG.'-'.$language->slug ; ?>" value="<?php echo $otherpost; ?>" size="5" /><input type="hidden" name="xili_language_rec_<?php echo QUETAG.'-'.$language->slug ; ?>" value="<?php echo $otherpostr; ?>"/> |
|
1109 |
|
1110 <?php |
|
1111 if ('' != $otherpost ) { |
|
1112 $output = "</td><td><a target='_blank' href='".get_permalink($otherpost)."' >"." ".__($language->description,'xili-language') ."</a></td><td><a target='_blank' href='post.php?action=edit&post=".$otherpost."' >"." ".__('Edit') ."</a></td></tr>"; |
|
1113 } else { |
2268 } else { |
1114 $output = $this->newlinkedpost($postlang, $language->name); /* if possible */ |
2269 return $original_id; |
1115 } |
2270 } |
1116 } |
2271 } else { |
1117 echo $output; |
2272 return $original_id; |
1118 } |
2273 } |
1119 /* since 1.4.1 */ |
2274 } |
1120 if (0 != $post_ID && "" != $postlang) { |
2275 } |
1121 ?> |
2276 |
1122 <tr ><th><?php _e('Check','xili-language'); ?></th><td><input id="xili_language_search_lang" name="xili_language_search_lang" type="checkbox" value="searchlinked" <?php if('' != $autosearch) echo 'checked="checked"' ?> /></td><td colspan = 2 ><small><?php echo$autosearchmess ; ?></small></td></tr> |
2277 /** |
1123 <?php } ?> |
2278 * List custom post types |
1124 </tbody></table> |
2279 * |
1125 <br /><small>© xili-language</small> |
2280 * @since 1.8.0 |
1126 <?php if ($this->post_ajax) { ?> |
2281 * |
1127 <div id='formstatus'></div><span id='loading' class='hidden'><?php _e('Saving...','xili-language') ?></span><span id='loading2' class='hidden'><?php _e('Refreshing...','xili-language') ?></span><div class='submit'> |
2282 */ |
1128 <input id='updatelink' name='updatelinked' type='submit' tabindex='6' value='Update' /><small>© xili-language</small></div><?php echo wp_nonce_field( 'oklinked', '_ajax_nonce', true, false );/**/ ?><?php /* echo wp_nonce_field( 'customrefresh', '_ajax_nonce', false, false );*/ ?> |
2283 function get_custom_desc() { |
1129 <script type='text/javascript'> |
2284 $types = get_post_types(array('show_ui'=>1)); |
1130 <!-- |
2285 if ( count($types) > 2 ) { |
1131 |
2286 $thecheck = array() ; |
1132 jQuery(document).ready(function(){ |
2287 $thecustoms = array(); |
1133 jQuery('#updatelink').click(function() { //start function when Random button is clicked |
2288 |
1134 jQuery.ajax({ |
2289 foreach ( $types as $type) { |
1135 type: "post",url: "admin-ajax.php", |
2290 $true = ( defined ('XDMSG') ) ? ( $type != XDMSG ) : true ; |
1136 data: { |
2291 if ( $type != 'page' && $type != 'post' && $true == true ) { |
1137 action: 'oklinked', |
2292 $custom = get_post_type_object ($type); |
1138 <?php |
2293 $clabels = $custom->labels; |
1139 foreach ($listlanguages as $language) { |
2294 $thecustoms[$type] = array ('name' => $custom->label, 'singular_name' => $clabels->singular_name, 'multilingual'=>'' ) ; |
1140 echo "xili_language_".$language->slug.": "."escape( jQuery( '#"."xili_language_".QUETAG."-".$language->slug."' ).val()),"; |
|
1141 } |
|
1142 echo "post_id: '".$post_ID."',"; |
|
1143 ?> |
|
1144 _ajax_nonce: '<?php echo $update_nonce; ?>' |
|
1145 }, |
|
1146 beforeSend: function() {jQuery("#loading").fadeIn('fast');jQuery("#formstatus").fadeIn("fast");}, //when link is clicked |
|
1147 success: function(html){ //so, if data is retrieved, store it in html |
|
1148 jQuery("#loading").fadeOut('slow'); |
|
1149 jQuery("#formstatus").html( html ); |
|
1150 jQuery.ajax({ // refresh custom fields list |
|
1151 type: "post",url: "admin-ajax.php", |
|
1152 data: { |
|
1153 action: 'customrefresh', |
|
1154 <?php |
|
1155 echo "post_id: '".$post_ID."',"; ?> |
|
1156 _ajax_nonce: '<?php echo $update_nonce; ?>' |
|
1157 }, |
|
1158 beforeSend: function() {jQuery("#loading2").fadeIn('fast');}, |
|
1159 success: function(html){ |
|
1160 jQuery("#the-list").html( html ); |
|
1161 jQuery("#loading2").fadeOut('slow'); |
|
1162 } |
|
1163 }); |
|
1164 } |
2295 } |
1165 }); //close jQuery.ajax |
2296 } |
1166 return false; |
2297 return $thecustoms ; |
1167 }) |
2298 } |
1168 }) |
2299 } |
1169 --> |
2300 |
1170 </script><?php } |
2301 /** |
1171 } |
2302 * unassign a language from a series of objects (post or link) |
1172 /** |
2303 * @since 1.8.8 |
1173 * to create a linked post in target language |
2304 * |
1174 * |
2305 * |
1175 * @since 1.3.0 |
2306 */ |
1176 * @updated 1.3.1 - Add New specific for pages |
2307 function multilingual_links_erase ( $lang_term_id ) { |
1177 * |
2308 $languages = $this -> get_listlanguages(); |
1178 */ |
2309 |
1179 function newlinkedpost($postlang = "" , $targetlang = "") { |
2310 foreach ($languages as $language ) { |
1180 global $post; |
2311 if ( $language->term_id == $lang_term_id ) { |
1181 $whatnew = ($post->post_type == 'post') ? 'post' : 'page'; |
2312 $lang_slug = $language->slug ; |
1182 if ($post->post_status == 'publish' || $post->post_status == 'pending' || $post->post_status == 'draft') { |
2313 continue ; |
1183 if ($postlang != strtolower($targetlang)) { |
2314 } |
1184 return "</td><td><small>".__('*','xili-language')."</small></td><td><a href='".$whatnew."-new.php?xlfrom_id=".$post->ID."&xlfrom_lang=".$postlang."&xltgt_lang=".$targetlang."' target='_blank' >".__('Add New')."</a></td><tr>"; |
2315 } |
1185 } |
2316 foreach ($languages as $language ) { |
1186 } else { |
2317 // for other languages as this - delete postmeta linked to post of erased posts |
1187 return "</td></tr>"; |
2318 if ( $language->term_id != $lang_term_id) { |
1188 } |
2319 $post_IDs = get_objects_in_term( array( $language->term_id ), array( TAXONAME ) ); |
1189 } |
2320 foreach ( $post_IDs as $post_ID ) { |
1190 |
2321 delete_post_meta( $post_ID, QUETAG.'-'.$lang_slug ) ; |
1191 /** |
2322 } |
1192 * to research post linking current post in the language |
2323 } |
1193 * @since 1.4.1 |
2324 } |
1194 * @params ID of post, lang of this post as meta_key, lang of searched pinger post, type of post (page) |
2325 // posts |
1195 * |
2326 $post_IDs = get_objects_in_term( array( $lang_term_id ), array( TAXONAME ) ); |
1196 */ |
2327 foreach ( $post_IDs as $post_ID ) { |
1197 function search_pinger_post ($targetID,$langmeta,$pingerlang,$posttype) { |
2328 // delete relationships posts |
1198 global $wpdb; |
2329 wp_delete_object_term_relationships( $post_ID, TAXONAME ); |
1199 |
2330 } |
1200 $query = "SELECT ID FROM $wpdb->posts as pp LEFT JOIN $wpdb->postmeta as pm ON (pp.ID = pm.post_id) LEFT JOIN $wpdb->term_relationships as tr ON (pp.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE 1=1 AND pm.meta_key = '$langmeta' AND pm.meta_value = '$targetID' AND pp.post_type = '$posttype' AND (pp.post_status IN ('publish','private','draft','pending')) AND tt.taxonomy = 'language' AND tt.term_id = $pingerlang ORDER BY pp.post_date DESC LIMIT 0, 1"; |
2331 // links of blogroll |
1201 //echo $query; |
2332 $links = get_objects_in_term( array( $lang_term_id ), array( 'link_'.TAXONAME ) ); |
1202 $r = @$wpdb->get_col($query); |
2333 foreach ( $links as $link ) { |
1203 //print_r($r); |
2334 wp_delete_object_term_relationships( $link, 'link_'.TAXONAME ); |
1204 if (!empty($r)) { |
2335 } |
1205 $id = $r[0]; /* if multiple take the most recent */ |
2336 } |
1206 } else { |
2337 |
1207 $id = 0; |
2338 |
1208 } |
2339 |
1209 //echo '->'.$id.$langmeta.$targetID.'</br>'; |
|
1210 return $id; |
|
1211 } |
|
1212 /* obsolete */ |
|
1213 function custom_refresh() { |
|
1214 check_ajax_referer( "oklinked" ); |
|
1215 $post_ID = $_POST['post_id']; |
|
1216 $count = 0; |
|
1217 $metadata = has_meta($post_ID); |
|
1218 $list =""; |
|
1219 $output = '';//<tr><td>Refreshed by xili-language</td></tr>'; |
|
1220 if ($metadata) |
|
1221 foreach ( $metadata as $entry ) { $list .= _list_meta_row( $entry, $count );} |
|
1222 $output .= $list; |
|
1223 echo $output."<!--- end updated by xili-language -->"; |
|
1224 die(); |
|
1225 } |
|
1226 |
|
1227 function ok_linked() { |
|
1228 check_ajax_referer( "oklinked" ); |
|
1229 |
|
1230 $post_ID = $_POST['post_id']; |
|
1231 |
|
1232 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
|
1233 $linked = array (); |
|
1234 foreach ($listlanguages as $language) { |
|
1235 $key = $language->slug; |
|
1236 $linked[$key] = $_POST['xili_language_'.$key]; |
|
1237 $linkid = $linked[$key]; |
|
1238 //$reclinkid = $_POST[$recinputid]; /* hidden previous value */ |
|
1239 $langslug = QUETAG.'-'.$key ; |
|
1240 //if ($reclinkid != $linkid) { /* only if changed value */ |
|
1241 if ((is_numeric($linkid) && $linkid == 0) || '' == $linkid ) { |
|
1242 delete_post_meta($post_ID, $langslug); |
|
1243 } elseif (is_numeric($linkid) && $linkid > 0) { |
|
1244 update_post_meta($post_ID, $langslug, $linkid); |
|
1245 $mess .= " ".$key; |
|
1246 } |
|
1247 } |
|
1248 echo '<p>All is OK '.$post_id.' ('.$mess.')</p>'; // voir bannière // |
|
1249 die(); |
|
1250 |
|
1251 } |
|
1252 |
|
1253 /** |
|
1254 * to display the languages settings admin UI |
|
1255 * |
|
1256 * @since 0.9.0 |
|
1257 * @updated 0.9.6 - only for WP 2.7.X - do new meta boxes and JS |
|
1258 * |
|
1259 */ |
|
1260 function languages_settings() { |
|
1261 $formtitle = 'Add a language'; /* translated in form */ |
|
1262 $submit_text = __('Add »','xili-language'); |
|
1263 $cancel_text = __('Cancel'); |
|
1264 |
|
1265 if (isset($_POST['reset'])) { |
|
1266 $action=$_POST['reset']; |
|
1267 } elseif (isset($_POST['updateoptions'])) { |
|
1268 $action='updateoptions'; |
|
1269 } elseif (isset($_POST['updateundefined'])) { |
|
1270 $action='updateundefined'; |
|
1271 |
|
1272 } elseif (isset($_POST['action'])) { |
|
1273 $action=$_POST['action']; |
|
1274 } |
|
1275 |
|
1276 if (isset($_GET['action'])) : |
|
1277 $action=$_GET['action']; |
|
1278 $term_id = $_GET['term_id']; |
|
1279 endif; |
|
1280 $message = $action ; |
|
1281 switch($action) { |
|
1282 case 'updateundefined'; |
|
1283 $targetlang = $_POST['xili_language_toset']; |
|
1284 $fromcats = $_POST['from_categories']; |
|
1285 if (""!= $targetlang) { |
|
1286 $q = xiliml_setlang_of_undefined_posts ($targetlang, $fromcats, 50); |
|
1287 $message .= " _ $q ".__('posts are set in:','xili-language')." ".$targetlang." ".__("category")." =[$fromcats]"; |
|
1288 } else { |
|
1289 $q = xiliml_setlang_of_undefined_posts ($targetlang, $fromcats, 50); |
|
1290 $message .= " _ around $q ".__('posts are undefined in','xili-language')." ".__("category")." = [$fromcats]"; |
|
1291 } |
|
1292 $actiontype = "reset"; |
|
1293 break; |
|
1294 case 'updateoptions'; |
|
1295 $this->browseroption = $_POST['xili_language_check_option']; |
|
1296 $this->authorbrowseroption = $_POST['xili_language_check_option_author']; |
|
1297 $this->functions_enable = $_POST['xili_language_check_functions_enable']; |
|
1298 $this->xili_settings['browseroption'] = $this->browseroption; |
|
1299 $this->xili_settings['authorbrowseroption'] = $this->authorbrowseroption; |
|
1300 $this->xili_settings['functions_enable'] = $this->functions_enable; |
|
1301 |
|
1302 $this->xili_settings['homelang'] = $_POST['xili_language_home_lang']; // 1.3.2 |
|
1303 |
|
1304 update_option('xili_language_settings', $this->xili_settings); |
|
1305 $message .= " - ".__('Option is updated.','xili-language')." (=> ".$this->browseroption.") (".$this->authorbrowseroption.") (".$this->functions_enable.")"; |
|
1306 $this->insert_gold_functions (); |
|
1307 $actiontype = "reset"; |
|
1308 break; |
|
1309 |
|
1310 case 'add': |
|
1311 $term = $_POST['language_name']; |
|
1312 $args = array( 'alias_of' => '', 'description' => $_POST['language_description'], 'parent' => 0, 'slug' =>$_POST['language_nicename']); |
|
1313 $theids = wp_insert_term( $term, TAXONAME, $args); |
|
1314 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
|
1315 update_term_order ($theids['term_id'],$this->langs_group_tt_id,$_POST['language_order']); |
|
1316 $actiontype = "add"; |
|
1317 $message .= " - ".__('A new language was added.','xili-language'); |
|
1318 break; |
|
1319 |
|
1320 case 'edit'; |
|
1321 $actiontype = "edited"; |
|
1322 //echo $term_id; |
|
1323 //$language = get_term($term_id,TAXONAME,OBJECT,'edit'); |
|
1324 $language = get_term_and_order ($term_id,$this->langs_group_tt_id,TAXONAME); |
|
1325 $submit_text = __('Update »'); |
|
1326 $formtitle = 'Edit language'; |
|
1327 $message .= " - ".__('Language to update.','xili-language'); |
|
1328 break; |
|
1329 |
|
1330 case 'edited'; |
|
1331 $actiontype = "add"; |
|
1332 $term = $_POST['language_term_id']; |
|
1333 |
|
1334 $args = array( 'alias_of' => '', 'description' => $_POST['language_description'], 'parent' => 0, 'slug' =>$_POST['language_nicename']); |
|
1335 $theids = wp_update_term( $term, TAXONAME, $args); |
|
1336 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
|
1337 update_term_order ($theids['term_id'],$this->langs_group_tt_id,$_POST['language_order']); |
|
1338 $message .= " - ".__('A language was updated.','xili-language'); |
|
1339 |
|
1340 break; |
|
1341 |
|
1342 case 'delete'; |
|
1343 $actiontype = "deleting"; |
|
1344 $submit_text = __('Delete »','xili-language'); |
|
1345 $formtitle = 'Delete language ?'; |
|
1346 //$language = get_term($term_id,TAXONAME,OBJECT,'edit'); |
|
1347 $language = get_term_and_order ($term_id,$this->langs_group_tt_id,TAXONAME); |
|
1348 $message .= " - ".__('A language to delete.','xili-language'); |
|
1349 |
|
1350 break; |
|
1351 |
|
1352 case 'deleting'; |
|
1353 $actiontype = "add"; |
|
1354 $term = $_POST['language_term_id']; |
|
1355 wp_delete_object_term_relationships( $term, TAXOLANGSGROUP ); |
|
1356 wp_delete_term( $term, TAXONAME, $args); |
|
1357 $message .= " - ".__('A language was deleted.','xili-language'); |
|
1358 break; |
|
1359 case 'reset'; |
|
1360 $actiontype = "add"; |
|
1361 break; |
|
1362 default : |
|
1363 $actiontype = "add"; |
|
1364 $message .= __('Find above the list of languages.','xili-language'); |
|
1365 |
|
1366 |
|
1367 } |
|
1368 /* register the main boxes always available */ |
|
1369 add_meta_box('xili-language-normal-1', __('List of languages','xili-language'), array(&$this,'on_normal_1_content'), $this->thehook , 'normal', 'core'); |
|
1370 add_meta_box('xili-language-normal-2', __('Language','xili-language'), array(&$this,'on_normal_2_content'), $this->thehook , 'normal', 'core'); |
|
1371 add_meta_box('xili-language-sidebox-3', __('Settings','xili-language'), array(&$this,'on_sidebox_3_content'), $this->thehook , 'side', 'core'); |
|
1372 |
|
1373 /* form datas in array for do_meta_boxes() */ |
|
1374 $data = array('message'=>$message,'messagepost'=>$messagepost,'action'=>$action, 'formtitle'=>$formtitle, 'language'=>$language,'submit_text'=>$submit_text,'cancel_text'=>$cancel_text,'browseroption'=>$this->browseroption, 'authorbrowseroption'=>$this->authorbrowseroption , 'functions_enable'=>$this->functions_enable); |
|
1375 ?> |
|
1376 |
|
1377 <div id="xili-language-settings" class="wrap" style="min-width:750px"> |
|
1378 <?php screen_icon('options-general'); ?> |
|
1379 <h2><?php _e('Languages','xili-language') ?></h2> |
|
1380 <form name="add" id="add" method="post" action="options-general.php?page=language_page"> |
|
1381 <input type="hidden" name="action" value="<?php echo $actiontype ?>" /> |
|
1382 <?php wp_nonce_field('xili-language-settings'); ?> |
|
1383 <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?> |
|
1384 <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); |
|
1385 /* 0.9.9.2 add has-right-sidebar for next wp 2.8*/ ?> |
|
1386 <div id="poststuff" class="metabox-holder has-right-sidebar"> |
|
1387 <div id="side-info-column" class="inner-sidebar"> |
|
1388 <?php do_meta_boxes($this->thehook, 'side', $data); ?> |
|
1389 </div> |
|
1390 |
|
1391 <div id="post-body" class="has-sidebar has-right-sidebar"> |
|
1392 <div id="post-body-content" class="has-sidebar-content" style="min-width:360px"> |
|
1393 |
|
1394 <?php do_meta_boxes($this->thehook, 'normal', $data); ?> |
|
1395 </div> |
|
1396 <h4><a href="http://dev.xiligroup.com/xili-language" 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__)).'/xililang-logo-32.gif'; ?>" alt="xili-language logo"/> xili-language</a> - © <a href="http://dev.xiligroup.com" target="_blank" title="<?php _e('Author'); ?>" >xiligroup.com</a>™ - msc 2007-9 - v. <?php echo XILILANGUAGE_VER; ?></h4> |
|
1397 </div> |
|
1398 </div> |
|
1399 </form> |
|
1400 </div> |
|
1401 <script type="text/javascript"> |
|
1402 //<![CDATA[ |
|
1403 jQuery(document).ready( function($) { |
|
1404 // close postboxes that should be closed |
|
1405 $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); |
|
1406 // postboxes setup |
|
1407 postboxes.add_postbox_toggles('<?php echo $this->thehook; ?>'); |
|
1408 }); |
|
1409 //]]> |
|
1410 </script> |
|
1411 <?php //end settings div |
|
1412 } |
|
1413 |
|
1414 //* display xililanguage in lists *// |
|
1415 function xili_manage_column($name, $id) { |
|
1416 if($name != TAXONAME) |
|
1417 return; |
|
1418 $terms = wp_get_object_terms($id, TAXONAME); |
|
1419 $first = true; |
|
1420 foreach($terms AS $term) { |
|
1421 if($first) |
|
1422 $first = false; |
|
1423 else |
|
1424 echo ', '; |
|
1425 echo '<a href="' . 'options-general.php?page=language_page'.'">'; /* see more precise link ?*/ |
|
1426 echo $term->name; |
|
1427 echo '</a>'; |
|
1428 } |
|
1429 } |
|
1430 function xili_manage_column_name($cols) { |
|
1431 $ends = array('comments', 'date', 'rel', 'visible'); |
|
1432 $end = array(); |
|
1433 foreach($cols AS $k=>$v) { |
|
1434 if(in_array($k, $ends)) { |
|
1435 $end[$k] = $v; |
|
1436 unset($cols[$k]); |
|
1437 } |
|
1438 } |
|
1439 $cols[TAXONAME] = __('Language','xili-language'); |
|
1440 $cols = array_merge($cols, $end); |
|
1441 return $cols; |
|
1442 } |
|
1443 |
|
1444 /** |
2340 /** |
1445 * Set language plugin |
2341 * Set language plugin |
1446 * |
2342 * |
1447 * |
2343 * |
1448 * @updated 1.1.9 |
2344 * @updated 1.1.9 |
1449 * also include automatic search of domain and lang subfolder in current theme |
2345 * also include automatic search of domain and lang subfolder in current theme |
1450 */ |
2346 */ |
1451 function init_textdomain() { |
2347 function init_textdomain() { |
1452 /*multilingual for admin pages and menu*/ |
2348 /*multilingual for admin pages and menu*/ |
1453 load_plugin_textdomain('xili-language',PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__))); |
2349 load_plugin_textdomain('xili-language', false, 'xili-language/languages' ); |
1454 if (!defined('THEME_TEXTDOMAIN')) { |
2350 |
1455 if ($this->xili_settings['theme_domain'] != "") { |
2351 /* in wp3 multisite - don't use constant - for backward compatibility keep it in mono*/ |
1456 define('THEME_TEXTDOMAIN',$this->xili_settings['theme_domain']); |
2352 if ( '' != $this->xili_settings['theme_domain'] ) { |
|
2353 if (!is_multisite() && !defined('THEME_TEXTDOMAIN') ) define('THEME_TEXTDOMAIN',$this->thetextdomain); // for backward compatibility; |
|
2354 if ( is_admin() ) { |
1457 |
2355 |
1458 } else { /* search it inside theme folder index.php */ |
2356 $this->thetextdomain = $this->xili_settings['theme_domain'] ; |
1459 if( is_file( get_template_directory().'/index.php') ) { |
2357 update_option('xili_language_settings', $this->xili_settings); |
1460 $lines = @file( get_template_directory().'/index.php'); |
2358 |
1461 foreach ($lines as $line) { |
2359 } |
1462 $i = preg_match_all("/_[_e]\('(.*)', ?'(.*)'/Ui", $line, $matches,PREG_PATTERN_ORDER); |
2360 } else { |
1463 if ($i > 0) { |
2361 $this->domaindetectmsg = __('no load_theme_textdomain in functions.php','xili-language'); |
1464 $resultterms = array_merge ($resultterms, $matches[1]); |
2362 } |
1465 //print_r($matches[1]); |
2363 |
1466 //print_r($matches[2]); |
2364 } |
1467 $domain = $matches[2][0]; |
2365 |
1468 $this->xili_settings['theme_domain'] = $domain; |
2366 function searchpath( $path, $filename ) { |
1469 update_option('xili_language_settings', $this->xili_settings); |
2367 $this->xili_settings['langs_folder'] = str_replace($this->get_template_directory,'',$path); |
1470 define('THEME_TEXTDOMAIN',$this->xili_settings['theme_domain']); |
2368 } |
1471 break; |
2369 |
1472 } |
|
1473 } |
|
1474 if ($domain == "") |
|
1475 _e('no theme domain in index.php','xili-language'); |
|
1476 } else { |
|
1477 _e('no index.php in theme, domain not set','xili-language'); |
|
1478 } |
|
1479 } |
|
1480 } |
|
1481 if (!defined('THEME_LANGS_FOLDER')) { /* set or detect */ |
|
1482 if ($this->xili_settings['langs_folder'] == "") { |
|
1483 $this->find_files(get_template_directory(), '/.mo$/', array(&$this,'searchpath')); |
|
1484 update_option('xili_language_settings', $this->xili_settings); |
|
1485 } |
|
1486 |
|
1487 define('THEME_LANGS_FOLDER',$this->xili_settings['langs_folder']); // for bkwd compatibility with xili-dictionary |
|
1488 } |
|
1489 } |
|
1490 function searchpath($path, $filename) { |
|
1491 $this->xili_settings['langs_folder'] = str_replace(get_template_directory(),'',$path); |
|
1492 } |
|
1493 /** |
2370 /** |
1494 * Reset values when theme was changed... updated by previous function |
2371 * Reset values when theme was changed... updated by previous function |
1495 * @since 1.1.9 |
2372 * @since 1.1.9 |
1496 */ |
2373 */ |
1497 function theme_switched ($theme) { |
2374 function theme_switched ( $theme ) { |
1498 $this->xili_settings['langs_folder'] =""; |
2375 $this->xili_settings['langs_folder'] =""; |
1499 $this->xili_settings['theme_domain'] =""; /* to force future search in new theme */ |
2376 $this->xili_settings['theme_domain'] =""; /* to force future search in new theme */ |
1500 update_option('xili_language_settings', $this->xili_settings); |
2377 update_option('xili_language_settings', $this->xili_settings); |
1501 } |
2378 } |
1502 |
2379 |
1503 /** |
2380 /** |
1504 * private functions for languages_settings |
2381 * to add links in current menu of twentyten |
1505 * @since 0.9.6 |
2382 * |
1506 * |
|
1507 * fill the content of the boxes (right side and normal) |
|
1508 * |
2383 * |
1509 */ |
2384 * |
1510 function on_sidebox_1_content($data) { |
2385 */ |
1511 extract($data); |
2386 function add_list_of_language_links_in_wp_menu ( $location ) { |
1512 ?> |
2387 $defaultarray = array( |
1513 <h4><?php _e('Note:','xili-language') ?></h4> |
2388 'menu-item-type' => 'custom', |
1514 <p><?php echo $message;?></p> |
2389 'menu-item-title' => '', |
1515 <?php |
2390 'menu-item-url' => '', |
1516 } |
2391 'menu-item-description' => '', |
1517 |
2392 'menu-item-status' => 'publish'); |
1518 function on_sidebox_2_content() { ?> |
2393 $url = get_bloginfo('url') ; |
1519 |
2394 $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); |
1520 <p><?php _e("This plugin was developed with the taxonomies, terms tables and tags specifications. <br /> Here a new taxonomy was created and used for languages of posts and pages. <br /> New radiobuttons are available in Post (and Page) write and edit admin pages for selection by author. It is updated for WP 2.9 since 1.1",'xili-language') ?></p> |
2395 $langdesc_array = array(); |
1521 <?php |
2396 foreach ($listlanguages as $language){ |
1522 } |
2397 $langdesc_array[] = $language->description; |
1523 |
2398 } |
1524 function on_sidebox_3_content($data) { /* where to choose if browser language preferences is tested or not */ |
2399 /* detect menu inside location */ |
1525 extract($data); |
2400 $menu_locations = get_nav_menu_locations(); |
1526 $update_nonce = wp_create_nonce('xilimloptions'); |
2401 $menuid = $menu_locations[$location]; |
1527 /* 1.0 browser - default - languages */ |
2402 $menuitem = wp_get_nav_menu_object($menuid); |
1528 ?> |
2403 $items = get_objects_in_term( $menuitem->term_id, 'nav_menu' ); |
1529 <fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"><legend><?php echo _e('Select language of the home page', 'xili-language'); ?></legend> |
2404 $nothere = true; |
1530 <select name="xili_language_check_option" id="xili_language_check_option" style="width:100%;"> |
2405 if ( ! empty( $items ) ) { |
1531 <?php if ($browseroption == 'browser') |
2406 $founditems = wp_get_nav_menu_items($menuid); //try to see if a previous insert was done |
1532 $checked = 'selected = "selected"'; |
2407 foreach ($founditems as $item) { |
1533 else |
2408 if ($item->title =='|' || in_array($item->title, $langdesc_array)) { |
1534 $checked = ''; |
2409 $nothere = false; |
1535 ?> |
2410 break; |
1536 <option value="" ><?php _e('Software defined','xili-language'); ?></option> |
2411 } |
1537 <option value="browser" <?php echo $checked; ?> ><?php _e("Language of visitor's browser",'xili-language'); ?></option> |
2412 } |
1538 <?php $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); |
2413 } |
1539 foreach ($listlanguages as $language) { |
2414 if ($nothere == true) { |
1540 if ($browseroption == $language->slug) |
2415 /* add separator */ |
1541 $checked = 'selected = "selected"'; |
2416 $defaultarray['menu-item-title'] = '|'; |
1542 else |
2417 $defaultarray['menu-item-url'] = $url.'/#'; |
1543 $checked = ''; |
2418 wp_update_nav_menu_item($menuid,0,$defaultarray); |
1544 echo '<option value="'.$language->slug.'" '.$checked.' >'.__($language->description,'xili-language').'</option>'; |
2419 foreach ($listlanguages as $language){ |
1545 } |
2420 $defaultarray['menu-item-title'] = $language->description ; |
1546 ?> |
2421 $defaultarray['menu-item-url'] = $url.'/?lang='.$language->slug ; |
1547 </select> |
2422 wp_update_nav_menu_item($menuid,0,$defaultarray); |
1548 <?php if ('page' != get_settings('show_on_front')) { ?> |
2423 } |
1549 <br /> <label for="xili_language_home_lang"><?php _e('Modify home query','xili-language') ?> <input id="xili_language_home_lang" name="xili_language_home_lang" type="checkbox" value="modify" <?php if($this->xili_settings['homelang'] == 'modify') echo 'checked="checked"' ?> /></label> |
2424 return __("language items added","xili-language"); |
1550 <?php } ?> |
2425 } else { |
1551 |
2426 return __("seems to be set","xili-language"); |
1552 |
2427 } |
1553 </fieldset> |
2428 } |
1554 <br /><br /> |
2429 |
1555 <label for="xili_language_check_option_author" class="selectit"><input id="xili_language_check_option_author" name="xili_language_check_option_author" type="checkbox" value="authorbrowser" <?php if($authorbrowseroption=='authorbrowser') echo 'checked="checked"' ?> /> <?php echo _e('For new post, pre-select by default: browser language of author', 'xili-language'); ?></label> |
2430 /** |
1556 <br /><br /> |
2431 * ***** Functions to improve bookmarks language filtering ***** |
1557 <?php if (file_exists(XILIFUNCTIONSPATH)) { /* test if folder exists - ready to add functions.php inside - since 1.0 */?> |
2432 * |
1558 <label for="xili_language_check_functions_enable" class="selectit"><input id="xili_language_check_functions_enable" name="xili_language_check_functions_enable" type="checkbox" value="enable" <?php if($functions_enable =='enable') echo 'checked="checked"' ?> /> <?php echo _e('Enable gold functions', 'xili-language'); ?></label> |
2433 */ |
1559 <?php } else { |
2434 |
1560 echo '<input type="hidden" name="xili_language_check_functions_enable" value="'.$functions_enable.'" />'; |
2435 /** |
1561 } ?> |
2436 * Filter to widget_links parameter |
1562 <div id='formstatus'></div><span id='loading' class='hidden'><?php _e('Updating...','xili-language') ?></span><div class='submit'> |
2437 * @ since 1.8.5 |
1563 <input id='updateoptions' name='updateoptions' type='submit' tabindex='6' value="<?php _e('Update','xili-language') ?>" /></div> |
2438 */ |
1564 <?php echo wp_nonce_field( 'xilimloptions', '_ajax_nonce', true, false );/**/ ?> |
2439 function widget_links_args_and_lang ($widget_args) { |
1565 <div style="clear:both; height:1px"></div><?php |
2440 |
1566 } |
2441 $cur_lang = $this->curlang; |
1567 |
2442 // rules depending category and settings in xili-language |
1568 function on_sidebox_4_content() { |
2443 $cat_settings = $this->xili_settings['link_categories_settings'] ; //array ( 'all'=> true, 'category' => array ( '2' => false , '811' => true ) ); |
1569 $update_nonce = wp_create_nonce('xilimloptions'); |
2444 $sub_select = false; |
1570 ?> |
2445 if ( $widget_args['category'] ) { |
1571 <fieldset style="margin:2px; padding:12px 6px; border:1px solid #ccc;"><legend><?php echo __("Theme's informations:",'xili-language').' ('.get_option("template").')'; ?></legend> |
2446 $sub_select = $cat_settings['category'][$widget_args['category']] ; |
1572 <p><?php |
2447 } else { |
1573 if (defined('THEME_TEXTDOMAIN')) { |
2448 $sub_select = $cat_settings['all']; |
1574 echo __('theme_domain:','xili-language').' '.THEME_TEXTDOMAIN.'<br />'.__('as function like:','xili-language').'<i> _e(\'-->\',\''.THEME_TEXTDOMAIN.'\');</i>'; } |
2449 // if ( $sub_select ) $widget_args['categorize'] = 0; |
1575 else { |
2450 } |
1576 _e('Theme domain NOT defined','xili-language'); |
2451 |
1577 } ?><br /> |
2452 if ( $sub_select ) { |
1578 <?php echo __("Languages sub-folder:",'xili-language').' '.$this->xili_settings['langs_folder']; ?><br /> |
2453 $linklang = term_exists($cur_lang,'link_'.TAXONAME) ; |
1579 <?php _e('Available MO files:','xili-language'); echo '<br />'; |
2454 $linklang_ever = term_exists('ev_er','link_'.TAXONAME) ; // the dummy lang - shown ever with selected language |
1580 $this->find_files(get_template_directory(), "/.mo$/", array(&$this,"available_mo_files")) ;?> |
2455 if ( $cur_lang && $linklang ) { |
1581 </p> |
2456 if ( $widget_args['category'] ) { |
1582 </fieldset> |
2457 $cat = get_term( $widget_args['category'], 'link_category' ); |
1583 <p><?php _e("Special Gold Actions",'xili-language') ?></p> |
2458 $catname = apply_filters( "link_category", $cat->name ); |
1584 |
2459 } |
1585 <?php |
2460 $the_link_ids = array (); |
1586 //echo '---'.$this->functions_enable; |
|
1587 if ($this->functions_enable !='' && function_exists('xiliml_setlang_of_undefined_posts')) { |
|
1588 xiliml_special_UI_undefined_posts ($this->langs_group_id); |
|
1589 } |
|
1590 } |
|
1591 |
|
1592 function on_normal_1_content($data) { |
|
1593 extract($data); ?> |
|
1594 <?php //if (!isset($action) || $action=='add' || $action=='edited' || $action=='deleting') :?> |
|
1595 <table class="widefat"> |
|
1596 <thead> |
|
1597 <tr> |
|
1598 <th scope="col" style="text-align: center"><?php _e('ID') ?></th> |
|
1599 <th scope="col"><?php _e('Name','xili-language') ?></th> |
|
1600 <th scope="col"><?php _e('Full name','xili-language') ?></th> |
|
1601 <th scope="col"><?php _e('Language slug','xili-language') ?></th> |
|
1602 <th scope="col"><?php _e('Order','xili-language') ?></th> |
|
1603 <th scope="col" width="90" style="text-align: center"><?php _e('Posts') ?></th> |
|
1604 <th colspan="2" style="text-align: center"><?php _e('Action') ?></th> |
|
1605 </tr> |
|
1606 </thead> |
|
1607 <tbody id="the-list"> |
|
1608 <?php $this->xili_lang_row(); /* the lines */?> |
|
1609 </tbody> |
|
1610 </table> |
|
1611 <?php if ($action=='edit' || $action=='delete') :?> |
|
1612 <p>(<a href="?action=add&page=language_page"><?php _e('Add a language','xili-language') ?></a>)</p> |
|
1613 <?php endif; ?> |
|
1614 <?php |
|
1615 } |
|
1616 |
|
1617 function on_normal_2_content($data) { |
|
1618 extract($data); |
|
1619 /* the create - edit - delete form */ ?> |
|
1620 |
|
1621 <h2 id="addlang" <?php if ($action=='delete') echo 'style="color:#FF1111;"'; ?>><?php _e($formtitle,'xili-language') ?></h2> |
|
1622 <?php if ($action=='edit' || $action=='delete') :?> |
|
1623 <input type="hidden" name="language_term_id" value="<?php echo $language->term_id ?>" /> |
|
1624 <?php endif; ?> |
|
1625 <table class="editform" width="100%" cellspacing="2" cellpadding="5"> |
|
1626 <tr> |
|
1627 <th width="33%" scope="row" valign="top" align="right"><label for="language_name"><?php _e('Name') ?></label>: </th> |
|
1628 <td width="67%"><input name="language_name" id="language_name" type="text" value="<?php echo attribute_escape($language->name); ?>" size="40" <?php if($action=='delete') echo 'disabled="disabled"' ?> /></td> |
|
1629 </tr> |
|
1630 <tr> |
|
1631 <th scope="row" valign="top" align="right"><label for="language_nicename"><?php _e('Language slug','xili-language') ?></label>: </th> |
|
1632 <td><input name="language_nicename" id="language_nicename" type="text" value="<?php echo attribute_escape($language->slug); ?>" size="40" <?php if($action=='delete') echo 'disabled="disabled"' ?> /></td> |
|
1633 </tr> |
|
1634 <tr> |
|
1635 <th scope="row" valign="top" align="right"><label for="language_description"><?php _e('Full name','xili-language') ?></label>: </th> |
|
1636 <td><input name="language_description" id="language_description" size="40" value="<?php echo $language->description; ?>" <?php if($action=='delete') echo 'disabled="disabled"' ?> /></td> |
|
1637 |
2461 |
1638 </tr> |
2462 $the_link_ids_cat = get_objects_in_term( array( $widget_args['category'] ), 'link_category' ) ; |
1639 <tr> |
2463 $the_link_ids = get_objects_in_term( array( $linklang['term_id'], $linklang_ever['term_id'] ), 'link_'.TAXONAME ) ; // lang + ever |
1640 <th scope="row" valign="top" align="right"><label for="language_order"><?php _e('Order','xili-language') ?></label>: </th> |
2464 $the_link_ids_all = array_intersect ($the_link_ids , $the_link_ids_cat ); |
1641 <td><input name="language_order" id="language_order" size="3" value="<?php echo $language->term_order; ?>" <?php if($action=='delete') echo 'disabled="disabled"' ?> /></td> |
2465 if ( $widget_args['category'] ) $widget_args['categorize'] = 0; // no sub list in one cat asked |
|
2466 $widget_args['include'] = implode (',' , $the_link_ids_all ); |
|
2467 $widget_args['category'] = ''; // because implode of intersect |
|
2468 $widget_args['title_li'] = $catname ; |
1642 |
2469 |
1643 </tr> |
2470 } |
1644 <tr> |
|
1645 <th><p class="submit"><input type="submit" name="reset" value="<?php echo $cancel_text ?>" /></p></th> |
|
1646 <td> |
|
1647 <p class="submit"><input type="submit" name="submit" value="<?php echo $submit_text ?>" /></p> |
|
1648 </td> |
|
1649 </tr> |
|
1650 </table> |
|
1651 <?php |
|
1652 } |
|
1653 |
|
1654 /** |
|
1655 * private functions for admin page : the language list |
|
1656 * @since 0.9.0 |
|
1657 * |
|
1658 * @update 0.9.5 : two default languages if taxonomy languages is empty |
|
1659 * |
|
1660 */ |
|
1661 function xili_lang_row() { |
|
1662 /*list of languages*/ |
|
1663 //$listlanguages = get_terms_with_order($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); |
|
1664 $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); |
|
1665 |
|
1666 if (empty($listlanguages)) : /*create two default lines with the default language (as in config)*/ |
|
1667 /* language of WP */ |
|
1668 $term = 'en_US'; |
|
1669 $args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>''); |
|
1670 $theids = wp_insert_term( $term, TAXONAME, $args); |
|
1671 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); |
|
1672 $term = $this->default_lang; |
|
1673 $desc = $this->default_lang; |
|
1674 if (!defined('WPLANG') || $this->default_lang == 'en_US' ) {$term = 'fr_FR'; $desc = 'french';} |
|
1675 $args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' =>''); |
|
1676 $theids = wp_insert_term( $term, TAXONAME, $args); |
|
1677 wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); /* create the group */ |
|
1678 $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); |
|
1679 endif; |
|
1680 foreach ($listlanguages as $language) { |
|
1681 $class = ((defined('DOING_AJAX') && DOING_AJAX) || " class='alternate'" == $class ) ? '' : " class='alternate'"; |
|
1682 $language->count = number_format_i18n( $language->count ); |
|
1683 $posts_count = ( $language->count > 0 ) ? "<a href='edit.php?lang=$language->slug'>$language->count</a>" : $language->count; |
|
1684 |
|
1685 $edit = "<a href='?action=edit&page=language_page&term_id=".$language->term_id."' >".__( 'Edit' )."</a></td>"; |
|
1686 /* delete link*/ |
|
1687 $edit .= "<td><a href='?action=delete&page=language_page&term_id=".$language->term_id."' class='delete'>".__( 'Delete' )."</a>"; |
|
1688 |
|
1689 $line="<tr id='cat-$language->term_id'$class> |
|
1690 <th scope='row' style='text-align: center'>$language->term_id</th> |
|
1691 <td>" .$language->name. "</td> |
|
1692 <td>$language->description</td> |
|
1693 <td>$language->slug</td> |
|
1694 <td>$language->term_order</td> |
|
1695 <td align='center'>$posts_count</td> |
|
1696 <td>$edit</td>\n\t</tr>\n"; /*to complete - 0.9.8.1 count to post*/ |
|
1697 echo $line; |
|
1698 //print_r($language); |
|
1699 } |
2471 } |
|
2472 return $widget_args ; |
|
2473 } |
|
2474 |
|
2475 /** |
|
2476 * only active if 'lang' in template tag wp_list_bookmarks() |
|
2477 * |
|
2478 * as : wp_list_bookmarks( array( 'lang'=>the_curlang() ) ) to display only in current language |
|
2479 * |
|
2480 * don't interfere with widget_links filter |
|
2481 * |
|
2482 * @ since 1.8.5 |
|
2483 */ |
|
2484 function the_get_bookmarks_lang ($links_list, $args) { |
|
2485 if ( isset( $args[QUETAG] ) ) { |
|
2486 // get links in selected lang |
|
2487 $linklang = term_exists($args[QUETAG],'link_'.TAXONAME) ; |
|
2488 $linklang_ever = term_exists('ev_er','link_'.TAXONAME) ; // the dummy lang - shown ever with selected language |
|
2489 //global $the_link_ids; |
|
2490 $this->the_link_ids = get_objects_in_term( array( $linklang['term_id'], $linklang_ever['term_id'] ), 'link_'.TAXONAME ) ; |
|
2491 |
|
2492 return array_filter ( $links_list , array(&$this,'_filtering_links') ) ; |
|
2493 |
|
2494 } |
|
2495 return $links_list; |
|
2496 } |
|
2497 function _filtering_links ($link) { |
|
2498 //global $the_link_ids; |
|
2499 if ( in_array( $link->link_id , $this->the_link_ids ) ) return true ; |
|
2500 } |
|
2501 |
|
2502 /** |
|
2503 * Register link language taxonomy |
|
2504 * @ since 1.8.5 |
|
2505 */ |
|
2506 function add_link_taxonomy () { |
|
2507 register_taxonomy( 'link_'.TAXONAME, 'link', array('hierarchical' => false, 'label' => false, 'rewrite' => false, 'update_count_callback' => array(&$this,'_update_link_lang_count'), 'show_ui' => false, '_builtin' => false )); |
|
2508 |
|
2509 } |
|
2510 // count update |
|
2511 function _update_link_lang_count( $terms ) { |
|
2512 // |
|
2513 global $wpdb; |
|
2514 foreach ( (array) $terms as $term ) { |
|
2515 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->term_relationships.object_id AND term_taxonomy_id = %d", $term ) ); |
|
2516 $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); |
|
2517 } |
|
2518 } |
|
2519 |
|
2520 |
|
2521 /** end of language for bookmarks * @ since 1.8.5 **/ |
|
2522 |
|
2523 |
|
2524 /** |
|
2525 * now active in same file as class xili_language |
|
2526 * Widgets registration after classes rewritten |
|
2527 * |
|
2528 * @since 1.8.8 |
|
2529 */ |
|
2530 |
|
2531 function add_new_widgets() { |
|
2532 load_plugin_textdomain('xili-language-widget',false, 'xili-language/languages'); // 1.8.8.1 fixes translation and red messages |
|
2533 register_widget('xili_Widget_Recent_Posts'); // since 1.3.2 |
|
2534 register_widget('xili_WP_Widget_Recent_Comments'); // since 1.8.3 |
|
2535 register_widget('xili_language_Widgets'); // since 1.8.3 |
1700 } |
2536 } |
1701 |
2537 |
1702 //********************************************// |
2538 //********************************************// |
1703 // Functions for themes (hookable by add_action() in functions.php - 0.9.7 |
2539 // Functions for themes (hookable by add_action() in functions.php - 0.9.7 |
1704 //********************************************// |
2540 //********************************************// |
1705 |
2541 |
1706 /** |
2542 /** |
1707 * List of available languages. |
2543 * List of available languages. |
1708 * |
2544 * |
1709 * @since 0.9.0 |
2545 * @since 0.9.0 |
1710 * @updated 0.9.7.4 - 0.9.8.3 - 0.9.9.6 |
2546 * @updated 0.9.7.4 - 0.9.8.3 - 0.9.9.6 - 1.5.5 (add class current-lang in <a>) |
|
2547 * @updated 1.6.0 - new option for nav menu hook and echoing 4th param - better permalink |
|
2548 * @updated 1.8.1 - delete 'in' prefix in list - class if LI |
1711 * can be hooked by add_action in functions.php |
2549 * can be hooked by add_action in functions.php |
1712 * with : add_action('xili_language_list','my_infunc_language_list',10,3); |
2550 * with : add_action('xili_language_list','my_infunc_language_list',10,4); |
1713 * |
2551 * |
1714 * for multiple widgets since 0.9.9.6 : incorporate top option (without flag) but with example rules |
2552 * for multiple widgets since 0.9.9.6, 1.6.0 : incorporate options |
1715 * |
2553 * |
1716 * @param $before = '<li>', $after ='</li>'. |
2554 * @param $before = '<li>', $after ='</li>'. |
1717 * @return list of languages of site for sidebar list. |
2555 * @return list of languages of site for sidebar list. |
1718 */ |
2556 */ |
1719 function xili_language_list($before = '<li>', $after ='</li>',$option='') { |
2557 function xili_language_list( $before = '<li>', $after ='</li>', $option='', $echo = true, $hidden = false ) { |
1720 $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); |
2558 global $post; |
|
2559 $lang_perma = $this->lang_perma; // since 2.1.1 |
|
2560 |
|
2561 $before_class = false ; |
|
2562 if ( substr($before,-2) == '.>' ) { // tips to add dynamic class in before |
|
2563 $before_class = true ; |
|
2564 $before = str_replace('.>','>',$before); |
|
2565 } |
|
2566 $listlanguages = $this->get_listlanguages(); |
|
2567 $a = ''; // 1.6.1 |
|
2568 |
1721 if ($option == 'typeone') { |
2569 if ($option == 'typeone') { |
1722 /* the rules : don't display the current lang if set and add link of category if is_category()*/ |
2570 /* the rules : don't display the current lang if set and add link of category if is_category()*/ |
1723 if (is_category()) { |
2571 $currenturl = $this->current_url ( $lang_perma ); // 2.5 |
1724 $catcur = xiliml_get_category_link(); |
2572 foreach ($listlanguages as $language) { |
1725 $currenturl = $catcur.'&'; |
2573 $display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ; |
|
2574 if ($language->slug != the_curlang() && $display ) { |
|
2575 $beforee = ( $before_class && $before == '<li>' ) ? '<li class="lang-'.$language->slug.'" >': $before; |
|
2576 $class = ' class="lang-'.$language->slug.'"'; |
|
2577 |
|
2578 $link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ; |
|
2579 |
|
2580 $a .= $beforee .'<a '.$class.' href="'.$link.'" title="'.__('Posts selected', $this->thetextdomain ).' '.__('in '.$language->description, $this->thetextdomain ).'" >'. __( $language->description, $this->thetextdomain ) .'</a>'.$after; |
|
2581 } |
|
2582 } |
|
2583 |
|
2584 } elseif ($option == 'typeonenew') { // 2.1.0 |
|
2585 /* the rules : don't display the current lang if set and add link of category if is_category() but display linked singular */ |
|
2586 $currenturl = $this->current_url ( $lang_perma ); // 2.5 |
|
2587 foreach ($listlanguages as $language) { |
|
2588 $display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ; |
|
2589 if ($language->slug != the_curlang() && $display ) { |
|
2590 $beforee = ( $before_class && $before == '<li>' ) ? '<li class="lang-'.$language->slug.'" >': $before; |
|
2591 $class = ' class="lang-'.$language->slug.'"'; |
|
2592 |
|
2593 if ( ( is_single() || is_page() ) && !is_front_page() ) { |
|
2594 $link = $this->link_of_linked_post ( $post->ID, $language->slug ) ; |
|
2595 $title = sprintf (__('Current post in %s', $this->thetextdomain ), __($language->description, $this->thetextdomain ) ) ; |
|
2596 } else { |
|
2597 $link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ; |
|
2598 $title = sprintf (__('Posts selected in %s', $this->thetextdomain ), __($language->description, $this->thetextdomain ) ) ; |
|
2599 } |
|
2600 |
|
2601 $a .= $beforee .'<a '.$class.' href="'.$link.'" title="'.$title.'" >'. __($language->description, $this->thetextdomain ) .'</a>' . $after; |
|
2602 } |
|
2603 } |
|
2604 |
|
2605 } elseif ($option == 'navmenu') { /* current list in nav menu 1.6.0 */ |
|
2606 if ( $lang_perma ) { |
|
2607 $currenturl = get_bloginfo('url').'/%lang%/'; |
1726 } else { |
2608 } else { |
1727 $currenturl = get_bloginfo('siteurl').'/?'; |
2609 $currenturl = get_bloginfo('url').'/?'; |
1728 } |
2610 } |
1729 foreach ($listlanguages as $language) { |
2611 foreach ($listlanguages as $language) { |
1730 if ($language->slug != $this->curlang ) { |
2612 $display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ; |
1731 $a .= $before ."<a href='".$currenturl.QUETAG."=".$language->slug."' title='".__('Website',THEME_TEXTDOMAIN)." ".__('in '.$language->description,THEME_TEXTDOMAIN)."'>". __('in '.$language->description,THEME_TEXTDOMAIN) ."</a>".$after; |
2613 if ( $display ) { |
|
2614 if ($language->slug != the_curlang() ) { |
|
2615 $class = " class='menu-item menu-item-type-custom lang-".$language->slug."'"; |
|
2616 } else { |
|
2617 $class = " class='menu-item menu-item-type-custom lang-".$language->slug." current-lang current-menu-item'"; |
|
2618 } |
|
2619 $beforee = (substr($before,-1) == '>') ? str_replace('>',' '.$class.' >' , $before ) : $before ; |
|
2620 |
|
2621 |
|
2622 $link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ; |
|
2623 |
|
2624 $a .= $beforee .'<a href="'.$link.'" title="'.__('Posts selected', $this->thetextdomain ).' '.__('in '.$language->description, $this->thetextdomain ).'" >'. __( $language->description, $this->thetextdomain ) . '</a>' . $after; |
|
2625 } |
1732 } |
2626 } |
1733 } |
2627 |
1734 echo $a; |
2628 } elseif ($option == 'navmenu-1') { // 2.1.0 and single |
1735 } else { /* current list */ |
2629 $currenturl = $this->current_url ( $lang_perma ); // 2.5 |
1736 foreach ($listlanguages as $language) { |
2630 |
1737 $a .= $before ."<a href='".get_bloginfo('siteurl')."/?".QUETAG."=".$language->slug."' title='".__('Website',THEME_TEXTDOMAIN)." ".__('in '.$language->description,THEME_TEXTDOMAIN)."'>". __('in '.$language->description,THEME_TEXTDOMAIN) ."</a>".$after; |
2631 foreach ($listlanguages as $language) { |
1738 } |
2632 $display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ; |
1739 echo $a; |
2633 if ( $display ) { |
1740 } |
2634 |
1741 } |
2635 if ($language->slug != the_curlang() ) { |
|
2636 $class = " class='menu-item menu-item-type-custom lang-".$language->slug."'"; |
|
2637 } else { |
|
2638 $class = " class='menu-item menu-item-type-custom lang-".$language->slug." current-lang current-menu-item'"; |
|
2639 } |
|
2640 |
|
2641 if ( ( is_single() || is_page() ) && !is_front_page() ) { |
|
2642 $link = $this->link_of_linked_post ( $post->ID, $language->slug ) ; |
|
2643 $title = sprintf (__('Current post in %s',the_theme_domain()), __($language->description, $this->thetextdomain) ) ; |
|
2644 } else { |
|
2645 $link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ; |
|
2646 $title = sprintf ( __('Posts selected in %s',the_theme_domain()), __($language->description, $this->thetextdomain ) ) ; |
|
2647 } |
|
2648 |
|
2649 $beforee = (substr($before,-1) == '>') ? str_replace('>',' '.$class.' >' , $before ) : $before ; |
|
2650 $a .= $beforee .'<a href="'.$link.'" title="'.$title.'" >'. __($language->description, $this->thetextdomain ) .'</a>'.$after; |
|
2651 } |
|
2652 } |
|
2653 |
|
2654 |
|
2655 } else { /* current list only root */ |
|
2656 if ( $lang_perma ) { |
|
2657 $currenturl = get_bloginfo('url').'/%lang%/'; |
|
2658 } else { |
|
2659 $currenturl = get_bloginfo('url').'/?'; |
|
2660 } |
|
2661 foreach ($listlanguages as $language) { |
|
2662 $display = ( $hidden && ( $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ) ) ? false : true ; |
|
2663 |
|
2664 if ( $display ) { |
|
2665 if ( $language->slug != the_curlang() ) { |
|
2666 $class = " class='lang-".$language->slug."'"; |
|
2667 } else { |
|
2668 $class = " class='lang-".$language->slug." current-lang'"; |
|
2669 } |
|
2670 |
|
2671 $link = ( $lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ; |
|
2672 |
|
2673 $beforee = ( $before_class && $before == '<li>' ) ? '<li class="lang-'.$language->slug.'" >': $before; |
|
2674 $a .= $beforee .'<a '.$class.' href="'.$link.'" title="'.__('Posts selected', $this->thetextdomain ).' '.__('in '.$language->description, $this->thetextdomain).'" >'. __( $language->description, $this->thetextdomain ) .'</a>' . $after; |
|
2675 } |
|
2676 } |
|
2677 } |
|
2678 if ($echo) |
|
2679 echo $a; |
|
2680 else |
|
2681 return $a; |
|
2682 } |
|
2683 |
|
2684 /** |
|
2685 * link of linked post |
|
2686 * |
|
2687 * @since 2.1.0 |
|
2688 * |
|
2689 * @updated 2.1.1 |
|
2690 */ |
|
2691 function link_of_linked_post ( $fromID, $lang_slug ) { |
|
2692 $targetpost = $this->linked_post_in ( $fromID, $lang_slug ) ; |
|
2693 if ( $targetpost ) { |
|
2694 return get_permalink($targetpost); |
|
2695 } else { |
|
2696 if ( $this->lang_perma ) { |
|
2697 $currenturl = get_bloginfo('url').'/%lang%/'; |
|
2698 } else { |
|
2699 $currenturl = get_bloginfo('url')."/?"; |
|
2700 } |
|
2701 $link = ( $this->lang_perma ) ? str_replace ( '%lang%', $lang_slug, $currenturl ) : $currenturl.QUETAG."=".$lang_slug ; |
|
2702 return $link ; |
|
2703 } |
|
2704 } |
|
2705 |
|
2706 /** |
|
2707 * For widget - the list of options above |
|
2708 * @since 1.6.0 |
|
2709 */ |
|
2710 function xili_language_list_options () { |
|
2711 $this->langs_list_options = array( array('','default'), array('typeone','Type n°1'), array('typeonenew','Type for single') ); |
|
2712 } |
|
2713 |
1742 |
2714 |
1743 /** |
2715 /** |
1744 * language of current post used in loop |
2716 * language of current post used in loop |
1745 * @since 0.9.0 |
2717 * @since 0.9.0 |
1746 * |
2718 * |
|
2719 * @updated 2.5.1 |
1747 * |
2720 * |
1748 * @param $before = '<span class"xili-lang">(', $after =')</span>'. |
2721 * @param $before = '<span class"xili-lang">(', $after =')</span>'. |
1749 * @return language of post. |
2722 * @return language of post. |
1750 */ |
2723 */ |
1751 function xili_post_language($before = '<span class="xili-lang">(', $after =')</span>') { |
2724 function xili_post_language( $before = '<span class="xili-lang">(', $after =')</span>', $type = 'iso' ) { |
1752 global $post; |
2725 global $post ; |
1753 $ress = wp_get_object_terms($post->ID, TAXONAME); |
2726 $langpost = $this->get_post_language ( $post->ID, $type ); |
1754 $obj_term = $ress[0]; |
2727 |
1755 if ('' != $obj_term->name) : |
2728 if ( '' != $langpost ) : |
1756 $curlangname = $obj_term->name; |
2729 $curlangname = $langpost; |
1757 else : |
2730 else : |
1758 $curlangname = __('undefined',THEME_TEXTDOMAIN); |
2731 $curlangname = __('undefined',$this->thetextdomain); |
1759 endif; |
2732 endif; |
1760 $a = $before . $curlangname .$after.''; |
2733 $a = $before . $curlangname .$after.''; |
1761 echo $a; |
2734 echo $a; |
1762 } |
2735 } |
1763 |
2736 |
1843 * Add list of languages in radio input - for search form. |
2816 * Add list of languages in radio input - for search form. |
1844 * |
2817 * |
1845 * @since 0.9.7 |
2818 * @since 0.9.7 |
1846 * can be hooked by add_action in functions.php |
2819 * can be hooked by add_action in functions.php |
1847 * |
2820 * |
1848 * @updated 0.9.9.5 |
2821 * @updated 0.9.9.5, 1.8.2, 2.2.0 , 2.2.2 |
1849 * |
2822 * |
1850 * $before, $after each line of radio input |
2823 * $before, $after each line of radio input |
1851 * |
2824 * |
1852 * @param $before, $after. |
2825 * @param $before, $after. |
1853 * @return echo the form. |
2826 * @return echo the form. |
1854 */ |
2827 */ |
1855 function xiliml_langinsearchform ($before='',$after='') { |
2828 function xiliml_langinsearchform ( $before='', $after='', $echo = true ) { |
1856 /* default here*/ |
2829 /* default here*/ |
|
2830 global $wp_query; |
1857 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
2831 $listlanguages = get_terms(TAXONAME, array('hide_empty' => false)); |
|
2832 $a = ''; |
1858 foreach ($listlanguages as $language) { |
2833 foreach ($listlanguages as $language) { |
1859 $a = $before.'<input type="radio" name="'.QUETAG.'" value="'.$language->slug.'" id="'.$language->slug.'" /> '.__($language->description,THEME_TEXTDOMAIN).' '.$after; |
2834 if ( is_search() ) { |
1860 echo $a; |
2835 if ( isset( $wp_query->query_vars[QUETAG] ) ) { // to rebuilt form after search query |
1861 } |
2836 $selected = ( ( $language->slug == $wp_query->query_vars[QUETAG] ) ) ? 'checked="checked"' : "" ; //2.2.2 |
1862 echo $before.'<input type="radio" name="alllang" value="yes" /> '.__('All',THEME_TEXTDOMAIN).' '.$after; // this query alllang is unused - |
2837 } else { |
|
2838 $selected = ""; |
|
2839 } |
|
2840 } else { |
|
2841 $selected = ( ( $language->slug == $this->curlang ) ) ? 'checked="checked"' : "" ; |
|
2842 } |
|
2843 $a .= $before.'<input type="radio" name="'.QUETAG.'" value="'.$language->slug.'" id="'.QUETAG.'" '.$selected.' /> '.__( $language->description, $this->thetextdomain ).' '.$after; |
|
2844 } |
|
2845 // new javascript to uncheck radio buttons on form named searchform |
|
2846 $a .= $before.'<input type="button" name="clear" onClick="var form = document.forms[\'searchform\']; |
|
2847 for (var i=0; i < form.'.QUETAG.'.length; i++) { |
|
2848 if(form.'.QUETAG.'[i].checked) { |
|
2849 form.'.QUETAG.'[i].checked = false; } }" value="'.__('All', $this->thetextdomain ).'" /> '.$after; // this to all lang query - |
|
2850 |
|
2851 |
|
2852 if ( $echo ) |
|
2853 echo $a; |
|
2854 else |
|
2855 return $a; |
|
2856 |
1863 } |
2857 } |
1864 |
2858 |
1865 /** |
2859 /** |
1866 * Select latest comments in current lang. |
2860 * Select latest comments in current lang. |
1867 * |
2861 * |
1868 * @since 0.9.9.4 |
2862 * @since 0.9.9.4 |
1869 * used by widget xili-recent-comments |
2863 * used by widget xili-recent-comments |
1870 * |
2864 * |
1871 * $before, $after each line of radio input |
2865 * @param $number. |
1872 * |
2866 * @return $comments. |
1873 * @param $before, $after. |
2867 */ |
1874 * @return echo the form. |
2868 function xiliml_recent_comments ( $number = 5 ) { |
1875 */ |
|
1876 function xiliml_recent_comments ($number = 5) { |
|
1877 global $comments, $wpdb ; |
2869 global $comments, $wpdb ; |
1878 if ( !$comments = wp_cache_get( 'xili_language_recent_comments', 'widget' ) ) { |
2870 if ( !$comments = wp_cache_get( 'xili_language_recent_comments', 'widget' ) ) { |
1879 $join = ""; |
2871 $join = ""; |
1880 $where = ""; |
2872 $where = ""; |
1881 $reqtag = is_term( $this->curlang, TAXONAME ); |
2873 $reqtag = term_exists( $this->curlang, TAXONAME ); |
1882 if (''!= $reqtag) { |
2874 if (''!= $reqtag) { |
1883 $wherereqtag = $reqtag['term_id']; |
2875 $wherereqtag = $reqtag['term_id']; |
1884 $join = " LEFT JOIN $wpdb->term_relationships as tr ON ($wpdb->comments.comment_post_ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) "; |
2876 $join = " LEFT JOIN $wpdb->term_relationships as tr ON ($wpdb->comments.comment_post_ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) "; |
1885 $where = " AND tt.taxonomy = '".TAXONAME."' "; |
2877 $where = " AND tt.taxonomy = '".TAXONAME."' "; |
1886 $where .= " AND tt.term_id = $wherereqtag "; |
2878 $where .= " AND tt.term_id = $wherereqtag "; |
1887 } |
2879 } |
1888 $query = "SELECT * FROM $wpdb->comments".$join." WHERE comment_approved = '1' ".$where." ORDER BY comment_date_gmt DESC LIMIT $number"; |
2880 $query = "SELECT * FROM $wpdb->comments".$join." WHERE comment_approved = '1' ".$where." ORDER BY comment_date_gmt DESC LIMIT $number"; |
1889 echo $query; |
2881 |
1890 $comments = $wpdb->get_results($query); |
2882 $comments = $wpdb->get_results($query); |
1891 wp_cache_add( 'xili_language_recent_comments', $comments, 'widget' ); |
2883 wp_cache_add( 'xili_language_recent_comments', $comments, 'widget' ); |
1892 } |
2884 } |
1893 return $comments; |
2885 return $comments; |
1894 } |
|
1895 |
|
1896 /** |
|
1897 * Recursive search of files in a path |
|
1898 * @since 1.1.9 |
|
1899 * @update 1.2.1 |
|
1900 * |
|
1901 */ |
|
1902 function find_files($path, $pattern, $callback) { |
|
1903 //$path = rtrim(str_replace("\\", "/", $path), '/') . '/'; |
|
1904 $matches = Array(); |
|
1905 $entries = Array(); |
|
1906 $dir = dir($path); |
|
1907 |
|
1908 while (false !== ($entry = $dir->read())) { |
|
1909 $entries[] = $entry; |
|
1910 } |
|
1911 $dir->close(); |
|
1912 foreach ($entries as $entry) { |
|
1913 $fullname = $path .$this->ossep. $entry; |
|
1914 if ($entry != '.' && $entry != '..' && is_dir($fullname)) { |
|
1915 $this->find_files($fullname, $pattern, $callback); |
|
1916 } else if (is_file($fullname) && preg_match($pattern, $entry)) { |
|
1917 call_user_func($callback, $path , $entry); |
|
1918 } |
|
1919 } |
|
1920 } |
|
1921 /** |
|
1922 * display lines of files in special sidebox |
|
1923 * @since 1.1.9 |
|
1924 */ |
|
1925 function available_mo_files($path , $filename) { |
|
1926 //echo $filename . " in : " . "/".str_replace("/","",str_replace(get_template_directory(),'',$path)) . "<br />"; |
|
1927 echo str_replace(".mo","",$filename ). " (".$this->ossep.str_replace($this->ossep,"",str_replace(get_template_directory(),'',$path)).")<br />"; |
|
1928 } |
2886 } |
1929 |
2887 |
1930 /** |
2888 /** |
1931 * Enable to add functions and filters that are not in theme's functions.php |
2889 * Enable to add functions and filters that are not in theme's functions.php |
1932 * These filters are common even if you change default theme... |
2890 * These filters are common even if you change default theme... |
1933 * Place your functions.php in folder plugins/xilidev-libraries/ |
2891 * Place your functions.php in folder plugins/xilidev-libraries/ |
1934 * if you have a filter in this file, avoid to have similar one in functions.php of the theme !!! |
2892 * if you have a filter in this file, avoid to have similar one in functions.php of the theme !!! |
1935 * |
2893 * |
1936 */ |
2894 */ |
1937 function insert_gold_functions () { |
2895 function insert_gold_functions () { |
1938 if ($this->functions_enable !='' && file_exists(XILIFUNCTIONSPATH . '/functions.php') ) |
2896 $gold_path = WP_PLUGIN_DIR . $this->xilidev_folder ; /* since 1.0 to add xili-libraries */ |
1939 include_once (XILIFUNCTIONSPATH . '/functions.php'); |
2897 if ( $this->xili_settings['functions_enable'] !='' && file_exists( $gold_path . '/functions.php') ) |
1940 } |
2898 include_once ( $gold_path . '/functions.php'); |
1941 |
2899 } |
1942 |
2900 |
1943 } /* end of xili-language class */ |
2901 /** |
1944 |
2902 * Retrieve category list in either HTML list or custom format - as in category-template - rewritten for multilingual - filter the_category only frontend |
|
2903 * |
|
2904 * @since 1.7.0 |
|
2905 * |
|
2906 * @param string $separator Optional, default is empty string. Separator for between the categories. |
|
2907 * @param string $parents Optional. How to display the parents. |
|
2908 * no third param because call by end filter |
|
2909 * @return string |
|
2910 */ |
|
2911 function xl_get_the_category_list( $thelist, $separator = '', $parents='' ) { |
|
2912 global $wp_rewrite, $post; |
|
2913 $categories = get_the_category( $post->ID ); |
|
2914 //if ( !is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) |
|
2915 //return apply_filters( 'the_category', '', $separator, $parents ); |
|
2916 |
|
2917 if ( empty( $categories ) ) { |
|
2918 return __( 'Uncategorized', $this->thetextdomain ) ; // fixed - avoid a previous recursive filter with custom @since 1.8.0 |
|
2919 } |
|
2920 $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"'; |
|
2921 |
|
2922 $thelist = ''; |
|
2923 if ( '' == $separator ) { |
|
2924 $thelist .= '<ul class="post-categories">'; |
|
2925 foreach ( $categories as $category ) { |
|
2926 $thelist .= "\n\t<li>"; |
|
2927 switch ( strtolower( $parents ) ) { |
|
2928 case 'multiple': |
|
2929 if ( $category->parent ) |
|
2930 $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
2931 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", $this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>' . __($category->name, $this->thetextdomain).'</a></li>'; |
|
2932 break; |
|
2933 case 'single': |
|
2934 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", $this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>'; |
|
2935 if ( $category->parent ) |
|
2936 $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
2937 $thelist .= __($category->name, $this->thetextdomain).'</a></li>'; |
|
2938 break; |
|
2939 case '': |
|
2940 default: |
|
2941 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", $this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>' . __($category->cat_name, $this->thetextdomain).'</a></li>'; |
|
2942 } |
|
2943 } |
|
2944 $thelist .= '</ul>'; |
|
2945 } else { |
|
2946 $i = 0; |
|
2947 foreach ( $categories as $category ) { |
|
2948 if ( 0 < $i ) |
|
2949 $thelist .= $separator; |
|
2950 switch ( strtolower( $parents ) ) { |
|
2951 case 'multiple': |
|
2952 if ( $category->parent ) |
|
2953 $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
2954 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s",$this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>' . __($category->name, $this->thetextdomain).'</a>'; |
|
2955 break; |
|
2956 case 'single': |
|
2957 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s",$this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>'; |
|
2958 if ( $category->parent ) |
|
2959 $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
2960 $thelist .= __($category->name, $this->thetextdomain)."</a>"; |
|
2961 break; |
|
2962 case '': |
|
2963 default: |
|
2964 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s",$this->thetextdomain ), __($category->name, $this->thetextdomain) ) ) . '" ' . $rel . '>' . __($category->name, $this->thetextdomain).'</a>'; |
|
2965 } |
|
2966 ++$i; |
|
2967 } |
|
2968 } |
|
2969 return $thelist; |
|
2970 } |
|
2971 |
|
2972 |
|
2973 |
|
2974 } /* **************** end of xili-language class ******************* */ |
|
2975 |
|
2976 /** |
|
2977 * called when wp_locale is declared when plugin_loaded |
|
2978 * |
|
2979 * @since 2.4 |
|
2980 * |
|
2981 */ |
|
2982 |
|
2983 function xiliml_declare_xl_wp_locale () { |
|
2984 /** |
|
2985 * special class extending wp_locale only for theme locale |
|
2986 * |
|
2987 * to work needs that locale datas and translation (a copy of those in core languages) will be in theme's po,mo files |
|
2988 * |
|
2989 * @since 2.4.0 |
|
2990 */ |
|
2991 if ( ! class_exists ( 'xl_WP_Locale' ) ) { |
|
2992 class xl_WP_Locale extends WP_locale { |
|
2993 |
|
2994 function __construct() { |
|
2995 parent::__construct(); |
|
2996 } |
|
2997 |
|
2998 function init() { |
|
2999 |
|
3000 $theme_domain = the_theme_domain(); |
|
3001 |
|
3002 // The Weekdays |
|
3003 $this->weekday[0] = /* translators: weekday */ __('Sunday', $theme_domain); |
|
3004 $this->weekday[1] = /* translators: weekday */ __('Monday', $theme_domain); |
|
3005 $this->weekday[2] = /* translators: weekday */ __('Tuesday', $theme_domain); |
|
3006 $this->weekday[3] = /* translators: weekday */ __('Wednesday', $theme_domain); |
|
3007 $this->weekday[4] = /* translators: weekday */ __('Thursday', $theme_domain); |
|
3008 $this->weekday[5] = /* translators: weekday */ __('Friday', $theme_domain); |
|
3009 $this->weekday[6] = /* translators: weekday */ __('Saturday', $theme_domain); |
|
3010 |
|
3011 // The first letter of each day. The _%day%_initial suffix is a hack to make |
|
3012 // sure the day initials are unique. |
|
3013 $this->weekday_initial[__('Sunday', $theme_domain)] = /* translators: one-letter abbreviation of the weekday */ __('S_Sunday_initial', $theme_domain); |
|
3014 $this->weekday_initial[__('Monday', $theme_domain)] = /* translators: one-letter abbreviation of the weekday */ __('M_Monday_initial', $theme_domain); |
|
3015 $this->weekday_initial[__('Tuesday', $theme_domain)] = /* translators: one-letter abbreviation of the weekday */ __('T_Tuesday_initial', $theme_domain); |
|
3016 $this->weekday_initial[__('Wednesday', $theme_domain)] = /* translators: one-letter abbreviation of the weekday */ __('W_Wednesday_initial', $theme_domain); |
|
3017 $this->weekday_initial[__('Thursday', $theme_domain)] = /* translators: one-letter abbreviation of the weekday */ __('T_Thursday_initial', $theme_domain); |
|
3018 $this->weekday_initial[__('Friday', $theme_domain)] = /* translators: one-letter abbreviation of the weekday */ __('F_Friday_initial', $theme_domain); |
|
3019 $this->weekday_initial[__('Saturday', $theme_domain)] = /* translators: one-letter abbreviation of the weekday */ __('S_Saturday_initial', $theme_domain); |
|
3020 |
|
3021 foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) { |
|
3022 $this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_); |
|
3023 } |
|
3024 |
|
3025 // Abbreviations for each day. |
|
3026 $this->weekday_abbrev[__('Sunday', $theme_domain)] = /* translators: three-letter abbreviation of the weekday */ __('Sun', $theme_domain); |
|
3027 $this->weekday_abbrev[__('Monday', $theme_domain)] = /* translators: three-letter abbreviation of the weekday */ __('Mon', $theme_domain); |
|
3028 $this->weekday_abbrev[__('Tuesday', $theme_domain)] = /* translators: three-letter abbreviation of the weekday */ __('Tue', $theme_domain); |
|
3029 $this->weekday_abbrev[__('Wednesday', $theme_domain)] = /* translators: three-letter abbreviation of the weekday */ __('Wed', $theme_domain); |
|
3030 $this->weekday_abbrev[__('Thursday', $theme_domain)] = /* translators: three-letter abbreviation of the weekday */ __('Thu', $theme_domain); |
|
3031 $this->weekday_abbrev[__('Friday', $theme_domain)] = /* translators: three-letter abbreviation of the weekday */ __('Fri', $theme_domain); |
|
3032 $this->weekday_abbrev[__('Saturday', $theme_domain)] = /* translators: three-letter abbreviation of the weekday */ __('Sat', $theme_domain); |
|
3033 |
|
3034 // The Months |
|
3035 $this->month['01'] = /* translators: month name */ __('January', $theme_domain); |
|
3036 $this->month['02'] = /* translators: month name */ __('February', $theme_domain); |
|
3037 $this->month['03'] = /* translators: month name */ __('March', $theme_domain); |
|
3038 $this->month['04'] = /* translators: month name */ __('April', $theme_domain); |
|
3039 $this->month['05'] = /* translators: month name */ __('May', $theme_domain); |
|
3040 $this->month['06'] = /* translators: month name */ __('June', $theme_domain); |
|
3041 $this->month['07'] = /* translators: month name */ __('July', $theme_domain); |
|
3042 $this->month['08'] = /* translators: month name */ __('August', $theme_domain); |
|
3043 $this->month['09'] = /* translators: month name */ __('September', $theme_domain); |
|
3044 $this->month['10'] = /* translators: month name */ __('October', $theme_domain); |
|
3045 $this->month['11'] = /* translators: month name */ __('November', $theme_domain); |
|
3046 $this->month['12'] = /* translators: month name */ __('December', $theme_domain ); |
|
3047 |
|
3048 // Abbreviations for each month. Uses the same hack as above to get around the |
|
3049 // 'May' duplication. |
|
3050 $this->month_abbrev[__('January', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Jan_January_abbreviation', $theme_domain); |
|
3051 $this->month_abbrev[__('February', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Feb_February_abbreviation', $theme_domain); |
|
3052 $this->month_abbrev[__('March', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Mar_March_abbreviation', $theme_domain); |
|
3053 $this->month_abbrev[__('April', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Apr_April_abbreviation', $theme_domain); |
|
3054 $this->month_abbrev[__('May', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('May_May_abbreviation', $theme_domain); |
|
3055 $this->month_abbrev[__('June', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Jun_June_abbreviation', $theme_domain); |
|
3056 $this->month_abbrev[__('July', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Jul_July_abbreviation', $theme_domain); |
|
3057 $this->month_abbrev[__('August', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Aug_August_abbreviation', $theme_domain); |
|
3058 $this->month_abbrev[__('September', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Sep_September_abbreviation', $theme_domain); |
|
3059 $this->month_abbrev[__('October', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Oct_October_abbreviation', $theme_domain); |
|
3060 $this->month_abbrev[__('November', $theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Nov_November_abbreviation', $theme_domain); |
|
3061 $this->month_abbrev[__('December',$theme_domain)] = /* translators: three-letter abbreviation of the month */ __('Dec_December_abbreviation', $theme_domain); |
|
3062 |
|
3063 foreach ($this->month_abbrev as $month_ => $month_abbrev_) { |
|
3064 $this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_); |
|
3065 } |
|
3066 |
|
3067 // The Meridiems |
|
3068 $this->meridiem['am'] = __('am', $theme_domain); |
|
3069 $this->meridiem['pm'] = __('pm', $theme_domain); |
|
3070 $this->meridiem['AM'] = __('AM', $theme_domain); |
|
3071 $this->meridiem['PM'] = __('PM', $theme_domain); |
|
3072 |
|
3073 // Numbers formatting |
|
3074 // See http://php.net/number_format |
|
3075 |
|
3076 /* translators: $thousands_sep argument for http://php.net/number_format, default is , */ |
|
3077 $trans = __('number_format_thousands_sep', $theme_domain); |
|
3078 $this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans; |
|
3079 |
|
3080 /* translators: $dec_point argument for http://php.net/number_format, default is . */ |
|
3081 $trans = __('number_format_decimal_point', $theme_domain); |
|
3082 $this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans; |
|
3083 |
|
3084 // test version // 2.7.1 |
|
3085 global $wp_version; |
|
3086 if ( version_compare($wp_version, '3.4', '<') ) { |
|
3087 // Import global locale vars set during inclusion of $locale.php. |
|
3088 foreach ( (array) $this->locale_vars as $var ) { |
|
3089 if ( isset($GLOBALS[$var]) ) |
|
3090 $this->$var = $GLOBALS[$var]; |
|
3091 } |
|
3092 } else { |
|
3093 // Set text direction. |
|
3094 if ( isset( $GLOBALS['text_direction'] ) ) |
|
3095 $this->text_direction = $GLOBALS['text_direction']; |
|
3096 /* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */ |
|
3097 elseif ( 'rtl' == _x( 'ltr', 'text direction', $theme_domain ) ) |
|
3098 $this->text_direction = 'rtl'; |
|
3099 |
|
3100 } |
|
3101 } |
|
3102 } } |
|
3103 } |
1945 |
3104 |
1946 /**** Functions that improve taxinomy.php ****/ |
3105 /**** Functions that improve taxinomy.php ****/ |
1947 |
3106 |
1948 /** |
3107 /** |
1949 * get terms and add order in term's series that are in a taxonomy |
3108 * get terms and add order in term's series that are in a taxonomy |