function qtranxf_reloadConfig() { global $q_config; $url_info = isset($q_config['url_info']) ? $q_config['url_info'] : null; //qtranxf_dbg_log('qtranxf_reloadConfig: $url_info: ',$url_info); qtranxf_del_conf_filters(); qtranxf_loadConfig(); qtranxf_admin_loadConfig(); if ($url_info) { $q_config['url_info'] = $url_info; if (isset($q_config['url_info']['language'])) { $q_config['language'] = $q_config['url_info']['language']; } if (!qtranxf_isEnabled($q_config['language'])) { $q_config['language'] = $q_config['default_language']; } //qtranxf_dbg_log('qtranxf_reloadConfig: $q_config[language]: ',$q_config['language']); } qtranxf_load_option_qtrans_compatibility(); }
function qtranxf_init_language() { global $q_config, $pagenow; //qtranxf_dbg_log('1.qtranxf_init_language:'); //if(defined('QTRANS_INIT')){ // //qtranxf_dbg_log('qtranxf_init_language: QTRANS_INIT: url_info: ',$q_config['url_info']); // return; //} //define('QTRANS_INIT',true); qtranxf_loadConfig(); //'url_info' hash is not for external use, it is subject to change at any time. //'url_info' is preserved on reloadConfig if (!isset($q_config['url_info'])) { $q_config['url_info'] = array(); } $url_info =& $q_config['url_info']; $url_info['cookie_enabled'] = isset($_COOKIE[QTX_COOKIE_NAME_FRONT]) || isset($_COOKIE[QTX_COOKIE_NAME_ADMIN]); if (WP_DEBUG) { $url_info['pagenow'] = $pagenow; $url_info['REQUEST_METHOD'] = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : ''; if (defined('WP_ADMIN') && WP_ADMIN) { $url_info['WP_ADMIN'] = true; } if (defined('DOING_AJAX')) { $url_info['DOING_AJAX_POST'] = $_POST; } if (defined('DOING_CRON')) { $url_info['DOING_CRON_POST'] = $_POST; } } //fill $url_info the same way as _parseURL does $url_info['scheme'] = is_ssl() ? 'https' : 'http'; $url_info['host'] = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; //https://wordpress.org/support/topic/messy-wp-cronphp-command-line-output if (empty($_SERVER['REQUEST_URI'])) { $url_info['path'] = ''; } else { $url_info['path'] = $_SERVER['REQUEST_URI']; $p = strpos($url_info['path'], '?'); if ($p) { $url_info['path'] = substr($url_info['path'], 0, $p); if (empty($_SERVER['QUERY_STRING'])) { $url_info['query'] = substr($url_info['path'], $p + 1); } else { $url_info['query'] = $_SERVER['QUERY_STRING']; } $url_info['query'] = qtranxf_sanitize_url($url_info['query']); // to prevent xss if (strpos($url_info['query'], 'qtranslate-mode=raw') !== false) { $url_info['qtranslate-mode'] = 'raw'; $url_info['doing_front_end'] = true; $q_config['url_info'] = $url_info; $q_config['url_info']['language'] = $q_config['default_language']; $q_config['language'] = $q_config['default_language']; //qtranxf_load_option_qtrans_compatibility(); return; } } } $url_info['original_url'] = $_SERVER['REQUEST_URI']; //is in use in -slug, here is for debugging purpose only //qtranxf_dbg_log('qtranxf_init_language: SERVER: ',$_SERVER); $url_info['language'] = qtranxf_detect_language($url_info); $q_config['language'] = apply_filters('qtranslate_language', $url_info['language'], $url_info); //qtranxf_dbg_log('qtranxf_init_language: detected: url_info: ',$url_info); if ($q_config['url_info']['doing_front_end'] && qtranxf_can_redirect()) { $lang = $q_config['language']; $url_orig = $url_info['scheme'] . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $url_lang = qtranxf_convertURL('', $lang); //uses $q_config['url_info'] and caches information, which will be needed later anyway. if (!isset($url_info['doredirect']) && $url_orig != $url_lang) { $url_info['doredirect'] = '$url_orig != $url_lang'; } if (isset($url_info['doredirect'])) { $target = apply_filters('qtranslate_language_detect_redirect', $url_lang, $url_orig, $url_info); //qtranxf_dbg_log('qtranxf_init_language: doredirect to '.$lang.PHP_EOL .'urlorg:'.$url_orig.PHP_EOL .'target:'.$target.PHP_EOL .'url_info: ',$url_info); if ($target !== false && $target != $url_orig) { wp_redirect($target); //header('Location: '.$target); exit; } else { //neutral path $url_info['doredirect'] .= ' - cancelled, because it goes to the same target - neutral URL'; if ($pagenow == 'index.php' && $q_config['url_mode'] == QTX_URL_PATH) { $_SERVER['REQUEST_URI'] = trailingslashit($url_info['path-base']) . $lang . $url_info['wp-path']; //should not hurt? if (!empty($url_info['query'])) { $_SERVER['REQUEST_URI'] .= '?' . $url_info['query']; } } } //qtranxf_dbg_log('qtranxf_init_language: doredirect canceled: $url_info: ',$url_info); } } elseif (isset($url_info['doredirect'])) { $url_info['doredirect'] .= ' - cancelled by can_redirect'; //qtranxf_dbg_log('qtranxf_init_language: doredirect canceled: $url_info: ',$url_info); } // fix url to prevent xss - how does this prevents xss? //$q_config['url_info']['url'] = qtranxf_convertURL(add_query_arg('lang',$q_config['default_language'],$q_config['url_info']['url'])); //qtranslate_hooks.php has to go before load_plugin_textdomain() require_once dirname(__FILE__) . '/qtranslate_hooks.php'; //common hooks moved here from qtranslate.php since 3.2.9.2, because they all need language already detected // load plugin translations // since 3.2-b3 moved it here as https://codex.wordpress.org/Function_Reference/load_plugin_textdomain seem to recommend to run load_plugin_textdomain in 'plugins_loaded' action, which is this function respond to $lang_dir = qtranxf_plugin_dirname() . '/lang'; load_plugin_textdomain('qtranslate', false, $lang_dir); /** * allow other plugins to initialize whatever they need before the fork between front and admin. */ do_action('qtranslate_load_front_admin', $url_info); if ($q_config['url_info']['doing_front_end']) { require_once QTRANSLATE_DIR . '/qtranslate_frontend.php'; } else { require_once QTRANSLATE_DIR . '/admin/qtx_admin.php'; } apply_filters('wp_translator', null); //create QTX_Translator object qtranxf_load_option_qtrans_compatibility(); /** * allow other plugins to initialize whatever they need for language */ do_action('qtranslate_init_language', $url_info); //qtranxf_dbg_log('qtranxf_init_language: done: url_info: ',$url_info); }
function qtranxf_init_language() { global $q_config, $pagenow; //if(defined('QTRANS_INIT')){ // //qtranxf_dbg_log('qtranxf_init_language: QTRANS_INIT: url_info: ',$q_config['url_info']); // return; //} //define('QTRANS_INIT',true); qtranxf_loadConfig(); $q_config['cookie_enabled'] = isset($_COOKIE[QTX_COOKIE_NAME_FRONT]) || isset($_COOKIE[QTX_COOKIE_NAME_ADMIN]); $q_config['url_info'] = array(); //'url_info' hash is not for external use, it is subject to change at any time. $url_info =& $q_config['url_info']; if (WP_DEBUG) { $url_info['pagenow'] = $pagenow; if (defined('WP_ADMIN') && WP_ADMIN) { $url_info['WP_ADMIN'] = true; } if (defined('DOING_AJAX')) { $url_info['DOING_AJAX_POST'] = $_POST; } if (defined('DOING_CRON')) { $url_info['DOING_CRON_POST'] = $_POST; } } //fill $url_info the same way as _parseURL does $url_info['scheme'] = is_ssl() ? 'https' : 'http'; $url_info['host'] = $_SERVER['HTTP_HOST']; if (empty($_SERVER['REQUEST_URI'])) { $url_info['path'] = ''; } else { $url_info['path'] = $_SERVER['REQUEST_URI']; $p = strpos($url_info['path'], '?'); if ($p) { $url_info['path'] = substr($url_info['path'], 0, $p); if (empty($_SERVER['QUERY_STRING'])) { $url_info['query'] = substr($url_info['path'], $p + 1); } else { $url_info['query'] = $_SERVER['QUERY_STRING']; } $url_info['query'] = qtranxf_sanitize_url($url_info['query']); // to prevent xss if (strpos($url_info['query'], 'qtranslate-mode=raw') !== false) { $url_info['qtranslate-mode'] = 'raw'; $url_info['doing_front_end'] = true; $q_config['url_info'] = $url_info; $q_config['url_info']['language'] = $q_config['default_language']; $q_config['language'] = $q_config['default_language']; //qtranxf_load_option_qtrans_compatibility(); return; } } } $url_info['original_url'] = $_SERVER['REQUEST_URI']; //is in use in -slug, here is for debugging purpose only //qtranxf_dbg_log('qtranxf_init_language: SERVER: ',$_SERVER); //qtranxf_dbg_log('qtranxf_init_language: REQUEST_TIME_FLOAT: ',$_SERVER['REQUEST_TIME_FLOAT']); $url_info['language'] = qtranxf_detect_language($url_info); //qtranxf_dbg_log('qtranxf_init_language: detected: url_info: ',$url_info); $q_config['language'] = apply_filters('qtranslate_language', $url_info['language'], $url_info); if ($q_config['url_info']['doing_front_end'] && qtranxf_can_redirect()) { $lang = $q_config['language']; $url_orig = $url_info['scheme'] . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $url_lang = qtranxf_convertURL('', $lang); //uses $q_config['url_info'] and caches information, which will be needed later anyway. if (!isset($url_info['doredirect']) && $url_orig != $url_lang) { $url_info['doredirect'] = '$url_orig != $url_lang'; } if (isset($url_info['doredirect'])) { $target = apply_filters('qtranslate_language_detect_redirect', $url_lang, $url_orig, $url_info); if ($target !== false && $target != $url_orig) { //qtranxf_dbg_log('qtranxf_init_language: doredirect to '.$lang.PHP_EOL .'urlorg:'.$url_orig.PHP_EOL .'target:'.$target.PHP_EOL .'url_info: ',$url_info); wp_redirect($target); //header('Location: '.$target); exit; } else { $url_info['doredirect'] .= ' - cancelled, because it goes to the same target.'; } //qtranxf_dbg_log('qtranxf_init_language: doredirect: ',$url_info['doredirect']); } } elseif (isset($url_info['doredirect'])) { $url_info['doredirect'] .= ' - cancelled by can_redirect'; } // fix url to prevent xss - how does this prevents xss? //$q_config['url_info']['url'] = qtranxf_convertURL(add_query_arg('lang',$q_config['default_language'],$q_config['url_info']['url'])); //qtranslate_hooks.php has to go before load_plugin_textdomain() require_once dirname(__FILE__) . '/qtranslate_hooks.php'; //common hooks moved here from qtranslate.php since 3.2.9.2, because they all need language already detected // load plugin translations // since 3.2-b3 moved it here as https://codex.wordpress.org/Function_Reference/load_plugin_textdomain seem to recommend to run load_plugin_textdomain in 'plugins_loaded' action, which is this function respond to $lang_dir = dirname(plugin_basename(__FILE__)) . '/lang'; load_plugin_textdomain('qtranslate', false, $lang_dir); if ($q_config['url_info']['doing_front_end']) { require_once dirname(__FILE__) . "/qtranslate_frontend.php"; } else { require_once dirname(__FILE__) . '/admin/qtx_configuration.php'; // load qTranslate Services if available // disabled since 3.1 //if(file_exists(dirname(__FILE__).'/qtranslate_services.php')) // require_once(dirname(__FILE__).'/qtranslate_services.php'); } qtranxf_load_option_qtrans_compatibility(); //allow other plugins to initialize whatever they need for language do_action('qtranslate_init_language', $url_info); //qtranxf_dbg_log('qtranxf_init_language: done: url_info: ',$url_info); }