diff -r 2d410dc8c1f3 -r 8e3a5a6fc63e web/wp-content/plugins/xili-language/xili-language.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/wp-content/plugins/xili-language/xili-language.php Thu Mar 18 09:56:33 2010 +0000
@@ -0,0 +1,2406 @@
+is_metabox = $metabox;
+ $this->post_ajax = $post_ajax;
+ $this->locale_method = $locale_method; /* added for compatibility with cache plugin from johan */
+ /*activated when first activation of plug*/
+ register_activation_hook(__FILE__,array(&$this,'xili_language_activate'));
+ $this->ossep = strtoupper(substr(PHP_OS,0,3)=='WIN')?'\\':'/';
+ /*get current settings - name of taxonomy - name of query-tag - 0.9.8 new taxonomy taxolangsgroup */
+ $this->xili_settings = get_option('xili_language_settings');
+ if(empty($this->xili_settings)) {
+ $submitted_settings = array(
+ 'taxonomy' => 'language',
+ 'version' => '0.4',
+ 'reqtag' => 'lang',
+ 'browseroption' => '',
+ 'authorbrowseroption' => '',
+ 'taxolangsgroup' => 'languages_group',
+ 'functions_enable' => '',
+ 'langs_folder' => '',
+ 'theme_domain' => '',
+ 'homelang' => ''
+ );
+ define('TAXONAME','language');
+ define('QUETAG','lang');
+ define('TAXOLANGSGROUP','languages_group');
+ update_option('xili_language_settings', $submitted_settings);
+ $this->xili_settings = get_option('xili_language_settings');
+ } else {
+ define('TAXONAME',$this->xili_settings['taxonomy']);
+ define('QUETAG',$this->xili_settings['reqtag']);
+ $this->browseroption = $this->xili_settings['browseroption'];
+ $this->authorbrowseroption = $this->xili_settings['authorbrowseroption'];
+ $this->functions_enable = $this->xili_settings['functions_enable'];
+ if ($this->xili_settings['version'] == '0.2' || $this->xili_settings['version'] == '0.3') { /* 1.3.2 */
+ $this->xili_settings['taxolangsgroup'] = 'languages_group';
+ $this->xili_settings['homelang'] = '';
+ $this->xili_settings['version'] = '0.4';
+ update_option('xili_language_settings', $this->xili_settings);
+ }
+ define('TAXOLANGSGROUP',$this->xili_settings['taxolangsgroup']);
+ }
+ define('XILIFUNCTIONSPATH',WP_PLUGIN_DIR.'/xilidev-libraries'); /* since 1.0 to add xili-libraries */
+
+ /** add new taxonomy in available taxonomies
+ * 1.0.2 - add label false as http://core.trac.wordpress.org/ticket/10437
+ * to avoid metabox as tag displayed
+ */
+ register_taxonomy( TAXONAME, 'post',array('hierarchical' => false, 'label'=>false, 'rewrite' => false, 'update_count_callback' => array(&$this,'_update_post_lang_count')));
+ register_taxonomy( TAXOLANGSGROUP, 'term',array('hierarchical' => false, 'update_count_callback' => ''));
+ $thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group'));
+ if (!$thegroup) { /* update langs group 0.9.8 */
+ $args = array( 'alias_of' => '', 'description' => 'the group of languages', 'parent' => 0, 'slug' =>'the-langs-group');
+ wp_insert_term( 'the-langs-group', TAXOLANGSGROUP, $args); /* create and link to existing langs */
+ $listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
+ foreach($listlanguages as $language) {
+ wp_set_object_terms($language->term_id, 'the-langs-group', TAXOLANGSGROUP);
+ }
+ $thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group'));
+ }
+ $this->langs_group_id = $thegroup[0]->term_id;
+ $this->langs_group_tt_id = $thegroup[0]->term_taxonomy_id;
+
+ /* default values */
+ if (''!= WPLANG && strlen(WPLANG)==5) :
+ $this->default_lang = WPLANG;
+ else:
+ $this->default_lang = 'en_US';
+ endif;
+ define('DEFAULTSLUG', $this->get_default_slug());
+ if ( $dir = get_bloginfo('text_direction') ) /* if present in blog options @since 0.9.9 */
+ $this->default_dir = $dir;
+
+ add_filter('query_vars', array(&$this,'keywords_addQueryVar'));
+ add_filter('posts_join', array(&$this,'with_lang'));
+ add_filter('posts_where', array(&$this,'where_lang'));
+
+ add_action('wp', array(&$this,'xiliml_language_wp'));
+ /* 'wp' = where theme's language is defined just after query */
+ if ($this->locale_method)
+ add_filter('locale', array(&$this,'xiliml_setlocale'), 10);
+ /* to be compatible with l10n cache from Johan since 1.1.9 */
+ add_filter('language_attributes', array(&$this,'head_language_attributes'));
+ add_action('wp_head', array(&$this,'head_insert_language_metas'),10,2);
+
+ add_filter('widget_title', array(&$this,'widget_texts')); /* added 0.9.8.1 */
+ add_filter('widget_text', array(&$this,'widget_texts'));
+ add_filter('list_cats', array(&$this,'xiliml_cat_language'),10,2); /* mode 2 : content = name */
+
+ add_filter('category_link', array(&$this,'xiliml_link_append_lang'));
+ $filter = 'category_link';
+ $function = 'xiliml_link_append_lang';
+ $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 */
+
+ add_filter('category_description',array(&$this,'xiliml_link_translate_desc'));
+ add_filter('single_cat_title',array(&$this,'xiliml_single_cat_title_translate')); /* 1.4.1 wp_title() */
+ add_filter('tag_link', array(&$this,'xiliml_taglink_append_lang' ));
+
+ add_action('pre_get_posts', array(&$this,'xiliml_modify_querytag'));
+ /* filters for archives since 0.9.9.4 */
+ add_filter('getarchives_join', array(&$this,'xiliml_getarchives_join'),10,2);
+ add_filter('getarchives_where', array(&$this,'xiliml_getarchives_where'),10,2);
+ add_filter('get_archives_link', array(&$this,'xiliml_get_archives_link'));
+ /* actions for post and page admin UI */
+ add_action('save_post', array(&$this,'xili_language_add'));
+ //add_action('publish_post', array(&$this,'xili_language_add')); /* only set when published !*/
+ add_action('save_page', array(&$this,'xili_language_add'));
+ //add_action('publish_page', array(&$this,'xili_language_add'));
+ if ($this->post_ajax) {
+ add_action( 'wp_ajax_oklinked', array(&$this,'ok_linked') );
+ add_action( 'wp_ajax_customrefresh', array(&$this,'custom_refresh') );
+ }
+ /* admin settings UI*/
+ add_action('init', array(&$this, 'init_textdomain'));
+ add_filter('plugin_action_links', array(&$this,'xililang_filter_plugin_actions'), 10, 2);
+
+ add_action('admin_menu', array(&$this,'myplugin_add_custom_box'));
+ add_action('admin_menu', array(&$this,'xili_add_pages'));
+ /* special to detect theme changing since 1.1.9 */
+ add_action('switch_theme', array(&$this,'theme_switched'));
+ /* inspired from custax */
+ add_action('manage_posts_custom_column', array(&$this,'xili_manage_column'), 10, 2);
+ add_filter('manage_edit_columns', array(&$this,'xili_manage_column_name'));
+
+ add_action('manage_pages_custom_column', array(&$this,'xili_manage_column'), 10, 2);
+ add_filter('manage_edit-pages_columns', array(&$this,'xili_manage_column_name'));
+
+ /* new actions for xili-language theme's templates tags */
+
+ $this->add_action('xili_language_list','xili_language_list',10,3); /* add third param 0.9.7.4*/
+ $this->add_action('xili_post_language','xili_post_language',10,2);
+
+ $this->add_action('xiliml_the_other_posts','xiliml_the_other_posts',10,4); /* add a param 1.1 */
+ $this->add_action('xiliml_the_category','xiliml_the_category',10,3);
+ $this->add_action('xiliml_langinsearchform','xiliml_langinsearchform',10,2);
+
+ }
+
+ function add_action ($action, $function = '', $priority = 10, $accepted_args = 1)
+ {
+ add_action ($action, array (&$this, $function == '' ? $action : $function), $priority, $accepted_args);
+ $this->idx[$action] = _wp_filter_build_unique_id($action, array (&$this, $function == '' ? $action : $function), $priority); /* unique id of this filter from object */
+ }
+
+ function add_filter ($filter, $function = '', $priority = 10, $accepted_args = 1)
+ {
+ add_filter ($filter, array (&$this, $function == '' ? $filter : $function), $priority, $accepted_args);
+ $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 */
+ }
+
+ /**
+ * More than one filter for the function.
+ *
+ * @since 0.9.7
+ *
+ * @param $the_function (string).
+ * @return true if more than one.
+ */
+ function this_has_filter($the_function) {
+ global $wp_filter;
+ $has = $wp_filter[$the_function];
+ //print_r($has);
+ $keys = array_keys($has);
+ //echo count($has[$keys[0]]);
+ if (count($has[$keys[0]]) >= 2) { /*one from class others from functions.php or elsewhere*/
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function myplugin_add_custom_box() {
+ add_meta_box('xilil-2', __("Page's language",'xili-language'), array(&$this,'xili_language_checkboxes_n'), 'page', 'side','high');
+ add_meta_box('xilil-2', __("Post's language",'xili-language'), array(&$this,'xili_language_checkboxes_n'), 'post', 'side','high');
+ if ($this->is_metabox) {
+ add_meta_box('xilil-1', __('Linked posts','xili-language'), array(&$this,'xili_language_linked_posts'), 'post', 'side','high');
+ add_meta_box('xilil-1', __('Linked pages','xili-language'), array(&$this,'xili_language_linked_posts'), 'page', 'side','high');
+ }
+ }
+
+ /**
+ * Will update term count based on posts AND pages.
+ *
+ * @access private from register taxonomy etc...
+ * @since 0.9.8.1
+ * @uses $wpdb
+ *
+ * @param array $terms List of Term taxonomy IDs
+ */
+ function _update_post_lang_count( $terms ) {
+ global $wpdb;
+ foreach ( (array) $terms as $term ) {
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND term_taxonomy_id = %d", $term ) );
+ $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
+ }
+ }
+
+ /**
+ * set language when post or page is saved or changed
+ *
+ * @since 0.9.0
+ * @completed 0.9.7.1 to record postmeta of linked posts in other languages
+ * @updated 0.9.7.5 to delete relationship when undefined
+ * @updated 0.9.9 to avoid delete relationship when in quick_edit
+ * @updated 1.3.0 to avoid delete relationship when trashing - 1.4.1 - create post-meta xl-search-linked
+ * @param $post_ID
+ */
+ function xili_language_add($post_ID) {
+ if (!isset($_POST['_inline_edit'])) { /* to avoid delete relationship when in quick_edit (edit.php) */
+ $sellang = $_POST['xili_language_set'];
+ if ("" != $sellang) {
+ wp_set_object_terms($post_ID, $sellang, TAXONAME);
+ } else {
+ if ($_GET['action'] != 'trash' && $_GET['action'] != 'untrash')
+ wp_delete_object_term_relationships( $post_ID, TAXONAME );
+ }
+ if ($this->is_metabox) {
+ /* the linked posts set by author */
+ $listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
+ foreach ($listlanguages as $language) {
+ $inputid = 'xili_language_'.QUETAG.'-'.$language->slug ;
+ $recinputid = 'xili_language_rec_'.QUETAG.'-'.$language->slug ;
+ $linkid = $_POST[$inputid];
+ $reclinkid = $_POST[$recinputid]; /* hidden previous value */
+ $langslug = QUETAG.'-'.$language->slug ;
+
+ if ($reclinkid != $linkid) { /* only if changed value or created since 1.3.0 */
+ if ((is_numeric($linkid) && $linkid == 0) || '' == $linkid ) {
+ delete_post_meta($post_ID, $langslug);
+ } elseif (is_numeric($linkid) && $linkid > 0) {
+ update_post_meta($post_ID, $langslug, $linkid);
+ if ($reclinkid == "-1") update_post_meta($linkid, QUETAG.'-'.$sellang, $post_ID);
+ }
+ }
+ }
+ //if (isset($_POST['xili_language_search_lang'])) {
+ if ('' != $_POST['xili_language_search_lang']) {
+ update_post_meta($post_ID, '_xl-search-linked', $_POST['xili_language_search_lang']);
+ } else {
+ if ($_GET['action'] != 'trash' && $_GET['action'] != 'untrash')
+ delete_post_meta($post_ID, '_xl-search-linked');
+ }
+ //}
+
+ }
+ } /* quick edit */
+ }
+
+ /**
+ * Return language dir
+ *
+ * @since 0.9.9
+ * @param slug of lang
+ */
+ function get_dir_of_cur_language($lang_slug) {
+ $rtlarray = explode ('-',$this->rtllanglist);
+ $dir = (in_array(substr(strtolower($lang_slug),0,2),$rtlarray)) ? 'rtl' : 'ltr';
+ return $dir;
+ }
+
+ /**
+ * Return language of post.
+ *
+ * @since 0.9.0
+ * @updated 0.9.7.6, 0.9.9
+ *
+ * @param $post_ID.
+ * @return slug of language of post or false if var langstate is false.
+ */
+ function get_cur_language($post_ID) {
+ $ress = wp_get_object_terms($post_ID, TAXONAME);
+ if ($ress) {
+ if (is_a($ress, 'WP_Error')){
+ echo "Language table not created ! see plug-in admin";
+ $this->langstate = false;
+ } else {
+ $obj_term = $ress[0];
+ $this->langstate = true;
+ $postlang = $obj_term->slug;
+ $postlangdir = $this->get_dir_of_cur_language($postlang);
+ return array('lang'=>$postlang,'direction'=>$postlangdir);
+ }
+ } else {
+ $this->langstate = false; /* can be used in language attributes for header */
+ return false; /* undefined state */
+ }
+ }
+
+ /* first activation of plugin */
+ function xili_language_activate() {
+ $this->xili_settings = get_option('xili_language_settings');
+ if(empty($this->xili_settings)) {
+ $this->xili_settings = array(
+ 'taxonomy' => 'language',
+ 'version' => '0.4',
+ 'reqtag' => 'lang',
+ 'browseroption' => '',
+ 'authorbrowseroption' => '',
+ 'taxolangsgroup' => 'languages_group',
+ 'functions_enable' => '',
+ 'langs_folder' => '',
+ 'theme_domain' => '',
+ 'homelang' => ''
+ );
+ update_option('xili_language_settings', $this->xili_settings);
+ }
+ }
+
+ /*enable the new query tag associated with new taxonomy*/
+ function keywords_addQueryVar($vars) {
+ $vars[] = QUETAG;
+ return $vars ;
+ }
+
+ function get_default_slug() {
+ $listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
+ $default_slug = 'en_us';
+ foreach ($listlanguages as $language) {
+ if ($language->name == $this->default_lang ) return $language->slug;
+ }
+ return $default_slug ;
+ }
+
+ /**
+ * filters used when querytag is used -
+ * see below and functions.php where rules depend from theme
+ */
+ function with_lang($join) {
+ global $wp_query, $wpdb;
+ if ( '' != $wp_query->query_vars[QUETAG] ) {
+ $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) ";
+ }
+
+ return $join;
+ }
+
+ /**
+ * Setup global post data.
+ *
+ * @since 0.9.0
+ * @updated 0.9.4 (OR added) lang=xx_xx,yy_yy,..
+ *
+ * @param object $where.
+ * @return $where.
+ */
+ function where_lang($where) {
+ global $wp_query , $wpdb;
+ $reqtags = array();
+ $thereqtags = array();
+ if ( '' != $wp_query->query_vars[QUETAG] ) {
+ /* one or more lang - no + because only one lang per post now */
+ if ( strpos($wp_query->query_vars[QUETAG], ',') !== false ) {
+ $langs = preg_split('/[,\s]+/', $wp_query->query_vars[QUETAG]);
+ foreach ( (array) $langs as $lang ) {
+ $lang = sanitize_term_field('slug', $lang, 0, 'post_tag', 'db');
+ $reqtags[]= $lang;
+ }
+
+ foreach ($reqtags as $reqtag){
+ $reqtagt = is_term( $reqtag, TAXONAME );
+ if ($reqtagt)
+ $thereqtags[] = $reqtagt['term_id'];
+ }
+
+ $wherereqtag = implode(", ", $thereqtags);
+ $where .= " AND tt.taxonomy = '".TAXONAME."' ";
+ $where .= " AND tt.term_id IN ( $wherereqtag )";
+
+ } else {
+ /* only one lang */
+ $wp_query->query_vars[QUETAG] = sanitize_term_field('slug', $wp_query->query_vars[QUETAG], 0, 'post_tag', 'db');
+ $reqtag = $wp_query->query_vars[QUETAG];
+ $reqtag = is_term( $reqtag, TAXONAME );
+ if (''!= $reqtag) {
+ $wherereqtag = $reqtag['term_id'];
+ } else {
+ $wherereqtag = 0;
+ }
+ $where .= " AND tt.taxonomy = '".TAXONAME."' ";
+ $where .= " AND tt.term_id = $wherereqtag ";
+ }
+
+ }
+ return $where;
+ }
+
+ /******** template theme live modifications ********/
+
+ /**
+ * wp action for theme at end of query
+ *
+ * @since 0.9.0
+ * @updated 1.1.9
+ * can be hooked in functions.php xiliml_cur_lang_head
+ * call by wp hook
+ *
+ */
+ function xiliml_language_wp() {
+ $this->curlang = $this->xiliml_cur_lang_head();
+ $this->curlang_dir = $this->get_dir_of_cur_language($this->curlang); /* general dir of the theme */
+ if (!defined('THEME_TEXTDOMAIN')) _e('xili-language plugin : THEME_TEXTDOMAIN UNDEFINED','xili-language'); /* here because not visible in admin UI */
+
+ if ($this->locale_method) {
+ $this->xiliml_load_theme_textdomain (THEME_TEXTDOMAIN); /* new method for cache compatibility - tests */
+ } else {
+ $this->set_mofile($this->curlang);
+ }
+ }
+
+ /**
+ * locale hook when load_theme_textdomain is present in functions.php
+ *
+ * @since 1.1.9
+ *
+ * call by locale hook
+ */
+ function xiliml_setlocale ($locale) {
+ if ($this->theme_locale === true) {
+ $listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $this->curlang));
+ return $listlanguages[0]->name;
+ } else {
+ return $locale;
+ }
+ }
+
+ /**
+ * locale hook when load_theme_textdomain is present in functions.php
+ *
+ * @since 1.1.9
+ *
+ * call by locale hook
+ */
+ function xiliml_load_theme_textdomain ($domain) {
+ $this->theme_locale = true;
+ $langfolder = (defined('THEME_LANGS_FOLDER')) ? THEME_LANGS_FOLDER : $this->xili_settings['langs_folder'];
+ $langfolder = '/'.str_replace("/","",$langfolder); /* please no lang folder in sub-subfolder */
+ $langfolder = ($langfolder == "/") ? "" : $langfolder;
+ load_theme_textdomain($domain, get_template_directory() . $langfolder);
+ $this->theme_locale = false;
+ }
+
+ /**
+ * select .mo file
+ * @since 0.9.0
+ * @updated 0.9.7.1 - 1.1.9
+ * call by function xiliml_language_wp()
+ * @param $curlang .
+ */
+ function set_mofile($curlang) {
+ // load_theme_textdomain(THEME_TEXTDOMAIN); - replaced to be flexible -
+ if (defined('THEME_TEXTDOMAIN')) {$themetextdomain = THEME_TEXTDOMAIN; } else {$themetextdomain = 'ttd-not-defined'; }
+ $langfolder = (defined('THEME_LANGS_FOLDER')) ? THEME_LANGS_FOLDER : $this->xili_settings['langs_folder'];
+ $langfolder = '/'.str_replace("/","",$langfolder); /* please no lang folder in sub-subfolder */
+ $langfolder = ($langfolder == "/") ? "" : $langfolder;
+ $listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $curlang));
+ $filename = $listlanguages[0]->name;
+ $filename .= '.mo';
+ if ('' != $filename) {
+ $mofile = get_template_directory() .$langfolder."/$filename";
+ load_textdomain($themetextdomain,$mofile);
+ }
+ }
+
+ /**
+ * default rules - set curlang in head according rules
+ *
+ * @since 0.9.7
+ * @updated 0.9.7.1 - if no posts 0.9.9.1 - 0.9.9.4
+ * @updated 1.3.2 - Option for home.php
+ *
+ * default filter of xiliml_cur_lang_head
+ * @return $curlang .
+ */
+ function xiliml_cur_lang_head () {
+ if (has_filter('xiliml_cur_lang_head')) return apply_filters('xiliml_cur_lang_head',''); /* '' warning on some server need one arg by default*/
+ /* default */
+ global $post,$wp_query, $query_string;
+ if (have_posts()) {
+ if(!is_front_page()) { /* every pages */
+ $curlangdir = $this->get_cur_language($post->ID);
+ $curlang = $curlangdir['lang']; /* the first post give the current lang*/
+ if ($curlangdir == false) $curlang = DEFAULTSLUG; /* can be changed if use hook */
+ if (is_page()) {
+ if (isset($_GET["loclang"])) {
+ $curlang=$_GET["loclang"];
+ /* get var to override the selected lang - ex. in bi-lingual contact*/
+ }
+ }
+ elseif (is_search() && isset($_GET["lang"])) {
+ $curlang=$_GET["lang"]; /*useful when no result*/
+ }
+ } else { /* front page */
+ if ( '' != $wp_query->query_vars[QUETAG] ) {
+ $curlang = $wp_query->query_vars[QUETAG]; /* home series type*/
+ } else {
+ $showpage = get_settings('show_on_front');
+ $page_front = get_settings('page_on_front');
+ $hcurlang = (isset($_GET["hlang"])) ? $_GET["hlang"] : $this->choice_of_browsing_language() ;
+ $target = get_post_meta($page_front, 'lang-'.$hcurlang, true);
+ if ($showpage == "page") {
+ if ($target && $target != $post->ID) { /* only if present and diff */
+ query_posts('page_id='.$target);
+ if (have_posts()) {
+ the_post();
+ $curlang = get_cur_language($post->ID);
+ rewind_posts();
+ } else {
+ query_posts('page_id='.$page_front); /* restore */
+ $curlang = get_cur_language($page_front);
+ }
+ } else {
+ $curlang = get_cur_language($post->ID);
+ }
+ } else { /* home.php - 1.3.2 */
+ $curlang = $this->choice_of_browsing_language();
+ if ($this->xili_settings['homelang'] == 'modify') query_posts($query_string."&lang=".$curlang);
+ }
+ }
+ }
+ } else { /*no posts for instance in category + lang */
+ if (isset($_GET["lang"])) {
+ $curlang=$_GET["lang"];
+ } else {
+ $curlang = $this->choice_of_browsing_language();//strtolower(WPLANG); /* select here the default language of the site */
+ }
+ }
+ return $curlang; /* as in external hook for filter*/
+ }
+
+ /**
+ * modify language_attributes() output
+ *
+ * @since 0.9.7.6
+ *
+ * The - language_attributes() - template tag is use in header of theme file in html tag
+ *
+ * @param $output
+ */
+ function head_language_attributes($output) {
+ /* hook head_language_attributes */
+ if (has_filter('head_language_attributes')) return apply_filters('head_language_attributes',$output);
+ $attributes = array();
+ $output = '';
+
+ if ( $dir = get_bloginfo('text_direction') ) /*use hook for future use */
+ $attributes[] = "dir=\"$dir\"";
+ if ($this->langstate == true) {
+ $lang = str_replace('_','-',substr($this->curlang,0,3).strtoupper(substr($this->curlang,-2)));
+ } else {
+ //use hook if you decide to display limited list of languages for use by instance in frontpage
+ $listlang = array();
+ //$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
+ $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
+ foreach ($listlanguages as $language) {
+ $listlang[] = str_replace('_','-',$language->name);
+ }
+ $lang = $listlang[0]; // implode(', ',$listlang); // not w3c compatible
+ }
+ if ( get_option('html_type') == 'text/html')
+ $attributes[] = "lang=\"$lang\"";
+
+ if ( get_option('html_type') != 'text/html')
+ $attributes[] = "xml:lang=\"$lang\"";
+
+ $output = implode(' ', $attributes);
+ return $output;
+ }
+
+ /**
+ * modify insert language metas in head (via wp_head)
+ *
+ * @since 0.9.7.6
+ * @updated 1.1.8
+ * @must be defined in functions.php according general theme design (wp_head)
+ *
+ * @param $curlang
+ */
+ function head_insert_language_metas($curlang,$undefined=true) {
+ $curlang = $this->curlang;
+ $undefined = $this->langstate;
+ echo "\n";
+ if (has_filter('head_insert_language_metas')) return apply_filters('head_insert_language_metas',$curlang,$undefined);
+ }
+
+ /**
+ * Translate texts of widgets
+ *
+ * @since 0.9.8.1
+ * @ return
+ */
+ function widget_texts ($value){
+ return __($value,THEME_TEXTDOMAIN);
+ }
+
+ /**
+ * insert other language of wp_list_categories
+ *
+ * @since 0.9.0
+ * @updated 0.9.8.4 - 1.4.1 = no original term in ()
+ * can be hooked by filter add_filter('xiliml_cat_language','yourfunction',2,3) in functions.php
+ * call by do_filter list_cats
+ * @param $content, $category
+ */
+ function xiliml_cat_language ($content, $category = null) {
+ if (has_filter('xiliml_cat_language')) return apply_filters('xiliml_cat_language',$content, $category,$this->curlang);
+ $new_cat_name = (!is_admin()) ? __($category->name,THEME_TEXTDOMAIN) : $content ; /*to detect admin UI*/
+ return $new_cat_name;
+ }
+
+ /**
+ * add the language key in category links of current pages
+ *
+ * @since 0.9.0
+ * update 0.9.7
+ * can be hooked by filter add_filter('xiliml_link_append_lang','yourfunction',10,2) in functions.php
+ * call by do_filter
+ * @param $content,
+ */
+ function xiliml_link_append_lang( $link ) {
+ if (has_filter('xiliml_link_append_lang')) return apply_filters('xiliml_link_append_lang',$link,$this->curlang);
+ /*default*/
+ if ($this->curlang) :
+ $link .= '&'.QUETAG.'='.$this->curlang ;
+ endif;
+
+ return $link;
+ }
+
+ /**
+ * Setup global post data.
+ *
+ * @since 0.9.4
+ * update 0.9.7
+ * can be hooked by filter add_filter('xiliml_taglink_append_lang','yourfunction',2,3) in functions.php
+ *
+ * @param $taglink, $tag_id.
+ * @return $taglink.
+ */
+ function xiliml_taglink_append_lang ( $taglink, $tag_id=null ) {
+ if (has_filter('xiliml_taglink_append_lang')) return apply_filters('xiliml_taglink_append_lang',$taglink,$tag_id,$this->curlang);
+ /* no yet default */
+ /* global $curlang;
+
+ if ($curlang) :
+ $taglink .= '&'.QUETAG.'='.$curlang ;
+ endif;
+
+ */
+ return $taglink;
+ }
+
+ /**
+ * to cancel sub select by lang in cat 1 by default
+ *
+ * @since 0.9.2
+ * update 0.9.7
+ * can be hooked by filter add_filter('xiliml_modify_querytag','yourfunction') in functions.php
+ *
+ *
+ */
+ function xiliml_modify_querytag() {
+ if (has_filter('xiliml_modify_querytag')) {
+ apply_filters('xiliml_modify_querytag','');
+ } else {
+ /*default*/
+ global $wp_query;
+ if (!defined('XILI_CATS_ALL')) define('XILI_CATS_ALL','1'); /* change in functions.php or use hook in cat 1 by default*/
+ $excludecats = explode(",", XILI_CATS_ALL);
+ if (!empty($wp_query->query_vars['cat'])) {
+ if (in_array($wp_query->query_vars['cat'],$excludecats)) {
+ $wp_query->query_vars[QUETAG] = ""; /* to cancel sub select */
+ }
+ }
+ }
+ }
+ /**
+ * filters for wp_get_archives
+ *
+ * @since 0.9.2
+ * @params $join or $where and template params
+ *
+ */
+ function xiliml_getarchives_join($join,$r) {
+ global $wpdb;
+ if (has_filter('xiliml_getarchives_join')) return apply_filters('xiliml_getarchives_join',$join,$r,$this->curlang);
+ extract( $r, EXTR_SKIP );
+ $this->get_archives_called = $r;
+ if (isset($lang)) {
+ if ("" == $lang ) { /* used for link */
+ $this->get_archives_called['lang'] = $this->curlang;
+ } else {
+ $this->get_archives_called['lang'] = $lang;
+ }
+ $join = " INNER JOIN $wpdb->term_relationships as tr ON ($wpdb->posts.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) ";
+
+ }
+ return $join;
+
+ }
+
+ function xiliml_getarchives_where($where,$r) {
+ global $wpdb;
+ if (has_filter('xiliml_getarchives_where')) return apply_filters('xiliml_getarchives_where',$where,$r,$this->curlang);
+ extract( $r, EXTR_SKIP );
+ if (isset($lang)) {
+ if ("" == $lang ) {
+ $curlang = $this->curlang;
+ } else {
+ $curlang = $lang;
+ }
+ $reqtag = is_term( $curlang, TAXONAME );
+ if (''!= $reqtag) {
+ $wherereqtag = $reqtag['term_id'];
+ } else {
+ $wherereqtag = 0;
+ }
+ $where .= " AND tt.taxonomy = '".TAXONAME."' ";
+ $where .= " AND tt.term_id = $wherereqtag ";
+ }
+ return $where;
+ }
+
+ /* here basic translation - to improve depending theme features : use hook 'xiliml_get_archives_link' */
+ function xiliml_get_archives_link($link_html) {
+ if (has_filter('xiliml_link_translate_desc')) return apply_filters('xiliml_get_archives_link', $link_html,$this->get_archives_called, $this->curlang);
+ extract( $this->get_archives_called, EXTR_SKIP );
+ if ('' != $lang) {
+ $permalink = get_option('permalink_structure');
+ $sep = ('' == $permalink) ? "&lang=" : "?lang=";
+ if ($format != 'option' && $format != 'link' && $type != 'postbypost' && $type != 'alpha') {
+ /* text extract */
+ $i = preg_match_all("/'>(.*)<\/a>/Ui", $link_html, $matches,PREG_PATTERN_ORDER);
+ $line = $matches[1][0];
+ /* link extract */
+ $i = preg_match_all("/href='(.*)' title/Ui", $link_html, $matches,PREG_PATTERN_ORDER);
+ if ( '' == $type || 'monthly' == $type) {
+ if ('' == $permalink) {
+ $archivedate = str_replace(get_bloginfo('siteurl').'/?' , "" , $matches[1][0]);
+ $r = wp_parse_args( $archivedate, array());
+ extract($r, EXTR_SKIP );
+ $month = substr($m,-2);
+ $year = substr($m,0,4);
+ } else {
+ /* Due to prevents post ID and date permalinks from overlapping using /date/ v 1.1.9
+ * no / at end for "numeric" permalink giving /archives/date/2009/04
+ */
+ $thelink = $matches[1][0];
+ $i = preg_match_all("/\/([0-9]{4})\/([0-9]{2})/Ui", $thelink, $results,PREG_PATTERN_ORDER);
+ if ($i) { //print_r($results);
+ $month = $results[2][0];
+ $year = $results[1][0];
+ }
+ }
+ $time = strtotime($month.'/1/'.$year);
+ $line2print = the_xili_local_time('%B %Y',$time); /* use server local*/
+ $link_html = str_replace($line , $line2print , $link_html);
+ }
+ $link_html = str_replace("' titl" , $sep.$lang."' titl" , $link_html);
+ } elseif ($format == 'option') {
+ /* need improve with regex */
+ $link_html = str_replace("'>" , $sep.$lang."'>" , $link_html);
+ }
+ }
+ return $link_html;
+ }
+
+ /**
+ * translate description of categories
+ *
+ * @since 0.9.0
+ * update 0.9.7 - 0.9.9.4
+ * can be hooked by filter add_filter('xiliml_link_translate_desc','yourfunction',2,4) in functions.php
+ *
+ *
+ */
+ function xiliml_link_translate_desc( $description, $category=null,$context='') {
+ if (has_filter('xiliml_link_translate_desc')) return apply_filters('xiliml_link_translate_desc',$description,$category,$context,$this->curlang);
+ $translated_desc = ($this->curlang && ''!= $description) ? __($description,THEME_TEXTDOMAIN) : $description ;
+ return $translated_desc;
+ }
+
+ /**
+ * filters for wp_title() translation - single_cat_title -
+ * since 1.4.1
+ *
+ */
+ function xiliml_single_cat_title_translate ($cat_name) {
+ if (has_filter('xiliml_single_cat_title_translate')) return apply_filters('xiliml_single_cat_title_translate',$cat_name);
+ $translated = ($this->curlang && ''!= $cat_name) ? __($cat_name,THEME_TEXTDOMAIN) : $cat_name;
+ return $translated;
+ }
+
+ /**
+ * Return the list of preferred languages for displaying pages (see in firefox prefs)
+ * thanks to php.net comments HTTP_ACCEPT_LANGUAGE
+ * @since 0.9.7.5
+ *
+ * @return array (non sorted)
+ */
+ function the_preferred_languages() {
+ $preferred_languages = array();
+ if(preg_match_all("#([^;,]+)(;[^,0-9]*([0-9\.]+)[^,]*)?#i",$_SERVER["HTTP_ACCEPT_LANGUAGE"], $matches, PREG_SET_ORDER)) {
+ foreach($matches as $match) {
+ $preferred_languages[$match[1]] = floatval($match[3]);
+ if($match[3]==NULL) $preferred_languages[$match[1]] = 1.0;
+ }
+ return $preferred_languages;
+ } else {
+ return false;
+ }
+ }
+ /**
+ * Return the lang defined by admin UI if no browser
+ *
+ * @since 1.0
+ *
+ */
+ function choice_of_home_selected_lang() {
+ if ($this->browseroption == 'browser') {
+ return choice_of_browsing_language();
+ } elseif ($this->browseroption != '') { /* slug of the lang*/
+ return $this->browseroption;
+ } else {
+ return strtolower($this->default_lang);
+ }
+ }
+
+ /**
+ * Return the list of preferred languages for displaying pages (see in firefox prefs)
+ * thanks to php.net comments HTTP_ACCEPT_LANGUAGE
+ * @since 0.9.7.5
+ * @update 0.9.9.4
+ * @return array (non sorted)
+ */
+ function choice_of_browsing_language() {
+ if (has_filter('choice_of_browsing_language')) return apply_filters('choice_of_browsing_language');
+ if ($this->browseroption != 'browser') return $this->choice_of_home_selected_lang(); /* in settings UI - after filter to hook w/o UI */
+ $listofprefs = $this->the_preferred_languages();
+ if (is_array($listofprefs)) {
+ arsort($listofprefs, SORT_NUMERIC);
+ $listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
+ $sitelanguage = $this->match_languages ($listofprefs,$listlanguages);
+ if ($sitelanguage) return $sitelanguage->slug;
+ return strtolower($this->default_lang);
+ } else {
+ return strtolower($this->default_lang);
+ }
+ }
+
+ function match_languages ($listofprefs,$listlanguages) {
+
+ foreach($listofprefs as $browserlanguage => $priority) {
+ /* match root languages to give similar in site - first : five chars langs*/
+ foreach($listlanguages as $sitelanguage) {
+ if ($sitelanguage->slug == str_replace('-','_',$browserlanguage)) return $sitelanguage;
+ }
+ }
+ foreach($listofprefs as $browserlanguage => $priority) {
+ /* match root languages to give similar in site - second : two first chars langs*/
+ foreach($listlanguages as $sitelanguage) {
+ if (str_replace('-','_',$browserlanguage) == substr($sitelanguage->slug,0,2)) return $sitelanguage;
+ }
+ }
+ }
+
+ /********************************** ADMIN UI ***********************************/
+
+ /**
+ * add admin menu and associated pages of admin UI
+ *
+ * @since 0.9.0
+ * @updated 0.9.6 - only for WP 2.7.X - do registering of new meta boxes and JS
+ *
+ */
+ function xili_add_pages() {
+ $this->thehook = add_options_page(__('Languages','xili-language'), __('Languages','xili-language'), 'manage_options', 'language_page', array(&$this,'languages_settings'));
+ add_action('load-'.$this->thehook, array(&$this,'on_load_page'));
+ }
+
+ function on_load_page() {
+ wp_enqueue_script('common');
+ wp_enqueue_script('wp-lists');
+ wp_enqueue_script('postbox');
+ add_meta_box('xili-language-sidebox-1', __('Message','xili-language'), array(&$this,'on_sidebox_1_content'), $this->thehook , 'side', 'core');
+ add_meta_box('xili-language-sidebox-2', __('Info','xili-language'), array(&$this,'on_sidebox_2_content'), $this->thehook , 'side', 'core');
+ add_meta_box('xili-language-sidebox-4', __('Special','xili-language'), array(&$this,'on_sidebox_4_content'), $this->thehook , 'side', 'core');
+
+ }
+
+ /**
+ * Add action link(s) to plugins page
+ *
+ * @since 0.9.3
+ * @author MS
+ * @copyright Dion Hulse, http://dd32.id.au/wordpress-plugins/?configure-link and scripts@schloebe.de
+ */
+ function xililang_filter_plugin_actions($links, $file){
+ static $this_plugin;
+ if( !$this_plugin ) $this_plugin = plugin_basename(__FILE__);
+ if( $file == $this_plugin ){
+ $settings_link = '' . __('Settings') . '';
+ $links = array_merge( array($settings_link), $links); // before other links
+ }
+ return $links;
+ }
+
+ /* UI added in sidebar of post admin (write , edit)
+ *
+ * @since 0.9.0
+ * @updated 0.9.5 : add a no-lang radio - again in top of sidebar admin post's UI
+ * @updated 0.9.8.3 : if new post and checked in settings : default language = author's browser's language !
+ * @updated 1.3.0
+ */
+ function xili_language_checkboxes_n() {
+ global $post_ID ;
+ //$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
+ $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
+ if ($this->authorbrowseroption == 'authorbrowser') { // setting = select language of author's browser
+ $listofprefs = $this->the_preferred_languages();
+ if (is_array($listofprefs)) {
+ arsort($listofprefs, SORT_NUMERIC);
+ $sitelanguage = $this->match_languages ($listofprefs,$listlanguages);
+ if ($sitelanguage) {
+ $defaultlanguage = $sitelanguage->name;
+ } else {
+ $defaultlanguage = "";
+ }
+ $mention = '('.__('Browser language', 'xili-language').')';
+ } else {
+ $defaultlanguage = ""; /* undefined */
+ }
+ } else {
+ $defaultlanguage = ""; /* undefined */
+ $mention = "";
+ }
+
+ if(0 != $post_ID){
+ $ress = wp_get_object_terms($post_ID, TAXONAME);
+
+ /*Array ( [0] => stdClass Object ( [term_id] => 18 [name] => [slug] => 18 [term_group] => 0 [term_taxonomy_id] => 19 [taxonomy] => language [description] => [parent] => 0 [count] => 1 ) )*/
+ $obj_term = $ress[0];
+ if ('' != $obj_term->name) :
+ $curlangname = $obj_term->name;
+ else :
+ $curlangname = ""; /* when created before plugin */
+ endif;
+
+ } else {
+ if (isset($_GET['xltgt_lang'])) {
+ $curlangname = $_GET['xltgt_lang']; /* since 1.3.0 */
+ $mention = '
('.__('From other post', 'xili-language').': '.$_GET['xlfrom_id'].' '.$_GET['xlfrom_lang'].')';
+ } else {
+ $curlangname = $defaultlanguage; /* new post */
+ }
+ }
+ echo __('Selected language', 'xili-language').' : '.$curlangname.' '.((0 == $post_ID) ? $mention : "").'
' ; /*link to bottom of sidebar*/
+ foreach ($listlanguages as $language) { ?>
+
+
+
+
+
© xili-language
+ slug) ? $obj_term->slug : ""; /* when created before plugin */
+ } else {
+ $postlang = ""; /* new post */
+ }
+ //$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
+ $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC');
+ if ($post->post_type == 'post') { ?>
+
+
+ +
| + | + + | "." ".__($language->description,'xili-language') ." | "." ".__('Edit') ." |
|---|---|---|---|
| /> | |||
All is OK '.$post_id.' ('.$mess.')
'; // voir bannière // + die(); + + } + + /** + * to display the languages settings admin UI + * + * @since 0.9.0 + * @updated 0.9.6 - only for WP 2.7.X - do new meta boxes and JS + * + */ + function languages_settings() { + $formtitle = 'Add a language'; /* translated in form */ + $submit_text = __('Add »','xili-language'); + $cancel_text = __('Cancel'); + + if (isset($_POST['reset'])) { + $action=$_POST['reset']; + } elseif (isset($_POST['updateoptions'])) { + $action='updateoptions'; + } elseif (isset($_POST['updateundefined'])) { + $action='updateundefined'; + + } elseif (isset($_POST['action'])) { + $action=$_POST['action']; + } + + if (isset($_GET['action'])) : + $action=$_GET['action']; + $term_id = $_GET['term_id']; + endif; + $message = $action ; + switch($action) { + case 'updateundefined'; + $targetlang = $_POST['xili_language_toset']; + $fromcats = $_POST['from_categories']; + if (""!= $targetlang) { + $q = xiliml_setlang_of_undefined_posts ($targetlang, $fromcats, 50); + $message .= " _ $q ".__('posts are set in:','xili-language')." ".$targetlang." ".__("category")." =[$fromcats]"; + } else { + $q = xiliml_setlang_of_undefined_posts ($targetlang, $fromcats, 50); + $message .= " _ around $q ".__('posts are undefined in','xili-language')." ".__("category")." = [$fromcats]"; + } + $actiontype = "reset"; + break; + case 'updateoptions'; + $this->browseroption = $_POST['xili_language_check_option']; + $this->authorbrowseroption = $_POST['xili_language_check_option_author']; + $this->functions_enable = $_POST['xili_language_check_functions_enable']; + $this->xili_settings['browseroption'] = $this->browseroption; + $this->xili_settings['authorbrowseroption'] = $this->authorbrowseroption; + $this->xili_settings['functions_enable'] = $this->functions_enable; + + $this->xili_settings['homelang'] = $_POST['xili_language_home_lang']; // 1.3.2 + + update_option('xili_language_settings', $this->xili_settings); + $message .= " - ".__('Option is updated.','xili-language')." (=> ".$this->browseroption.") (".$this->authorbrowseroption.") (".$this->functions_enable.")"; + $this->insert_gold_functions (); + $actiontype = "reset"; + break; + + case 'add': + $term = $_POST['language_name']; + $args = array( 'alias_of' => '', 'description' => $_POST['language_description'], 'parent' => 0, 'slug' =>$_POST['language_nicename']); + $theids = wp_insert_term( $term, TAXONAME, $args); + wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); + update_term_order ($theids['term_id'],$this->langs_group_tt_id,$_POST['language_order']); + $actiontype = "add"; + $message .= " - ".__('A new language was added.','xili-language'); + break; + + case 'edit'; + $actiontype = "edited"; + //echo $term_id; + //$language = get_term($term_id,TAXONAME,OBJECT,'edit'); + $language = get_term_and_order ($term_id,$this->langs_group_tt_id,TAXONAME); + $submit_text = __('Update »'); + $formtitle = 'Edit language'; + $message .= " - ".__('Language to update.','xili-language'); + break; + + case 'edited'; + $actiontype = "add"; + $term = $_POST['language_term_id']; + + $args = array( 'alias_of' => '', 'description' => $_POST['language_description'], 'parent' => 0, 'slug' =>$_POST['language_nicename']); + $theids = wp_update_term( $term, TAXONAME, $args); + wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); + update_term_order ($theids['term_id'],$this->langs_group_tt_id,$_POST['language_order']); + $message .= " - ".__('A language was updated.','xili-language'); + + break; + + case 'delete'; + $actiontype = "deleting"; + $submit_text = __('Delete »','xili-language'); + $formtitle = 'Delete language ?'; + //$language = get_term($term_id,TAXONAME,OBJECT,'edit'); + $language = get_term_and_order ($term_id,$this->langs_group_tt_id,TAXONAME); + $message .= " - ".__('A language to delete.','xili-language'); + + break; + + case 'deleting'; + $actiontype = "add"; + $term = $_POST['language_term_id']; + wp_delete_object_term_relationships( $term, TAXOLANGSGROUP ); + wp_delete_term( $term, TAXONAME, $args); + $message .= " - ".__('A language was deleted.','xili-language'); + break; + case 'reset'; + $actiontype = "add"; + break; + default : + $actiontype = "add"; + $message .= __('Find above the list of languages.','xili-language'); + + + } + /* register the main boxes always available */ + add_meta_box('xili-language-normal-1', __('List of languages','xili-language'), array(&$this,'on_normal_1_content'), $this->thehook , 'normal', 'core'); + add_meta_box('xili-language-normal-2', __('Language','xili-language'), array(&$this,'on_normal_2_content'), $this->thehook , 'normal', 'core'); + add_meta_box('xili-language-sidebox-3', __('Settings','xili-language'), array(&$this,'on_sidebox_3_content'), $this->thehook , 'side', 'core'); + + /* form datas in array for do_meta_boxes() */ + $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); + ?> + + Here a new taxonomy was created and used for languages of posts and pages.
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') ?>
| + | + | + | + | + | + | + | |
|---|---|---|---|---|---|---|---|
| : | +/> | +
|---|---|
| : | +/> | +
| : | +/> | + +
| : | +/> | + +
| + | + + | +