diff -r 2f6f6f7551ca -r 32102edaa81b web/wp-content/plugins/xili-language/xili-language.php --- a/web/wp-content/plugins/xili-language/xili-language.php Thu Sep 16 15:45:36 2010 +0000 +++ b/web/wp-content/plugins/xili-language/xili-language.php Mon Nov 19 18:26:13 2012 +0100 @@ -2,27 +2,33 @@ /* Plugin Name: xili-language Plugin URI: http://dev.xiligroup.com/xili-language/ -Description: This plugin modify on the fly the translation of the theme depending the language of the post or other blog elements - a way to create a real multilanguage site (cms or blog). It introduce a new taxonomy - here language - to describe posts and pages. To complete with tags, use also xili-tidy-tags plugin. +Description: This plugin modify on the fly the translation of the theme depending the language of the post or other blog elements - a way to create a real multilanguage site (cms or blog). Numerous template tags and three widgets are included. It introduce a new taxonomy - here language - to describe posts and pages. To complete with tags, use also xili-tidy-tags plugin. To include and set translation of .mo files use xili-dictionary plugin. Includes add-on for multilingual bbPress forums. Author: dev.xiligroup.com - MS -Version: 1.4.1 Author URI: http://dev.xiligroup.com +Version: 2.8.1 +License: GPLv2 +Text Domain: xili-language +Domain Path: /languages/ */ -# updated 100220 - 1.4.1 - wp_title translation for categories, () suppressed in cats list display, auto-search linked posts option -# updated 100216 - 1.3.2 - Option to modify home query according rules by chief editor. fixes gold functions. New Recent Posts Widget. -# updated 100216 - 1.3.1 - Just to correct a minor omission - Add New link works now for linked pages. -# updated 100215 - 1.3.0 - new functions to change and restore loop's language query-tag. Better post UI to create linked post - fixes lost lang's link when trash or untrash. -# updated 100207 - 1.2.1 - fixes some directories issues in (rare) xamp servers - Some improvements in post edit UI. -# updated 100109 - 1.2.0 - tested with WP 2.9.1 - more localization for admin UI (RU) -# updated 091104 - 1.1.9.1 - fixes special functions -# updated 091103 - 1.1.9 - optional improve hooking ways to be compatible with l10n cache of Johan see line 2200 - fix title of wp_get_archive links with current permalinks. -# updated 091019 - 1.1.8 - gold functions and shortcode for linked posts - first tests with WP 2.9 -# updated 091007 - 1.1.es - tests - gold functions active - update undefined posts functions in library -# updated 090918 - 1.1 - xiliml_the_other_posts function improved and upgraded for CMS webmasters -# updated 090719 - 1.0.2 - fix unexpected like tags metabox added by WP 28 tracs #10437 -# updated 090626 - 1.0.1 - fix filter unique id for category link hooks -# updated 090615 - 1.0 - Via admin UI, new ways to choose default language of front-page (page, home,...) -# updated 090606 - 0.9.9.6 - ready for 2.8 hooks - ready for multiple languages list widget -# see readme text for these intermediate versions. + +# updated 120921 - 2.8.1 - fixes sticky perma - improvements for bbPress - new filters in admin - fixes feed links meta +# updated 120903 - 2.8.0 - fixes, new: admin side language selection - b : langstate +# updated 120819 - 120723 - 2.7.1 - fixes lang_perma detect for permalinks add-ons - new start via action +# updated 120721 - 2.7.0 - multilingual features in media library - centralize alert messages and ready for link to wiki +# updated 120708 - 2.6.3 - fixes notice when page-on-front - new icons - test propagate cats +# updated 120701 - 2.6.2 - add news pointer in class admin, tabs in help +# updated 120615 - 2.6.1 - fixes notice xlrp +# updated 120528 - 2.6.0 - class admin in separate file, able to detect and use local files (local-xx_XX.mo) containing translations +# updated 120420 - 2.5.1 - add style for post edit (flag in imput) +# updated 120415 - 2.5.0 - new dashboard metabox for translations list of linked posts and actions (as in XD2), language postmetas now hidden, hreflang link added in head, WP3.4 pre-tests: fixes metaboxes columns + +# updated 120329 - 2.4.4 - fixes posts list language column in 3.2.1 +# updated 120225 - 2.4.3 - fixes before releasing +# updated 120212 - 2.4.2 - admin_bar replaced by toolbar and node (>= WP3.3) - cc: + Reply-To: - better merge loadthemedomain in multisite - ready for XD 2.0 - sub-sub-folder for language files +# updated 120128 - 2.4.1 - new readme - new tabs in settings - improved lang slug creation - test menu location get_registered_nav_menus - +# updated 111222 - 2.4.0 - if needed and present add rtl.css for rtl languages - new date based on wp_locale - time options +# less than 2.4…. +# see readme text for these intermediate versions for WP 2.x. or visit other previous versions (2.5). # updated 090228 - Class and OOP - see 0.9.7 in comments of functions below - only for WP 2.7.x # This plugin is free software; you can redistribute it and/or @@ -39,179 +45,662 @@ # License along with this plugin; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -define('XILILANGUAGE_VER','1.4.1'); /* used in admin UI*/ + +define('XILILANGUAGE_VER','2.8.1'); /* used in admin UI*/ +define('XILILANGUAGE_WP_VER','3.3'); /* used in error - see at end */ +define('XILILANGUAGE_PHP_VER','5.0.0'); /* used in error - see at end */ +define('XILILANGUAGE_PREV_VER','2.4.3'); + + + + +/********************* the CLASS **********************/ class xili_language { + var $xili_settings; /* saved in options */ + + var $langs_group_id; /* group ID and Term Taxo ID */ + var $langs_group_tt_id; + var $default_lang; /* language of config.php*/ + var $default_slug; /* slug of language of config.php since 1.5.3 wpmu*/ var $curlang; + + var $thetextdomain = ""; /* since 1.5.2 - used if multiple */ var $langstate; /* undefined or not */ + var $browseroption = ''; + var $lang_neither_browser = ''; // when neither match with browser var $authorbrowseroption = ''; - var $functions_enable = ''; + var $default_dir = ''; /* undefined or not in WP config '' or rtl or ltr */ var $curlang_dir = ''; /* undefined or not according array */ - var $rtllanglist = 'ar-he-fa-ur'; /*default-list - can be set after class instantiation*/ - var $post_ajax = false; /* ajax used in meta box in post edit UI unstable yet */ - var $is_metabox = false; /* meta box in post edit UI - if used don't use custom fields that are not refreshed */ - var $xili_settings; /* saved in options */ - var $langs_group_id; /* group ID and Term Taxo ID */ - var $langs_group_tt_id; + var $rtllanglist = 'ar-he-fa-ur'; /* default-list - can be set after class instantiation */ + var $get_archives_called = array(); /* if != '' - insert lang in link */ var $idx = array(); /* used to identify filter or action set from this class - since 0.9.9.6 */ var $theme_locale = false; /* to control locale hook */ var $ossep = "/"; /* for recursive file search in xamp */ + var $current_lang_query_tag = ""; /* since 1.3.0 */ var $temp_lang_query_tag = ""; - function xili_language($metabox = false, $post_ajax = false, $locale_method = false) { - $this->is_metabox = $metabox; - $this->post_ajax = $post_ajax; + var $domaindetectmsg = ""; // used if pb with load_theme_textdomain + + 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 + + var $comment_form_labels = array ( // since 1.6.0 for comment_form + 'name' => 'Name', + 'email' => 'Email', + 'website' => 'Website', + 'comment' => 'Comment', + 'youmustbe' => 'You must be logged in to post a comment.', + 'loggedinas' => 'Logged in as %2$s. Log out?', + 'emailnotpublished' => 'Your email address will not be published.', + 'requiredmarked' => ' Required fields are marked *', + 'youmayuse' => 'You may use these HTML tags and attributes:', + 'leavereply' => 'Leave a Reply', + 'replyto' => 'Leave a Reply to %s', + 'cancelreply' => 'Cancel reply', + 'postcomment' => 'Post Comment' + ); + + var $sticky_keep_original = false ; // since 1.6.1 see translate_sticky_posts_ID function + var $xl_recent_posts = false ; + var $ltd = false ; // load_textdomain detected 1.8.5 + var $arraydomains = array(); + var $show = false ; + + var $langs_ids_array ; // array slug => id + var $langs_slug_name_array ; // array slug => name // 2.4.2 + var $langs_slug_fullname_array; // array slug => full name // 2.6.3 + + var $show_page_on_front = false; + + /* for permalink with lang at root */ + var $lang_perma = false; // if true new permalink for root and categories /en_us/category/.... if special action available… 2.1.1 + var $lpr = ''; // 2.3.2 + var $show_page_on_front_array = array(); // array of lang=>page_id if show_on_front == page + + var $undefchar = "."; // 2.2.3 - used to detect undefined + var $sublang = ""; // 2.2.3 - used to detect - or fr_fr- of like + + // 2.5 + // other in class admin + var $translation_state = '_xl_translation_state' ; // set to initial when post created from dashboard metabox (to update post slug) + + // 2.6 - class admin in separate file + var $file_file = ''; // see in construct below + var $file_basename = ''; + var $plugin_basename = ''; + var $plugin_url = ''; + var $plugin_path = ''; // The path to this plugin - see construct + + var $xilidev_folder = '/xilidev-libraries'; //must be in plugins + + //since 2.7.1 - updated 2.8.0 + var $examples_list = array(); + + /**** Construct is future ****/ + + public function __construct( $locale_method = false, $show = false, $class_admin = false ) { + + // 2.6 - class admin in separate file + $this->file_file = __FILE__ ; // see in construct below + $this->file_basename = basename(__FILE__) ; + $this->plugin_basename = plugin_basename(__FILE__) ; + $this->plugin_url = plugins_url('', __FILE__) ; + $this->plugin_path = plugin_dir_path(__FILE__) ; + $this->locale_method = $locale_method; /* added for compatibility with cache plugin from johan */ - /*activated when first activation of plug*/ + $this->show = $show; + $this->class_admin = $class_admin; + /* 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( + $this->ossep = strtoupper( substr(PHP_OS ,0 ,3 ) == 'WIN' ) ? '\\' : '/'; + + + /** + * get current settings + */ + $this->xili_settings = get_option('xili_language_settings'); + if( false === $this->xili_settings ) { //1.9.1 + $this->initial_settings (); + update_option('xili_language_settings', $this->xili_settings); + } else { + if ($this->xili_settings['version'] == '1.9') { /* 2.4.0 */ + $this->xili_settings['wp_locale'] = 'wp_locale'; //wp_locale new mode + $this->xili_settings['version'] = '2.0'; + update_option('xili_language_settings', $this->xili_settings); // + } + if ($this->xili_settings['version'] == '2.0') { /* 2.4.0 */ + $this->xili_settings['available_langs'] = array(); // default array + $this->xili_settings['version'] = '2.1'; + update_option('xili_language_settings', $this->xili_settings); // + } + if ($this->xili_settings['version'] == '2.1') { /* 2.6.0 */ + $this->xili_settings['external_xl_style'] = "on"; + $this->xili_settings['creation_redirect'] = 'redirect'; // default - after initial creation + $this->xili_settings['version'] = '2.2'; + update_option('xili_language_settings', $this->xili_settings); // + } + + if ( ! isset ( $this->xili_settings['version'] ) || $this->xili_settings['version'] != '2.2') { // repair or restart from new + $this->initial_settings (); + update_option('xili_language_settings', $this->xili_settings); + } + } + if ( ! $class_admin ) { + if ( ! defined( 'TAXONAME' ) ) define('TAXONAME', $this->xili_settings['taxonomy']); + if ( ! defined( 'QUETAG' ) ) define('QUETAG', $this->xili_settings['reqtag']); // 'lang' + if ( ! defined( 'TAXOLANGSGROUP' ) ) define('TAXOLANGSGROUP', $this->xili_settings['taxolangsgroup']); + if ( ! defined( 'LANG_UNDEF' ) ) define('LANG_UNDEF', $this->xili_settings['lang_undefined']); //2.2.3 + } + + $this->browseroption = $this->xili_settings['browseroption']; + $this->lang_neither_browser = $this->xili_settings['lang_neither_browser']; // 2.3.1 + $this->authorbrowseroption = $this->xili_settings['authorbrowseroption']; + + + //$this->thetextdomain = $this->xili_settings['theme_domain']; /* since 1.5.2 */ + $this->langsliststatus = $this->xili_settings['langs_list_status']; /* 1.6.0 */ + + /* detect research about permalinks */ + + //$this->lang_perma = ( has_filter ( 'term_link', 'insert_lang_4cat' ) ) ? true : false ; // 1.4.1 + $this->show_page_on_front = ( 'page' == $this->get_option_wo_xili('show_on_front') ) ; + + if ( !$class_admin ) { // filtering only one time 2.6 + add_action( 'init', array(&$this,'init_textdomain')); + add_action( 'init', array(&$this,'init_and_register_language_post_taxonomy') ); + } + add_action( 'init', array(&$this,'init_vars') ); // moved here 2.8.0 + + if ( !$class_admin ) { // filtering only one time 2.6 + + add_action( 'init', array(&$this,'add_link_taxonomy'), 12 ); // 1.8.5 + /* special to detect theme changing since 1.1.9 */ + add_action( 'switch_theme', array(&$this,'theme_switched') ); + + /* query filters */ + add_filter( 'posts_join', array(&$this,'posts_join_with_lang'), 10, 2 ); + add_filter( 'posts_where', array(&$this,'posts_where_lang'), 10, 2 ); + + add_filter( 'posts_search', array(&$this,'posts_search_filter'), 10, 2 ); //2.2.3 + add_action( 'pre_get_posts', array(&$this,'xiliml_modify_querytag') ); + + + add_action( 'wp', array(&$this,'xiliml_language_wp') ); /// since 2.2.3 - wp_loaded - wp before + /* 'wp' = where theme's language is defined just after query */ + if ( $this->xili_settings['wp_locale'] == 'wp_locale' ) + add_action( 'wp', array(&$this,'xili_locale_setup'), 15 ); // since 2.4 + 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( 'widget_title', array(&$this,'one_text')); /* added 0.9.8.1 */ + add_filter( 'widget_text', array(&$this,'one_text')); + + add_filter( 'list_cats', array(&$this,'xiliml_cat_language'), 10, 2 ); /* mode 2 : content = name */ + add_filter( 'link_category', array(&$this,'one_text')); // 1.6.0 for wp_list_bookmarks (forgotten) + add_filter( 'category_link', array(&$this,'xiliml_link_append_lang'), 10, 2 ); + $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, 2); + /* 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_filter( 'bloginfo', array(&$this,'xiliml_bloginfo'), 10, 2); /* since 1.6.0 - description - date - time */ + + /* 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') ); + + /* option modified */ + add_filter( 'option_sticky_posts', array(&$this, 'translate_sticky_posts_ID') ); /* 1.6.1 */ + + add_filter( 'option_page_on_front', array(&$this, 'translate_page_on_front_ID') ); /* 1.7.0 */ + $filter = 'option_page_on_front'; + $function = 'translate_page_on_front_ID'; + $this->idx['translate_page_on_front_ID'] = _wp_filter_build_unique_id($filter, array (&$this, $function == '' ? $filter : $function), 10, 2); + + /* bookmarks and widget_links 1.8.5 #2500 */ + add_filter( 'widget_links_args', array( &$this, 'widget_links_args_and_lang' ), 10, 1 ); // in class WP_Widget_Links (default-widgets.php) + add_filter( 'get_bookmarks', array( &$this, 'the_get_bookmarks_lang' ), 10, 2); // only active if 'lang' in wp_list_bookmarks() + + add_action( 'wp_head', array(&$this,'head_insert_language_metas'), 11 ); // © and options present in functions.php + + if ( !is_admin() ) { + add_filter( 'the_category', array(&$this,'xl_get_the_category_list'), 10, 2); /* 1.7.0 */ + add_filter( 'gettext', array(&$this,'change_plugin_domain'), 10, 3); /* 1.8.7 */ + add_filter( 'gettext_with_context', array(&$this,'change_plugin_domain_with_context'), 10, 4); /* 1.8.8 */ + add_filter( 'ngettext', array(&$this,'change_plugin_domain_plural'), 10, 5); + add_filter( 'ngettext_with_context', array(&$this,'change_plugin_domain_plural_with_context'), 10, 6); + + // for wp nav menu + add_filter('the_title', array(&$this,'wp_nav_title_text'),10,2); + if ('' != $this->xili_settings['in_nav_menu']) + add_filter('wp_nav_menu_items', 'xili_nav_lang_list',10,2); + if ('' != $this->xili_settings['page_in_nav_menu']) + add_filter('wp_nav_menu_items', 'xili_nav_page_list',9,2); // before lang's links - 1.7.1 + if ('' != $this->xili_settings['home_item_nav_menu']) + add_filter('walker_nav_menu_start_el', 'xili_nav_page_home_item',10,4); // add lang if - 1.8.9.2 + + add_filter( 'language_attributes', array(&$this,'head_language_attributes')); + add_action( 'wp_head', array(&$this,'head_insert_hreflang_link' ), 10 ); // since 2.5 + + add_filter( 'option_date_format', array(&$this, 'translate_date_format') ); /* 1.7.0 */ + + add_filter( 'category_feed_link', array(&$this, 'category_feed_link') ); // 2.8.1 + } + + // since 1.5.5 + add_filter( 'comment_form_default_fields', array(&$this,'xili_comment_form_default_fields')); + add_filter( 'comment_form_defaults', array(&$this,'xili_comment_form_defaults')); + + // since 2.4.0 for rtl.css + add_filter( 'locale_stylesheet_uri', array(&$this, 'change_locale_stylesheet_uri' ),10, 2 ) ; + + // since 1.8.8 - activate xl widget series + if ( $this->xili_settings['widget'] == 'enable' ) + add_action( 'widgets_init', array(&$this,'add_new_widgets') ); + + /* new actions for xili-language theme's templates tags */ + + $this->add_action( 'xili_language_list', 'xili_language_list', 10, 5); /* add third param 0.9.7.4 - 4th 1.6.0*/ + $this->add_action( 'xili_post_language', 'xili_post_language', 10, 2); + + $this->add_action( 'xiliml_the_other_posts', 'the_other_posts', 10, 4); /* add a param 1.1 */ + $this->add_action( 'xiliml_the_category', 'the_category', 10, 3); + $this->add_filter( 'xiliml_langinsearchform', 'xiliml_langinsearchform', 10, 3); // 1.8.2 action to filter + + // verify theme and set ltd for both parent and admin child + add_filter( 'override_load_textdomain', array(&$this,'xiliml_override_load'), 10, 3); // since 1.5.0 + add_filter( 'theme_locale', array(&$this,'xiliml_theme_locale'), 10, 2); // two times if is_admin() + } + } + + /** + * first activation or empty settings + */ + function initial_settings () { + $this->xili_settings = array( 'taxonomy' => 'language', - 'version' => '0.4', - 'reqtag' => 'lang', + 'version' => '2.2', + 'reqtag' => 'lang', // query_var 'browseroption' => '', 'authorbrowseroption' => '', 'taxolangsgroup' => 'languages_group', 'functions_enable' => '', 'langs_folder' => '', 'theme_domain' => '', - 'homelang' => '' + 'homelang' => '', + 'langs_list_status' => '', + 'in_nav_menu' => '', + 'page_in_nav_menu' => '', + 'args_page_in_nav_menu' => '', + 'multilingual_custom_post' => array(), + 'langs_in_root_theme' => '', + 'domains' => array( 'all' => 'disable', 'default' => 'disable','bbpress' => 'disable' ), // no default domain to theme domain 1.8.7 + 'widget' => 'enable', + 'delete_settings' => '', //1.8.8 for uninstall + 'allcategories_lang' => 'browser', // 1.8.9.1 + 'lang_features' => array() , + 'home_item_nav_menu' => '', // 1.8.9.2 + 'lang_undefined' => $this->undefchar, //2.2.3 + 'lang_neither_browser' => '', // 2.3.1 + 'wp_locale' => 'wp_locale', // 2.7.1 new mode as default - 2.4.0 = old mode based on db strftime + 'available_langs' => array(), + 'creation_redirect' => 'redirect', // 2.6 to redirect to new post after creation + 'external_xl_style' => "on" // activate external xl-style.css - on by default :2.6.3 ); - 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) + /* first activation of plugin */ + function xili_language_activate() { + $this->xili_settings = get_option('xili_language_settings'); + if( empty($this->xili_settings) ) { + $this->initial_settings (); + update_option('xili_language_settings', $this->xili_settings); + } + } + + 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) + 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 */ } + + /** + * for wpmu + * register functions must be called by init + * + * @since 1.5.1 + * + */ + function init_and_register_language_post_taxonomy () { + /** 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 , 'query_var' => QUETAG + * @updated 1.4.1 + */ + + if ( !$this->class_admin ) { + if ( $this->xili_settings['wp_locale'] == 'wp_locale' ) + xiliml_declare_xl_wp_locale (); + + if ( $this->lang_perma ) { + + 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 )); + $this->lpr = "-"; // 2.3.2 + } else { + add_filter('query_vars', array(&$this,'keywords_addQueryVar')); // now in taxonomy decl. // 2.1.1 + 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 )); + + } + + register_taxonomy( TAXOLANGSGROUP, 'term', array('hierarchical' => false, 'update_count_callback' => '', 'show_ui' => false, 'label'=>false, 'rewrite' => false, '_builtin' => false )); + } + + } + + /** + * since 2.6 + * + */ + function init_vars () { + + $this->examples_list = array( + 'af' => __('afrikaans','xili-language'), + 'ar_AR' => __('arabic', 'xili-language'), + 'be_BY' => __('belarusian', 'xili-language'), + 'bs_BA' => __('bosnian', 'xili-language'), + 'bg_BG' => __('bulgarian', 'xili-language'), + 'bn_BD' => __('bangla', 'xili-language'), + 'ca' => __('catalan', 'xili-language'), + 'cs_CZ' => __('czech', 'xili-language'), + 'cy' => __('welsh', 'xili-language'), + 'da_DK' => __('danish', 'xili-language'), + 'de_DE' => __('german', 'xili-language'), + 'el' => __('greek', 'xili-language'), + 'en_GB' => __('british english', 'xili-language'), + 'en_US' => __('english', 'xili-language'), + 'eo' => __('esperanto', 'xili-language'), + 'es_ES' => __('spanish', 'xili-language'), + 'es_CL' => __('chilean', 'xili-language'), + 'et' => __('estonian', 'xili-language'), + 'eu' => __('euskara', 'xili-language'), + 'fa_IR' => __('persian', 'xili-language'), + 'fi_FI' => __('finnish', 'xili-language'), + 'fo' => __('faroese', 'xili-language'), + 'fr_FR' => __('french', 'xili-language'), + 'ge_GE' => __('georgian', 'xili-language'), + 'gl_ES' => __('galician', 'xili-language'), + 'he_IL' => __('hebrew', 'xili-language'), + 'hr' => __('croatian', 'xili-language'), + 'hu_HU' => __('hungarian', 'xili-language'), + 'id_ID' => __('indonesian', 'xili-language'), + 'is_IS' => __('icelandic', 'xili-language'), + 'it_IT' => __('italian', 'xili-language'), + 'ja' => __('japanese', 'xili-language'), + 'km_KH' => __('khmer', 'xili-language'), + 'ko_KR' => __('korean', 'xili-language'), + 'lt_LT' => __('lithuanian', 'xili-language'), + 'lv' => __('latvian', 'xili-language'), + 'mg_MG' => __('malagasy', 'xili-language'), + 'mk_MK' => __('macedonian', 'xili-language'), + 'mn_MN' => __('mongolian', 'xili-language'), + 'ms_MY' => __('malay', 'xili-language'), + 'nb_NO' => __('norwegian', 'xili-language'), + 'ni_ID' => __('nias', 'xili-language'), + 'nl_NL' => __('dutch', 'xili-language'), + 'pl_PL' => __('polish', 'xili-language'), + 'pt_BR' => __('brazilian portuguese', 'xili-language'), + 'pt_PT' => __('portuguese', 'xili-language'), + 'ro_RO' => __('romanian', 'xili-language'), + 'ru_RU' => __('russian', 'xili-language'), + 'si_LK' => __('sinhala', 'xili-language'), + 'sk_SK' => __('slovak', 'xili-language'), + 'sl_SI' => __('slovenian', 'xili-language'), + 'sq_AL' => __('albanian', 'xili-language'), + 'sr_CS' => __('serbian', 'xili-language'), + 'sv_SE' => __('swedish', 'xili-language'), + 'su_ID' => __('sundanese', 'xili-language'), + 'tg' => __('tajik', 'xili-language'), + 'th' => __('thai', 'xili-language'), + 'tr' => __('turkish', 'xili-language'), + 'uk_UA' => __('ukrainian', 'xili-language'), + 'uz_UZ' => __('uzbek', 'xili-language'), + 'vi' => __('vietnamese', 'xili-language'), + 'zh_CN' => __('chinese', 'xili-language'), + 'zh_TW' => __('taiwan chinese', 'xili-language'), + 'zh_HK' => __('hong kong chinese', 'xili-language') + ); + /* default values */ + if ( ''!= WPLANG && ( strlen( WPLANG )==5 || strlen( WPLANG ) == 2 ) ) : // for japanese + $this->default_lang = WPLANG; + else: + $this->default_lang = 'en_US'; + endif; + + $thegroup = get_terms(TAXOLANGSGROUP, array('hide_empty' => false,'slug' => 'the-langs-group')); + if ( array() == $thegroup ) { /* update langs group 0.9.8 and if from start 2.3.1 */ + $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, 'get' => 'all')); + if ( array() == $listlanguages ) { /*create two default lines with the default language (as in config)*/ + /* language of WP */ + + $term = 'en_US'; + $args = array( 'alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' =>'en_us'); + + $theids = $this->safe_lang_term_creation ( $term, $args ); + if ( ! is_wp_error($theids) ) { + wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); + $this->xili_settings['lang_features']['en_us'] = array('charset'=>"",'hidden'=>""); + } + $term = $this->default_lang; + $desc = ( isset($this->examples_list[$term]) ) ? $this->examples_list[$term] : $this->default_lang; + $slug = strtolower( $this->default_lang ) ; // 2.3.1 + if (!defined('WPLANG') || $this->default_lang == 'en_US' || $this->default_lang == '' ) { + $term = 'fr_FR'; $desc = 'french'; $slug = 'fr_fr' ; + } + $args = array( 'alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug); + + $theids = $this->safe_lang_term_creation ( $term, $args ) ; + if ( ! is_wp_error($theids) ) { + wp_set_object_terms($theids['term_id'], 'the-langs-group', TAXOLANGSGROUP); + $this->xili_settings['lang_features'][$slug] = array('charset'=>"",'hidden'=>""); + } + update_option('xili_language_settings', $this->xili_settings); + $listlanguages = get_terms(TAXONAME, array('hide_empty' => false, 'get' => 'all')); + } + 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', 'get' => 'all') ); + } + + if (function_exists('is_child_theme') && is_child_theme() ) { // 1.8.1 - 1.8.5 + if ( $this->xili_settings['langs_in_root_theme'] == 'root' ) { + $this->get_template_directory = get_template_directory(); + } else { + $this->get_template_directory = get_stylesheet_directory(); + } + } else { + $this->get_template_directory = get_template_directory(); + } + + $this->langs_group_id = $thegroup[0]->term_id; + $this->langs_group_tt_id = $thegroup[0]->term_taxonomy_id; + + $this->get_lang_slug_ids(); // default array of languages slug=>id and slug=>name // 2.4.2 + + if ( $this->show_page_on_front ) $this->get_show_page_on_front_array(); + /* here because taxonomy is registered : since 1.5.3 */ + + $this->default_slug = $this->get_default_slug(); /*no constant for wpmu */ + if (!is_multisite() && !defined('DEFAULTSLUG')) define('DEFAULTSLUG',$this->default_slug); /* for backward compatibility */ + + + if ( $dir = get_bloginfo('text_direction') ) /* if present in blog options @since 0.9.9 */ + $this->default_dir = $dir; + + // 1.8.4 + if ( isset($this->xili_settings['available_langs']) && array() != $this->xili_settings['available_langs'] ) { + $this->available_langs = $this->xili_settings['available_langs']; + } else { + $this->available_langs = $this->get_lang_ids() ; + $this->xili_settings['available_langs'] = $this->available_langs; + update_option('xili_language_settings', $this->xili_settings); + } + + // 2.2.0 - add_roles - + + if ( is_admin() ) { + global $wp_roles; + + if ( current_user_can ('activate_plugins') ) { + $wp_roles->add_cap ('administrator', 'xili_language_set'); + $wp_roles->add_cap ('administrator', 'xili_language_menu'); + $wp_roles->add_cap ('administrator', 'xili_language_clone_tax'); + } elseif ( current_user_can ('editor') ) { + $wp_roles->add_cap ('editor', 'xili_language_menu'); + $wp_roles->add_cap ('editor', 'xili_language_clone_tax'); // able to clone taxonomy ('categeory') during propagate or create post + } + } + } + + /** + * Safe language term creation + * + * @since 2.4.1 + */ + function safe_lang_term_creation ( $term, $args ) { + global $wpdb ; + // test if exists with other slug or name + if ( $term_id = term_exists( $term ) ) { + $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name, slug FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); + if ( $existing_term['slug'] != $args['slug'] ) { + $res = wp_insert_term( $term.'xl', TAXONAME, $args); // temp insert with temp other name + $args['name'] = $term ; + $res = wp_update_term( $res['term_id'], TAXONAME, $args); + } else { + return new WP_Error('term_exists', __('A term with the name provided already exists.'), $term_id ); + } + } else { + $res = wp_insert_term( $term, TAXONAME, $args); + } + if (is_wp_error($res)) { + return $res ; + } else { + $theids = $res; + } + return $theids ; + } + + /** + * Get list language Objects - designed and used to avoid query by using settings + * + * @since 1.6.0 + * @param $force to avoid buffer + * @return array of objects + */ + function get_listlanguages( $force = false ) { + if ( $this->xili_settings['langs_list_status'] != "set" || $force === true ) { + $listlanguages = get_terms_of_groups_lite ( $this->langs_group_id, TAXOLANGSGROUP,TAXONAME, 'ASC' ); + if ( $listlanguages ) { + $this->xili_settings['languages_list'] = $listlanguages; + $this->xili_settings['langs_list_status'] = "set"; + if ( ! $this->class_admin ) { + update_option('xili_language_settings', $this->xili_settings); + } + } + return $listlanguages; + } else { + return $this->xili_settings['languages_list']; + } + } + + /** + * Get list language IDs + * + * @since 1.8.4 + */ + function get_lang_ids() { + + $lang_ids = array() ; + $listlanguages = get_terms_of_groups_lite ($this->langs_group_id,TAXOLANGSGROUP,TAXONAME,'ASC'); + foreach ( $listlanguages as $lang) { + $lang_ids[] = $lang->term_id; + } + return $lang_ids ; + } + + /** + * Get list languages slug_IDs + * + * @since 2.1.1 + */ + function get_lang_slug_ids() { + + $lang_slugs = array() ; + $lang_names = array() ; + $lang_full_names = array() ; + $listlanguages = $this->get_listlanguages( true ); + foreach ( $listlanguages as $lang) { + $key = $lang->slug; + $lang_slugs[$key] = $lang->term_id; + $lang_names[$key] = $lang->name; + $lang_full_names[$key] = $lang->description; + } + $this->langs_ids_array = $lang_slugs; + $this->langs_slug_name_array = $lang_names; + $this->langs_slug_fullname_array = $lang_full_names; + + $this->xili_settings['langs_ids_array'] = $lang_slugs; + if ( is_admin () && !$this->class_admin ) { + update_option( 'xili_language_settings', $this->xili_settings ); + + }// if changing occurs... + } + + /** + * get show pages on front + * + * @since 2.1.1 + * + * + * update $this->show_page_on_front_array array + */ + function get_show_page_on_front_array() { + $front_pages_array = array(); + $languages = $this->get_listlanguages( true ); + $front_page_id = $this->get_option_wo_xili ('page_on_front'); + foreach ( $languages as $lang) { + $key = $lang->slug; + $id = get_post_meta ( $front_page_id, QUETAG.'-'.$key, true ); + $page_id = ( ''!= $id ) ? $id : $front_page_id ; + $front_pages_array[$key] = $page_id; // + } + + $this->show_page_on_front_array = $front_pages_array; + $this->xili_settings['show_page_on_front_array'] = $front_pages_array; + if ( is_admin () ) update_option( 'xili_language_settings', $this->xili_settings ); // if changing occurs... + } /** * More than one filter for the function. @@ -221,26 +710,155 @@ * @param $the_function (string). * @return true if more than one. */ - function this_has_filter($the_function) { + function this_has_filter( $the_function ) { global $wp_filter; + if ( !isset ( $wp_filter[$the_function]) ) return false; // avoid php warning 2.3.0 $has = $wp_filter[$the_function]; - //print_r($has); + + if ( ! is_array( $has ) ) return false; // avoid php warning 2.1.0 $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'); - } + } + + /** + * + * + */ + function get_post_language ( $post_ID, $result = 'slug' ) { + $ress = wp_get_object_terms($post_ID, TAXONAME); + if ( $ress ) { + $obj_term = $ress[0]; // today only one language per post + + switch ( $result ) { + case 'iso': + $postlang = ('' != $obj_term->name) ? $obj_term->name : ""; + break; + case 'name': + $postlang = ('' != $obj_term->description) ? $obj_term->description : ""; + break; + default: // slug + $postlang = ('' != $obj_term->slug) ? $obj_term->slug : ""; + } + } else { + $postlang = ""; + } + return $postlang; + } + + + + + /** + * Create a linked copy of current post in target language + * + * @since 2.5 + * + */ + function create_initial_translation ( $target_lang, $from_post_title = "" , $frompostlang = "", $from_post_ID ) { + global $user_ID; + + $post_title_prefix = sprintf ( __('Please translate in %s:', 'xili-language' ), $target_lang ); + $target_post_title = ( $from_post_title == '' ) ? $post_title_prefix . ' ' . $from_post_ID : $post_title_prefix . ' ' . $from_post_title ; + + $post_type = get_post_type( $from_post_ID ); + + $params = array('post_status' => 'draft', 'post_type' => $post_type, 'post_author' => $user_ID, + 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, + 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', + 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, + 'post_content' => $target_post_title, 'post_title' => $target_post_title); + + $post_ID = wp_insert_post( $params ) ; + + if ( $post_ID != 0 ) { + // taxonomy + wp_set_object_terms( $post_ID, $target_lang, TAXONAME ); + // metas + // from + update_post_meta( $from_post_ID, QUETAG.'-'.$target_lang, $post_ID ); + + // this with other target of from + $listlanguages = $this->get_listlanguages () ; + foreach ( $listlanguages as $language ) { + if ( $language->slug != $target_lang && $language->slug != $frompostlang ) { + $id = get_post_meta( $from_post_ID, QUETAG.'-'.$language->slug, true ); + if ( $id != "" ) { + update_post_meta( $post_ID, QUETAG.'-'.$language->slug, $id ); + } + } + } + // this + update_post_meta( $post_ID, QUETAG.'-'.$frompostlang, $from_post_ID ); + update_post_meta( $post_ID, $this->translation_state, "initial" ); // to update further slug - post_name + + // categories of from_post + $this->propagate_categories ( $from_post_ID, $post_ID ); + return $post_ID; + } + } + + /** + * propagate categories from a reference post to another (loop is in class admin) + * if cat is not in target, cat will be unassigned in target if mode is 'erase' + * + * @since 2.6 + * + */ + function propagate_categories ( $from_post_ID, $post_ID, $mode = '' ) { + // categories of from_post + // get + $categories = get_the_category( $from_post_ID ); + if ( ! empty( $categories ) ) { + if ( is_object_in_taxonomy( get_post_type( $from_post_ID ), 'category' ) ) { + // set + $the_cats = array(); + foreach ( $categories as $category ) { + $the_cats[] = $category->slug; // wp_set_object_terms don't like loop + } + // prepare target (erase all) + if ( $mode == 'erase' ) wp_delete_object_term_relationships ( $post_ID, 'category' ); + wp_set_object_terms( $post_ID, $the_cats, 'category' ); + } + } + } + + + /** + * return post object + * + * @since 2.5 + * + */ + function temp_get_post ( $post_id ) { + global $wpdb ; + $res = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id)); + if ( $res && !is_wp_error($res) ) + return $res; + else + return false; + } + + /** + * return saved list of post_type and custom_post_type + * + * @since 2.5 + * + */ + function authorized_custom_post_type () { + + $custompoststype = $this->xili_settings['multilingual_custom_post'] ; + $custom = get_post_type_object ('post'); + $clabels = $custom->labels; + $custompoststype['post'] = array( 'name' => $custom->label , 'singular_name' => $clabels->singular_name , 'multilingual' => 'enable'); + $custom = get_post_type_object ('page'); + $clabels = $custom->labels; + $custompoststype['page'] = array( 'name' => $custom->label, 'singular_name' => $clabels->singular_name , 'multilingual' => 'enable'); + return $custompoststype; } /** @@ -261,69 +879,43 @@ } /** - * 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) { + function get_dir_of_cur_language( $lang_slug ) { $rtlarray = explode ('-',$this->rtllanglist); - $dir = (in_array(substr(strtolower($lang_slug),0,2),$rtlarray)) ? 'rtl' : 'ltr'; + $dir = ( in_array(substr(strtolower($lang_slug), 0, 2 ),$rtlarray) ) ? 'rtl' : 'ltr'; return $dir; } /** + * Insert rtl.css if exists (default filter of wp_head) - see theme.php (Thanks Sam R.) + * + * @since 2.4.0 + */ + function change_locale_stylesheet_uri ( $stylesheet_uri, $stylesheet_dir_uri ) { + $rtlarray = explode ('-', $this->rtllanglist); + $dir = ( in_array( substr( strtolower( $this->curlang ), 0, 2 ), $rtlarray ) ) ? 'rtl' : 'ltr'; + $dircss = get_stylesheet_directory(); + // avoid with locale.css + if ( $stylesheet_uri == '' || false !== strpos($stylesheet_uri, 'rtl.css' ) || false !== strpos($stylesheet_uri, 'ltr.css' ) ) { + if ( in_array ( substr( $this->curlang, 0, 2 ) , $rtlarray ) ) { + + if ( file_exists("$dircss/{$dir}.css") ) { + return $stylesheet_dir_uri."/{$dir}.css"; + } else { + return ''; + } + + } + } + return $stylesheet_uri ; // non filtered value + } + + + /** * Return language of post. * * @since 0.9.0 @@ -332,7 +924,7 @@ * @param $post_ID. * @return slug of language of post or false if var langstate is false. */ - function get_cur_language($post_ID) { + function get_cur_language( $post_ID ) { $ress = wp_get_object_terms($post_ID, TAXONAME); if ($ress) { if (is_a($ress, 'WP_Error')){ @@ -343,7 +935,7 @@ $this->langstate = true; $postlang = $obj_term->slug; $postlangdir = $this->get_dir_of_cur_language($postlang); - return array('lang'=>$postlang,'direction'=>$postlangdir); + return array( QUETAG => $postlang, 'direction' => $postlangdir); } } else { $this->langstate = false; /* can be used in language attributes for header */ @@ -351,34 +943,14 @@ } } - /* 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) { + /** 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)); + $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; @@ -387,66 +959,267 @@ } /** - * filters used when querytag is used - - * see below and functions.php where rules depend from theme + * Query join filter used when querytag is used or home + * + * @updated 1.7.0 modify page on front and home query + * @updated 1.8.4 * to select posts with undefined lang + * @updated 2.2.3 LANG_UNDEF = . and no * + * */ - 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) "; + function posts_join_with_lang( $join, $query_object = null ) { + global $wpdb, $wp_query; + + + $insert_join = false ; + if ( isset ( $query_object->query_vars[QUETAG] ) && '' != $query_object->query_vars[QUETAG] ) { + 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']) ) { + if ( isset ( $query_object->query_vars['xlrp'] ) && $query_object->query_vars['xlrp'] == 1 ) $insert_join = true ; // called by xili recent posts + } else { + $a = $query_object->query_vars['page_id']; + $b = get_option('page_on_front'); + + if ( !($query_object->is_home && $this->show_page_on_front ) ) { // join if no front-page and other page + if ( $a == $b && $a !='' ) { + // 1.8.1 - two pages in results when language is selected at front !! + // 1.8.4 - home as home + lang + $insert_join = false ; + } else { + + $insert_join = true ; // as in cat or home+lang + } + } elseif ( $query_object->is_home && !$this->show_page_on_front ) { // home and lang + $insert_join = true ; + } else { + $insert_join = true ; + } + + if ( $this->lang_perma ) { + + if ( $query_object->query_vars['category_name'] == "" && isset( $query_object->query_vars[QUETAG]) && $this->show_page_on_front && !is_admin()) { + $join = ''; + $insert_join = false ; + unset($wp_query->queried_object); // to avoid notice in get_page_template and force get_queried_object -2.3.2 + } + if ( $query_object->is_tax && $query_object->query_vars['category_name'] != '' ) $insert_join = true ; + } + } + + } else { // join if home and modify home according rule ignore_sticky_posts + + if ( ''== $this->sublang ) { + 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']) ) { + if ( isset( $query_object->query_vars['xlrp'] ) && $query_object->query_vars['xlrp'] == 1 ) $insert_join = true ; // called by xili recent posts + + } else { + if ( ( $query_object->is_home && $this->xili_settings['homelang'] == 'modify') || $query_object->query_vars['ignore_sticky_posts']) { + + $insert_join = true ; //error_log ('************ join ************' . serialize ( $query_object->query_vars['post_type'])); + + } + } + } } + + + if ( $insert_join ) { + $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) "; + } + return $join; + } + /** + * to detect undefined query and unset language tax query + * @since 2.2.3 - LANG_UNDEF + * + */ - return $join; + function posts_search_filter ( $search, $the_query) { + $this->sublang = ""; + + if ( isset( $the_query->query_vars[QUETAG] ) && false !== strpos( $the_query->query_vars[QUETAG] , LANG_UNDEF ) ) { + + + if ( array() != $the_query->tax_query->queries ) { + $new_queries = array(); + foreach ( $the_query->tax_query->queries as $query ) { + if ( $query['taxonomy'] != TAXONAME ) { + $new_queries[] = $query ; + } + } + $the_query->tax_query->queries = $new_queries; + } + $this->sublang = $the_query->query_vars[QUETAG]; // to adapt in where filter below + unset ( $the_query->query_vars[QUETAG] ); + unset ( $the_query->tax_query->relation ); + if ( array() == $the_query->tax_query->queries ) { + $the_query->is_tax = false ; + } + } + return $search; } + /** - * Setup global post data. + * Modify the query including lang or home * * @since 0.9.0 * @updated 0.9.4 (OR added) lang=xx_xx,yy_yy,.. + * @updated 1.7.0 modify page on front and home query + * @updated 2.2.3 LANG_UNDEF * * @param object $where. * @return $where. */ - function where_lang($where) { - global $wp_query , $wpdb; + function posts_where_lang( $where, $query_object = null ) { + global $wpdb, $wp_query; $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; + + + if ( "" != $this->sublang ) { // see above + + $lang = str_replace ( LANG_UNDEF, '' , $this->sublang ); //$query_object->query_vars[QUETAG] ) ; + if ( "" == $lang ) { + $lang_string = implode( ", ", $this->available_langs ); + } else { + $id = $this->langs_ids_array[ $lang ]; + $remain = array_diff( $this->available_langs, array($id)); + $lang_string = implode( ", ", $remain ); + } + + $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) )"; + + } elseif ( isset ($query_object->query_vars[QUETAG]) && '' != $query_object->query_vars[QUETAG] ) { + + $do_it = false; + 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']) ) { + + if ( isset ( $query_object->query_vars['xlrp'] ) && $query_object->query_vars['xlrp'] == 1) $do_it = true; + + } else { + + if ( $this->lang_perma && !is_admin ()) { + if ( $query_object->is_page && isset( $query_object->query_vars[QUETAG]) ) { + $do_it == false; + } elseif (!($query_object->is_home && $this->show_page_on_front )) { + + $do_it = true; + } + if ( $query_object->is_tax && $query_object->query_vars['taxonomy'] == 'category' ) { + $do_it = true; + } + if ( $query_object->is_tax && $query_object->query_vars['taxonomy'] == TAXONAME && "" == $query_object->query_vars['category_name'] ) { + $do_it = false; + if ( !$query_object->is_page ) { + $where .= " AND $wpdb->posts.post_type = 'post'"; + } + } + } else { + if ( !( $query_object->is_home && $this->show_page_on_front ) ) { + $do_it = true; // all but not home + } } + } + + + if ($do_it) { // insertion of selection - foreach ($reqtags as $reqtag){ - $reqtagt = is_term( $reqtag, TAXONAME ); - if ($reqtagt) - $thereqtags[] = $reqtagt['term_id']; + if ( strpos($query_object->query_vars[QUETAG], ',') !== false ) { + $langs = preg_split('/[,\s]+/', $query_object->query_vars[QUETAG]); + foreach ( (array) $langs as $lang ) { + $lang = sanitize_term_field('slug', $lang, 0, 'post_tag', 'db'); + $reqtags[]= $lang; + } + foreach ($reqtags as $reqtag){ + $thereqtagids[] = $this->langs_ids_array[$reqtag]; + } + $wherereqtag = implode(", ", $thereqtagids); + $where .= " AND xtt.taxonomy = '".TAXONAME."' "; + $where .= " AND xtt.term_id IN ( $wherereqtag )"; + + } else { + /* only one lang */ + $query_object->query_vars[QUETAG] = sanitize_term_field('slug', $query_object->query_vars[QUETAG], 0, 'post_tag', 'db'); + $reqtag = $query_object->query_vars[QUETAG]; + + $wherereqtag = $this->langs_ids_array[$reqtag]; + $where .= " AND xtt.taxonomy = '".TAXONAME."' "; + $where .= " AND xtt.term_id = $wherereqtag "; + } + + } else { // is_home and page + + if ( $query_object->is_home && $this->show_page_on_front ) { + $query_object->is_home = false ; // renew the values because the query contains lang= + $query_object->is_page = true ; + $query_object->is_singular = true ; + $query_object->query = array(); + $query_object->query_vars['page_id'] = get_option('page_on_front'); // new filtered value + //$query_object->query_vars['p'] = $query_object->query_vars['page_id']; + + $where = str_replace ("'post'","'page'",$where); // post_type = + $where .= " AND 3=3 AND {$wpdb->posts}.ID = " . $query_object->query_vars['page_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; + if ( $this->lang_perma && $this->show_page_on_front) { // 2.1.1 + if ( $query_object->query_vars[QUETAG] != "" && $query_object->query_vars['taxonomy'] == TAXONAME ) { + $query_object->is_page = true ; + $query_object->is_tax = false ; + $query_object->is_archive = false ; + $query_object->is_singular = true ; + + $query_object->query = array(); + $pid = $this->get_option_wo_xili ('page_on_front') ; + $lang = ( isset ( $query_object->query_vars[QUETAG] ) ? $query_object->query_vars[QUETAG] : 'en_us' ); + $id = get_post_meta ( $pid, QUETAG.'-'.$lang, true ); + $pagid = ( ''!= $id ) ? $id : $pid ; + $query_object->query_vars['page_id'] = $pagid ; + + unset ( $query_object->query_vars['taxonomy'] ); + + $where = str_replace ("'post'","'page'",$where); // post_type = + $where = "AND {$pagid} = {$pagid} "." AND {$wpdb->posts}.ID = " . $query_object->query_vars['page_id'] . " AND {$wpdb->posts}.post_type = 'page'"; + + $query_object->query_vars['page_id'] = get_option ('page_on_front') ; + //$query_object->query_vars['p'] = $query_object->query_vars['page_id']; + + unset($wp_query->queried_object); + $wp_query->queried_object_id = $query_object->query_vars['page_id']; + $wp_query->queried_object->ID = $query_object->query_vars['page_id']; + //$this->first_change = $lang ; + //update_option('xili_language_settings_test', $this->first_change); + } } - $where .= " AND tt.taxonomy = '".TAXONAME."' "; - $where .= " AND tt.term_id = $wherereqtag "; } + - } - return $where; + } else { // no query tag + //error_log ( "****** join ******" ); + 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']) ) { + + if ( isset($query_object->query_vars['xlrp']) && $query_object->query_vars['xlrp'] == 1) { + $reqtag = $query_object->query_vars[QUETAG]; + + $wherereqtag = $this->langs_ids_array[$reqtag]; + $where .= " AND xtt.taxonomy = '".TAXONAME."' "; + $where .= " AND xtt.term_id = $wherereqtag "; + + } + } else { //error_log ( "****** ici ******" . serialize ( $query_object->query_vars['post_type']) ); + if ( $query_object->is_home && !$this->show_page_on_front && $this->xili_settings['homelang'] == 'modify' ) { + + // force change if loop + $curlang = $this->choice_of_browsing_language(); + + $wherereqtag = $this->langs_ids_array[$curlang]; + $where .= " AND xtt.taxonomy = '".TAXONAME."' "; + $where .= " AND xtt.term_id = $wherereqtag "; + + } + } + } + //error_log ( "****** join ******".$where ); + return $where; } /******** template theme live modifications ********/ @@ -455,21 +1228,189 @@ * 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 + * @updated 1.1.9, 1.4.2a + * 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 ( !is_admin() ) { + $this->curlang = $this->get_curlang_action_wp(); // see hooks in that function + //$this->curlang = 'en_us'; + + $this->curlang_dir = $this->get_dir_of_cur_language( $this->curlang ); /* general dir of the theme */ + if ( $this->locale_method ) { + $this->xiliml_load_theme_textdomain ( $this->thetextdomain ); /* new method for cache compatibility - tests */ + } else { + $this->set_mofile( $this->curlang ); + } + } + } + + + + /** + * wp action to switch wp_locale only on front-end + * + * @since 2.4.0 + * + * call by wp hook after theme cur_lang set + * + */ + function xili_locale_setup ( ) { + if ( !is_admin() ) { + unset($GLOBALS['wp_locale']); + global $wp_locale; + $wp_locale = new xl_WP_Locale(); + } + } + + /** + * only called in front-end + * + * @since 2.4.0 + * + */ + function translate_date_format ( $format ) { + if ( $this->xili_settings['wp_locale'] == 'wp_locale' ) + return __( $format , $this->thetextdomain ); + else + return $format; + } + + /** + * fixes feed link if not permalinks because called after category filter + * + * @since 2.8.1 + * + */ + function category_feed_link ( $link, $feed = '' ) { + $permalink_structure = get_option( 'permalink_structure' ); + + if ( '' != $permalink_structure ) { + if ( $feed == get_default_feed() ) + $feed_link = 'feed'; + else + $feed_link = "feed/$feed"; + // clean current link + $root_link = str_replace ( user_trailingslashit( $feed_link, 'feed' ), '', $link ); + // get part after ?lang= + $parts = explode ( '?'.QUETAG.'=', $root_link ); + if ( isset( $parts[1] ) ) { + // recreate current link + $link = trailingslashit( $parts[0] ) . user_trailingslashit( $feed_link, 'feed' ) . '?'.QUETAG.'='. str_replace ( '/','',$parts[1] ); + } + } + return $link; + + } + + /** + * 'theme_locale' filter to detect theme and don't load theme_domain in functions.php + * + * @since 1.5.0 + * + * call by 'theme_locale' filter + */ + function xiliml_theme_locale ( $locale, $domain ) { + $this->xili_settings['theme_domain'] = $domain; + $this->thetextdomain = $domain; - if ($this->locale_method) { - $this->xiliml_load_theme_textdomain (THEME_TEXTDOMAIN); /* new method for cache compatibility - tests */ - } else { - $this->set_mofile($this->curlang); + //if ( defined ( "WP_DEBUG" ) && WP_DEBUG == true ) error_log ( $this->class_admin . ' < domain = ' . $domain ) ; + + return 'wx_YZ'; // dummy local + } + + /** + * 'override_load_textdomain' filter to avoid dummy load + * + * @since 1.5.0 + * @updated 1.8.1 - 1.8.5 + * + */ + function xiliml_override_load ( $falseval, $domain, $mofile ) { + if ( $this->show ) { + if ( !in_array( $domain , $this->arraydomains ) ) + $this->arraydomains[] = $domain; } + if (false === strpos ($mofile ,'wx_YZ.mo')) {// + return false; + } else { + if ( str_replace( get_stylesheet_directory(), '', $mofile ) == $mofile ) { // no effect + $this->get_template_directory = get_template_directory(); + $this->xili_settings['langs_in_root_theme'] = 'root'; + } else { + $this->get_template_directory = get_stylesheet_directory(); // a load is in child + $this->xili_settings['langs_in_root_theme'] = ''; + + } + $this->ltd = true ; + + $langs_folder = str_replace('/wx_YZ.mo','',str_replace( $this->get_template_directory, '', $mofile )); + // in wp3 the detection is only done here (end user side by theme domain) so updated is mandatory for xili-dico + if ( $this->xili_settings['langs_folder'] != $langs_folder ) { + $this->xili_settings['langs_folder'] = $langs_folder ; + update_option( 'xili_language_settings', $this->xili_settings ); + } + // to restore theme mo if theme datas and terms in admin ui…. + if ( is_admin() ) load_textdomain( $domain, str_replace('wx_YZ', get_locale(), $mofile )); // 2.3.1 - 18h18 + return true; + + } + } + + /** + * + * Introduced only in visitors side (not in admin) to change domain of plugin or other + * gettext filter from function translate() in wp-includes/I10n.php + * + * @since 1.8.7 - 1.8.8 + */ + function change_plugin_domain ($translation, $text, $domain ) { + + $domain = $this->switching_domain ( $domain ); + + $translations = &get_translations_for_domain( $domain ); + return $translations->translate( $text ); + } + function change_plugin_domain_with_context ($translation, $text, $context, $domain ) { + + $domain = $this->switching_domain ( $domain ); + + $translations = &get_translations_for_domain( $domain ); + return $translations->translate( $text, $context ); + } + function change_plugin_domain_plural ($translation, $single, $plural, $number, $domain ) { + + $domain = $this->switching_domain ( $domain ); + + $translations = &get_translations_for_domain( $domain ); + $translation = $translations->translate_plural( $single, $plural, $number ); + return $translation ; + } + function change_plugin_domain_plural_with_context ($translation, $single, $plural, $number, $context, $domain ) { + + $domain = $this->switching_domain ( $domain ); + + $translations = &get_translations_for_domain( $domain ); + $translation = $translations->translate_plural( $single, $plural, $number, $context ); + return $translation ; + } + + /** + * domain switching + */ + function switching_domain ( $domain ) { + $ok = false ; + if ( $domain != $this->thetextdomain ) { + if ( in_array ( $domain, array_keys( $this->xili_settings['domains'] ) ) ) { + if ( $this->xili_settings['domains'][$domain] == 'enable' ) $ok = true ; + } else { + if ( $this->xili_settings['domains']['all'] == 'enable' ) $ok = true ; + } + if ( $ok ) + $domain = $this->thetextdomain ; + } + return $domain; } /** @@ -479,7 +1420,7 @@ * * call by locale hook */ - function xiliml_setlocale ($locale) { + function xiliml_setlocale ( $locale ) { if ($this->theme_locale === true) { $listlanguages = get_terms(TAXONAME, array('hide_empty' => false,'slug' => $this->curlang)); return $listlanguages[0]->name; @@ -495,101 +1436,144 @@ * * call by locale hook */ - function xiliml_load_theme_textdomain ($domain) { + 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); + $langfolder = $this->xili_settings['langs_folder']; + //$langfolder = '/'.str_replace("/","",$langfolder); /* please no lang folder in sub-subfolder */ + $langfolder = ($langfolder == "/") ? "" : $langfolder; + load_theme_textdomain($domain, $this->get_template_directory . $langfolder); $this->theme_locale = false; } /** * select .mo file * @since 0.9.0 - * @updated 0.9.7.1 - 1.1.9 + * @updated 0.9.7.1 - 1.1.9 - 1.5.2 wpmu - 1.8.9.1 (domain select) * call by function xiliml_language_wp() * @param $curlang . */ - function set_mofile($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 */ + if ( ""!=$this->thetextdomain ) { $themetextdomain = $this->thetextdomain; } else { $themetextdomain = 'ttd-not-defined'; } + $langfolder = $this->xili_settings['langs_folder']; + $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); + + $filename = ''; + if ( '' != $curlang ) { + + $filename = $this->langs_slug_name_array[$curlang]; // 2.4.2 + } + + if ( '' != $filename ) { + $filename .= '.mo'; + $mofile = $this->get_template_directory .$langfolder."/$filename"; + + if ( is_multisite() ) { /* completes theme's language with db structure languages (cats, desc,…) */ + if ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) { + $wpmu_curdir = $uploads['basedir']."/languages"; + load_textdomain( $themetextdomain, $wpmu_curdir."/local-" . $this->langs_slug_name_array[$curlang] . ".mo" ); // here to be the last value + load_textdomain( $themetextdomain, $wpmu_curdir."/$filename" ); + } + } + load_textdomain( $themetextdomain, $this->get_template_directory .$langfolder."/local-" . $this->langs_slug_name_array[$curlang] . ".mo" ); // here to be the last value + load_textdomain( $themetextdomain, $mofile ); // moved here for merge (prior for site and not theme) + + // 2.8.1 + do_action ( 'xiliml_add_frontend_mofiles' , $themetextdomain, $this->langs_slug_name_array[$curlang] ); // to add bbpress good mo + } } /** - * default rules - set curlang in head according rules + * default rules - set curlang for wp action * - * @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 . + * @since 1.7.0 - new mechanism for front-page + * @updated 1.8.9.1 - better category case + * @updated 2.2.3 - fixes rare frontpage infinite loop + * replace xiliml_cur_lang_head (0.9.7 -> 1.6.1) + * @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*/ + function get_curlang_action_wp () { + + if ( has_filter( 'xiliml_curlang_action_wp' ) ) return apply_filters( 'xiliml_curlang_action_wp', '' ); /* '' 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*/ + global $post, $wp_query ; + + + if ( have_posts() ) { + $showpage = get_option('show_on_front'); + $condition = false; + if ( 'page' == $showpage ) { + if (!in_array ( $wp_query->query_vars['page_id'], $this->xili_settings['show_page_on_front_array'] ) ) $condition = true; + } else { + if ( !is_home() ) $condition = true; + } + + if ( $condition ) { /* every pages !is_front_page() */ + $curlangdir = $this->get_cur_language($post->ID); + $curlang = $curlangdir[QUETAG]; /* the first post give the current lang*/ + if ( $curlangdir == false ) $curlang = $this->choice_of_browsing_language(); //$this->default_slug; /* no more constant - wpmu - 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*/ } - } else { /* front page */ - if ( '' != $wp_query->query_vars[QUETAG] ) { - $curlang = $wp_query->query_vars[QUETAG]; /* home series type*/ + // + if ( isset($wp_query->query_vars[QUETAG]) ) { + $curlang = $wp_query->query_vars[QUETAG] ; + } + } elseif ( is_search() ) { + if ( isset( $wp_query->query_vars[QUETAG] ) ) $curlang = $wp_query->query_vars[QUETAG] ; // + } elseif ( is_category() ) { + if ( $this->lang_perma ) { + if ( isset( $wp_query->query_vars[QUETAG] ) ) { + $curlang = str_replace ( LANG_UNDEF, "", $wp_query->query_vars[QUETAG]) ; + } else { + $curlang = $this->choice_of_categories_all_languages( $curlang ) ; + } } 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); - } + if ( isset( $_GET[QUETAG] ) ) { + $curlang = $_GET[QUETAG] ; + } else { + $curlang = $this->choice_of_categories_all_languages( $curlang ) ; //$this->choice_of_browsing_language(); // again as defined 1.8.9.1 + } + } + } + } else { /* front page - switch between lang (and post/page) is done in query posts_where_lang filter see above */ + + + if ( isset ( $wp_query->query_vars[QUETAG] ) && '' != $wp_query->query_vars[QUETAG] ) { + $this->langstate = true; // 2.8.0 b + $curlang = $wp_query->query_vars[QUETAG]; // home series type + } else { + + if ( 'page' == $showpage ) { //$this->show_page_on_front ) { + $page_front = get_option('page_on_front'); + $curlang = get_cur_language($page_front); + } else { // home.php - 1.3.2 + $curlang = $this->choice_of_browsing_language(); } } - } 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*/ + } + } else { /*no posts for instance in category + lang */ + if ( $this->lang_perma ) { + if ( isset( $wp_query->query_vars[QUETAG] ) ) { + $curlang = $wp_query->query_vars[QUETAG] ; + } else { + $curlang = $this->choice_of_browsing_language(); + } + } else { + if ( isset( $_GET[QUETAG] ) ) { + $curlang = $_GET[QUETAG]; + } else { + $curlang = $this->choice_of_browsing_language() ; //$this->choice_of_browsing_language(); // again as defined 1.8.9.1 + } + } + } + + + return str_replace ( LANG_UNDEF , '' , $curlang ) ; // 2.3 to return main part } /** @@ -601,33 +1585,41 @@ * * @param $output */ - function head_language_attributes($output) { + function head_language_attributes( $output ) { /* hook head_language_attributes */ - if (has_filter('head_language_attributes')) return apply_filters('head_language_attributes',$output); + + 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))); + if ( $this->langstate = true ) { + if (strlen($this->curlang) == 5) { + $lang = str_replace('_','-',substr( $this->curlang, 0, 3).strtoupper( substr( $this->curlang, -2))); + } else { + $lang = $this->curlang; //1.5.2 for ja as commented in 200909 + } } 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 + + $listlanguages = $this->get_listlanguages(); + if ( $listlanguages ) { + foreach ( $listlanguages as $language ) { + $listlang[] = str_replace( '_', '-', $language->name ); + } + $lang = $listlang[0]; // implode(', ',$listlang); // not w3c compatible + } } - if ( get_option('html_type') == 'text/html') + if ( get_option('html_type') == 'text/html' ) $attributes[] = "lang=\"$lang\""; - - if ( get_option('html_type') != 'text/html') + // to use both - use the hook - head_language_attributes + if ( get_option('html_type') != 'text/html' ) $attributes[] = "xml:lang=\"$lang\""; $output = implode(' ', $attributes); + return $output; } @@ -640,21 +1632,190 @@ * * @param $curlang */ - function head_insert_language_metas($curlang,$undefined=true) { - $curlang = $this->curlang; + function head_insert_language_metas( ) { + $curlang = $this->curlang; $undefined = $this->langstate; - echo "\n"; - if (has_filter('head_insert_language_metas')) return apply_filters('head_insert_language_metas',$curlang,$undefined); + echo "\n"; + if ( has_filter('head_insert_language_metas') ) return apply_filters( 'head_insert_language_metas', $curlang, $undefined ); + } + + /** + * insert hreflang link in head (via wp_head) + * + * @since 2.5 + * as commented in Google rel="alternate" + * + * to change rules or be compatible with cpt and taxonomy use head_insert_hreflang_link filter + * + * @param $curlang + */ + function head_insert_hreflang_link ( ) { + if ( has_filter('head_insert_hreflang_link') ) return apply_filters( 'head_insert_hreflang_link', $this->curlang ); + global $post, $cat; + if ( is_front_page() || is_category () ) { + $listlanguages = $this->get_listlanguages(); + $currenturl = $this->current_url ( $this->lang_perma ); + foreach ( $listlanguages as $language ) { + if ( $language->slug != $this->curlang ) { + if ( is_category() ) { + $category = get_category ( $cat ); // test targets count + if ( 0 < $this->count_posts_in_taxonomy_and_lang ( 'category', $category->slug , $language->slug ) ) { + $do_it = true; // + } else { + $do_it = false; + } + } else { + $do_it = true; + } + if ( $do_it ) { + $lang = str_replace( '_', '-', $language->name ); + $hreflang = ( $this->lang_perma ) ? str_replace ( '%lang%', $language->slug, $currenturl ) : $currenturl.QUETAG."=".$language->slug ; + printf ( ''."\n", $lang, $hreflang ) ; + } + } + + } + } elseif ( is_singular() ) { + $listlanguages = $this->get_listlanguages(); + foreach ( $listlanguages as $language ) { + $targetpost = $this->linked_post_in ( $post->ID, $language->slug ) ; + if ( $language->slug != $this->curlang && !empty ( $targetpost ) ) { + $hreflang = $this->link_of_linked_post ( $post->ID, $language->slug ) ; + $lang = str_replace( '_', '-', $language->name ); + printf ( ''."\n", $lang, $hreflang ) ; + } + } + } + } + + /** + * used in head_insert_hreflang_link and in xili_language_list + * + * @since 2.5 + */ + function current_url ( $lang_perma ) { + if ( $lang_perma ) { + if (is_category()) { + remove_filter('term_link', 'insert_lang_4cat') ; + $catcur = xiliml_get_category_link(); + add_filter( 'term_link', 'insert_lang_4cat', 10, 3 ); + $currenturl = $catcur; + } else { + $currenturl = get_bloginfo('url').'/%lang%/'; + } + } else { + if (is_category()) { + $catcur = xiliml_get_category_link(); + $permalink = get_option('permalink_structure'); /* 1.6.0 */ + $sep = ('' == $permalink) ? "&" : "?" ; + $currenturl = $catcur.$sep; + } else { + $currenturl = get_bloginfo('url').'/?'; + } + } + return $currenturl; } /** - * Translate texts of widgets + * return count of posts in taxonomy and language * - * @since 0.9.8.1 + * called by head_insert_hreflang_link + * available for specific behaviour - why not in custom plugin for xili_language_list or... + * @params taxonomy (category), current slug, current lang + * @since 2.5 + */ + function count_posts_in_taxonomy_and_lang ( $taxonomy, $slug = '' , $language = '', $post_type = 'post' ) { + + $args = array( + 'post_type' => $post_type, + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => $taxonomy, + 'field' => 'slug', + 'terms' => array( $slug ) + ), + array( // language + 'taxonomy' => TAXONAME, + 'field' => 'slug', + 'terms' => array( $language ) + ) + ) + ); + $query = new WP_Query( $args ); + + return $query->found_posts; + } + + /** + * Translate texts of widgets or other simple text... + * + * @updated 1.6.0 - Old name widget_texts + * @since 0.9.8.1 + * @ return + */ + function one_text ( $value ){ + if ('' != $value) + return __($value, $this->thetextdomain); + else + return $value; + } + + /** + * Translate title of wp nav menu + * + * @since 1.6.0 * @ return */ - function widget_texts ($value){ - return __($value,THEME_TEXTDOMAIN); + function wp_nav_title_text ( $value = "", $itemID = 0 ){ + if ('' != $value) { + return __( $value, $this->thetextdomain ); + } else { + return $value; + } + } + + /** + * Add filters of texts of comment form - because default text are linked with wp language (and not theme) + * + * @since 1.5.5 + * @ return arrays with themetextdomain + */ + function xili_comment_form_default_fields ( $fields ) { + $commenter = wp_get_current_commenter(); + + $req = get_option( 'require_name_email' ); + $aria_req = ( $req ? " aria-required='true'" : '' ); + $fields = array( + 'author' => '
', + 'email' => '' . ( $req ? '*' : '' ) . + '
', + 'url' => '' . + '
', + ); + return $fields; + } + /** 2.3.2 - noun context */ + function xili_comment_form_defaults ( $defaults ) { + global $user_identity, $post; + $req = get_option( 'require_name_email' ); + $xilidefaults = array( + + 'comment_field' => '', + 'must_log_in' => '' . sprintf( __( $this->comment_form_labels['youmustbe'], $this->thetextdomain ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post->ID ) ) ) ) . '
', + 'logged_in_as' => '' . sprintf( __( $this->comment_form_labels['loggedinas'], $this->thetextdomain ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post->ID ) ) ) ) . '
', + 'comment_notes_before' => '' . __( $this->comment_form_labels['emailnotpublished'], $this->thetextdomain ) . ( $req ? __( $this->comment_form_labels['requiredmarked'], $this->thetextdomain ) : '' ) . '
', + 'comment_notes_after' => ' ', + 'id_form' => 'commentform', + 'id_submit' => 'submit', + 'title_reply' => __( $this->comment_form_labels['leavereply'], $this->thetextdomain ), + 'title_reply_to' => __( $this->comment_form_labels['replyto'], $this->thetextdomain ), + 'cancel_reply_link' => __( $this->comment_form_labels['cancelreply'], $this->thetextdomain ), + 'label_submit' => __( $this->comment_form_labels['postcomment'], $this->thetextdomain ), + ); + $args = wp_parse_args( $xilidefaults, $defaults); + return $args; } /** @@ -666,9 +1827,9 @@ * call by do_filter list_cats * @param $content, $category */ - function xiliml_cat_language ($content, $category = null) { + 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*/ + $new_cat_name = (!is_admin()) ? __($category->name,$this->thetextdomain) : $content ; /*to detect admin UI*/ return $new_cat_name; } @@ -676,16 +1837,22 @@ * add the language key in category links of current pages * * @since 0.9.0 - * update 0.9.7 + * update 0.9.7 1.5.1 * 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); + function xiliml_link_append_lang( $link, $category_id = 0 ) { + if ( has_filter( 'xiliml_link_append_lang' ) ) return apply_filters( 'xiliml_link_append_lang', $link, $category_id, $this->curlang ); /*default*/ + if ($this->curlang) : - $link .= '&'.QUETAG.'='.$this->curlang ; + if ( !$this->lang_perma ){ // 2.1.1 + $permalink = get_option( 'permalink_structure' ); + $sep = ('' == $permalink) ? "&".QUETAG."=" : "?".QUETAG."="; + $link .= $sep.$this->curlang ; // wpmu + } + endif; return $link; @@ -713,31 +1880,50 @@ */ return $taglink; } + + /** + * Setup global post data. + * + * @since 1.6.0 + * can be hooked by filter add_filter('xiliml_bloginfo','yourfunction',10,3) in functions.php + * + * @param $output, $show. + * @return translated $output. + */ + function xiliml_bloginfo ( $output, $show ) { + if (has_filter('xiliml_bloginfo')) return apply_filters('xiliml_bloginfo',$output, $show, $this->curlang); + $info_enabled = array('name', 'blogname', 'description'); + if (in_array($show, $info_enabled)) { + return __($output, $this->thetextdomain); + } else { + return $output; + } + } /** * to cancel sub select by lang in cat 1 by default * * @since 0.9.2 - * update 0.9.7 + * update 0.9.7 - 1.8.4 * can be hooked by filter add_filter('xiliml_modify_querytag','yourfunction') in functions.php * * */ function xiliml_modify_querytag() { - if (has_filter('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)) { + /*default*/ + global $wp_query; + if ( defined('XILI_CATS_ALL') && !empty($wp_query->query_vars['cat']) ) { /* change in functions.php or use hook in cat 1 by default*/ + $excludecats = explode(",", XILI_CATS_ALL); + if ( $excludecats != array() && in_array($wp_query->query_vars['cat'],$excludecats) ) { $wp_query->query_vars[QUETAG] = ""; /* to cancel sub select */ } } } - } + } + /** * filters for wp_get_archives * @@ -745,16 +1931,16 @@ * @params $join or $where and template params * */ - function xiliml_getarchives_join($join,$r) { + 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; + $this->get_archives_called[QUETAG] = $this->curlang; } else { - $this->get_archives_called['lang'] = $lang; + $this->get_archives_called[QUETAG] = $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) "; @@ -763,7 +1949,7 @@ } - function xiliml_getarchives_where($where,$r) { + 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 ); @@ -773,7 +1959,7 @@ } else { $curlang = $lang; } - $reqtag = is_term( $curlang, TAXONAME ); + $reqtag = term_exists( $curlang, TAXONAME ); if (''!= $reqtag) { $wherereqtag = $reqtag['term_id']; } else { @@ -785,13 +1971,13 @@ 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); + /** *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) { + if ( isset( $lang ) && '' != $lang ) { $permalink = get_option('permalink_structure'); - $sep = ('' == $permalink) ? "&lang=" : "?lang="; + $sep = ('' == $permalink) ? "&".QUETAG."=" : "?".QUETAG."="; if ($format != 'option' && $format != 'link' && $type != 'postbypost' && $type != 'alpha') { /* text extract */ $i = preg_match_all("/'>(.*)<\/a>/Ui", $link_html, $matches,PREG_PATTERN_ORDER); @@ -800,7 +1986,7 @@ $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]); + $archivedate = str_replace(get_bloginfo('url').'/?' , "" , $matches[1][0]); $r = wp_parse_args( $archivedate, array()); extract($r, EXTR_SKIP ); $month = substr($m,-2); @@ -811,7 +1997,7 @@ */ $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); + if ($i) { $month = $results[2][0]; $year = $results[1][0]; } @@ -838,9 +2024,9 @@ * * */ - function xiliml_link_translate_desc( $description, $category=null,$context='') { + 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 ; + $translated_desc = ($this->curlang && ''!= $description) ? __($description, $this->thetextdomain) : $description ; return $translated_desc; } @@ -849,9 +2035,9 @@ * since 1.4.1 * */ - function xiliml_single_cat_title_translate ($cat_name) { + 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; + $translated = ($this->curlang && ''!= $cat_name) ? __($cat_name,$this->thetextdomain) : $cat_name; return $translated; } @@ -859,15 +2045,18 @@ * 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 - * + * @updated 2.7.1 * @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)) { + if( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) && 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; + if(isset($match[3])) { + $preferred_languages[$match[1]] = floatval($match[3]); + } else { + $preferred_languages[$match[1]] = 1.0; + } } return $preferred_languages; } else { @@ -895,24 +2084,26 @@ * thanks to php.net comments HTTP_ACCEPT_LANGUAGE * @since 0.9.7.5 * @update 0.9.9.4 - * @return array (non sorted) + * @update 2.3.1 - lang_neither_browser + * @return default target language */ 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 */ + if ( has_filter('choice_of_browsing_language') ) return apply_filters('choice_of_browsing_language',''); // '' 2.3.1 + 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)) { + $default_lang = ( "" != $this->lang_neither_browser ) ? $this->lang_neither_browser : $this->default_lang ; //2.3.1 + 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); + $sitelanguage = $this->match_languages ( $listofprefs, $listlanguages ); + if ( $sitelanguage ) return $sitelanguage->slug; + return strtolower( $default_lang ); } else { - return strtolower($this->default_lang); + return strtolower( $default_lang ); } } - function match_languages ($listofprefs,$listlanguages) { + function match_languages ( $listofprefs, $listlanguages ) { foreach($listofprefs as $browserlanguage => $priority) { /* match root languages to give similar in site - first : five chars langs*/ @@ -928,519 +2119,224 @@ } } - /********************************** ADMIN UI ***********************************/ - /** - * add admin menu and associated pages of admin UI + * Choice of language when is_category and all languages * - * @since 0.9.0 - * @updated 0.9.6 - only for WP 2.7.X - do registering of new meta boxes and JS + * @since 1.8.9.1 + * called by get_curlang_action_wp * */ - 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'); - + function choice_of_categories_all_languages( $curlang ) { + $choice = $this->xili_settings['allcategories_lang']; + if ( $choice == "browser" ) { + return $this->choice_of_browsing_language(); + } elseif ( $choice == "firstpost" ) { + return $curlang ; + } elseif ( $choice == "" ) { + if ( function_exists('xl_choice_of_categories_all_languages') ) { + return xl_choice_of_categories_all_languages () ; + } else { + return ''; // return without mo + } + } + return $choice; } /** - * 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) + * to encapsulate future method * - * @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 + * @since 1.8.9.1 + * @param post_ID and lang slug */ - 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 = '-
- -
- | + function translate_page_on_front_ID ( $original_id ) { + + if ( $this->lang_perma ) { + global $wp_query ; + + if ( !is_admin() && $this->show_page_on_front ) { + 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'] ) { + $curlang = $wp_query->query_vars[QUETAG]; + + + } elseif ( isset( $wp_query->query_vars[QUETAG] ) && in_array ( $wp_query->query_vars[QUETAG], array_keys ( $this->show_page_on_front_array ) ) ){ + + $curlang = $wp_query->query_vars[QUETAG]; // to verify + } else { + //$first_query = get_option('xili_language_settings_test') ; + //if ( $first_query ) { + //$curlang = $first_query ; + //} else { + $curlang = $this->choice_of_browsing_language(); // rule defined in admin UI + + //} + } + $trans_id = $this->linked_post_in( $original_id, $curlang ) ; - | "." ".__($language->description,'xili-language') ." | "." ".__('Edit') ." |
---|---|---|---|
/> |
All is OK '.$post_id.' ('.$mess.')
'; // voir bannière // - die(); - - } - /** - * to display the languages settings admin UI + * unassign a language from a series of objects (post or link) + * @since 1.8.8 * - * @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; + function multilingual_links_erase ( $lang_term_id ) { + $languages = $this -> get_listlanguages(); - 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') ?>
- | - | - | - | - | - | - |
---|
: | -/> | -
---|---|
: | -/> | -
: | -/> | - -
: | -/> | - -
- | - - | -
';
+ echo ''.__( 'Installation of xili-language is not completed.', 'xili_language_errors' ) . '';
+ echo '
';
+ printf( __( 'This xili-language version (%s) need PHP Version more than %s; installed release is %s.', 'xili_language_errors' ), XILILANGUAGE_VER , XILILANGUAGE_PHP_VER, PHP_VERSION ) ;
+ echo '
';
+ printf( __( 'Find a server with PHP Version to more %s or use xili-language version less or equal to %s', 'xili_language_errors' ), XILILANGUAGE_PHP_VER, XILILANGUAGE_PREV_VER );
+ echo '
';
+ echo ''.__( 'Installation of xili-language is not completed.', 'xili_language_errors' ) . '';
+ echo '
';
+ printf( __( 'This xili-language version (%s) need WordPress Version more than %s; installed release is %s.', 'xili_language_errors' ), XILILANGUAGE_VER , XILILANGUAGE_WP_VER, $wp_version) ;
+ echo '
';
+ printf( __( 'Upgrade WordPress Version to more %s or use xili-language version less than %s', 'xili_language_errors' ), XILILANGUAGE_WP_VER, XILILANGUAGE_PREV_VER );
+ echo '