/** * @since 3.2.8 */ function qtranxf_complete_url_info_path(&$urlinfo) { if (isset($urlinfo['path-base'])) { if (empty($urlinfo['path-base'])) { $urlinfo['wp-path'] = $urlinfo['path']; } elseif (!empty($urlinfo['path']) && qtranxf_startsWith($urlinfo['path'], $urlinfo['path-base'])) { //qtranxf_dbg_log('qtranxf_complete_url_info_path: urlinfo: ',$urlinfo); if (isset($urlinfo['path'][$urlinfo['path-base-length']])) { if ($urlinfo['path'][$urlinfo['path-base-length']] == '/') { $urlinfo['wp-path'] = substr($urlinfo['path'], $urlinfo['path-base-length']); } } else { $urlinfo['wp-path'] = ''; } } } //$urlinfo['wp-path'] is not set, means url does not belong to this WP installation }
function qtranxf_get_admin_page_config_post_type($post_type) { global $q_config, $pagenow; static $page_config; //cache if (!is_null($page_config)) { //qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: cached: '.$pagenow.'; post_type: ', $post_type); return $page_config; } if ($q_config['editor_mode'] == QTX_EDITOR_MODE_RAW) { //qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: QTX_EDITOR_MODE_RAW: '.$pagenow.'; post_type: ', $post_type); $page_config = array(); return $page_config; } if (!empty($q_config['post_type_excluded'])) { switch ($pagenow) { case 'post.php': case 'post-new.php': if (in_array($post_type, $q_config['post_type_excluded'])) { //qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: post_type_excluded: pagenow: '.$pagenow.'; post_type: ', $post_type); $page_config = array(); return $page_config; } default: break; } } //qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: pagenow: '.$pagenow.'; post_type: ', $post_type); $page_configs = qtranxf_get_admin_page_config(); //$page_configs = apply_filters('i18n_admin_config_post_type', $page_configs, $post_type); //qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: $page_configs: ', $page_configs); $page_config = isset($page_configs['']) ? $page_configs[''] : array(); if ($post_type) { foreach ($page_configs as $k => $cfg) { if (empty($k)) { continue; } if (isset($cfg['post_type'])) { $cfg_post_type = $cfg['post_type']; unset($cfg['post_type']); } else { $cfg_post_type = $k; } $matched = qtranxf_match_post_type($cfg_post_type, $post_type); //qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: $cfg: ', $cfg); //qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: $matched: ', $matched); if ($matched === false) { continue; } if (is_null($matched)) { $page_config = array(); break; } $page_config = qtranxf_merge_config($page_config, $cfg); } } //qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: $page_config: ', $page_config); unset($page_config['filters']); if (!empty($page_config)) { //clean up empty items if (!empty($page_config['forms'])) { foreach ($page_config['forms'] as $form_id => &$frm) { if (!isset($frm['fields'])) { continue; } foreach ($frm['fields'] as $k => $f) { if (isset($f['encode']) && $f['encode'] == 'none') { //unset($page_config['forms'][$form_id]['fields'][$k]); unset($frm['fields'][$k]); } if ($post_type && !empty($f['post-type-excluded']) && preg_match('/' . $f['post-type-excluded'] . '/', $post_type)) { unset($frm['fields'][$k]); } } foreach ($frm as $k => $token) { if (empty($token)) { unset($frm[$k]); } } if (empty($frm)) { unset($page_config['forms'][$form_id]); } } } foreach ($page_config as $k => $cfg) { if (empty($cfg)) { unset($page_config[$k]); } } } if (!empty($page_config)) { $page_config['js'] = array(); if (isset($page_config['js-conf'])) { foreach ($page_config['js-conf'] as $k => $js) { if (!isset($js['handle'])) { $js['handle'] = $k; } $page_config['js'][] = $js; } unset($page_config['js-conf']); } $page_config['js'][] = array('handle' => 'qtranslate-admin-common', 'src' => './admin/js/common.min.js'); if (isset($page_config['js-exec'])) { foreach ($page_config['js-exec'] as $k => $js) { if (!isset($js['handle'])) { $js['handle'] = $k; } $page_config['js'][] = $js; } unset($page_config['js-exec']); } //make src to be relative to WP_CONTENT_DIR //$bnm = 'plugins/'.qtranxf_plugin_dirname(); $bnm = qtranxf_plugin_dirname_from_wp_content(); $content_dir = trailingslashit(WP_CONTENT_DIR); foreach ($page_config['js'] as $k => $js) { if (!isset($js['src'])) { continue; } $src = $js['src']; if ($src[0] == '.' && ($src[1] == '/' || $src[1] == DIRECTORY_SEPARATOR)) { $page_config['js'][$k]['src'] = $bnm . substr($src, 1); } else { if (file_exists($content_dir . $src)) { continue; } //from WP_CONTENT_DIR as expected $fp = dirname($bnm) . '/' . $src; //from 'plugins' folder if (file_exists($content_dir . $fp)) { $page_config['js'][$k]['src'] = $fp; continue; } $fp = $bnm . '/' . $src; //from this plugin folder if (file_exists($content_dir . $fp)) { $page_config['js'][$k]['src'] = $fp; continue; } if (file_exists($src)) { //absolute path was given if (qtranxf_startsWith($src, $content_dir)) { $fp = substr($src, strlen($content_dir)); $page_config['js'][$k]['src'] = $fp; continue; } } unset($page_config['js'][$k]); qtranxf_error_log(sprintf(__('Could not find script file "%s" for handle "%s".', 'qtranslate'), $src, $js['handle'])); } } } /* * Customize the $page_config for this admin request. * @param (array) $page_config 'admin_config', filtered for the current page. * @param (string) $pagenow value of WordPress global variable $pagenow. * @param (string) $url_query query part of URL without '?', sanitized version of $_SERVER['QUERY_STRING']. * @param (string) $post_type type of post serving on the current page, or null if not applicable. */ //$page_config = apply_filters('i18n_admin_page_config', $page_config, $pagenow, $url_query, $post_type); //qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: $pagenow='.$pagenow.'; $url_query='.$q_config['url_info']['query'].'; $post_type='.$post_type.'; $page_config: ',qtranxf_json_encode($page_config)); qtranxf_write_config_log($page_config, '', $pagenow, '', $post_type); return $page_config; }