function qtranxf_get_url_info($url) { $urlinfo = qtranxf_parseURL($url); qtranxf_complete_url_info($urlinfo); qtranxf_complete_url_info_path($urlinfo); return $urlinfo; }
function qtranxf_detect_language(&$url_info) { global $q_config; if (defined('WP_ADMIN') || defined('WP_CLI')) { $siteinfo = qtranxf_get_site_info(); $url_info['path-base'] = $siteinfo['path']; $url_info['path-base-length'] = $siteinfo['path-length']; } else { qtranxf_complete_url_info($url_info); if (!isset($url_info['path-base'])) { //path did not match neither 'site' nor 'home', but it came to this code, then redirect to home. //may happen for testing $target = get_option('home'); wp_redirect($target); exit; } $url_info['doing_front_end'] = true; } $lang = qtranxf_parse_language_info($url_info); if ((!$lang || !isset($url_info['doing_front_end'])) && (defined('DOING_AJAX') || !$url_info['cookie_enabled']) && isset($_SERVER['HTTP_REFERER'])) { //get language from HTTP_REFERER, if needed, and detect front- vs back-end $http_referer = $_SERVER['HTTP_REFERER']; $url_info['http_referer'] = $http_referer; if (strpos($http_referer, '/wp-admin') !== FALSE) { $url_info['referer_admin'] = true; if (!isset($url_info['doing_front_end'])) { $url_info['doing_front_end'] = false; } } else { $ref_info = qtranxf_parseURL($http_referer); if (!qtranxf_external_host($ref_info['host'])) { //determine $ref_info['path-base'] qtranxf_complete_url_info($ref_info); if (isset($ref_info['path-base'])) { $url_info['internal_referer'] = true; //$ref_info['url'] = $ref_info['path']; if (!$lang || !(isset($url_info['doing_front_end']) || isset($ref_info['doing_front_end']))) { $lang = qtranxf_parse_language_info($ref_info, true); if ($lang === false) { unset($url_info['internal_referer']); } } $url_info['referer_language'] = $lang; if (!isset($url_info['doing_front_end']) && isset($ref_info['doing_front_end'])) { $url_info['doing_front_end'] = $ref_info['doing_front_end']; } } } if (!$lang && $q_config['hide_default_language'] && isset($url_info['doing_front_end']) && $url_info['doing_front_end']) { $lang = $q_config['default_language']; } } } //$url_info['doing_front_end'] defines if we are in front- or back-end. Why WP does not have that, or does it? if (!isset($url_info['doing_front_end'])) { $url_info['doing_front_end'] = !defined('WP_ADMIN'); } if (!$lang) { if ($url_info['doing_front_end']) { $lang = qtranxf_detect_language_front($url_info); } else { $lang = qtranxf_detect_language_admin($url_info); } } $url_info['set_cookie'] = !defined('DOING_AJAX'); /** * Hook for possible other methods * Set $url_info['language'] with the result */ $lang = apply_filters_ref_array('i18n_detect_language', array($lang, &$url_info)); $url_info['language'] = $lang; /** * Hook for possible other methods * Set $url_info['language'] with the result */ $url_info = apply_filters('qtranslate_detect_language', $url_info); //obsolete, use the above filter instead $lang = $url_info['language']; //qtranxf_dbg_log('qtranxf_detect_language: detected: url_info: ',$url_info); if ($url_info['set_cookie']) { qtranxf_set_language_cookie($lang); } return $lang; }