From fa87157e52e99cda69578db2584746827dbe6f20 Mon Sep 17 00:00:00 2001
From: John Clause ';// text-align: center;
- printf(__('Are you new to plugin %s?', 'qtranslate'), 'qTranslate‑X');
- echo ' ';
- echo __('Read Startup Guide', 'qtranslate');
- echo ' '.__('I have already done it, dismiss this message.', 'qtranslate');
- echo '
';
- echo '
'.sprintf(__('It might be a good idea to review %smigration instructions%s, if you have not yet done so.', 'qtranslate'),'','').'
'; - $msg=sprintf(__('Activation of plugin %s deactivated plugin %s since they cannot run simultaneously.', 'qtranslate'), $qtxlink, $link).' '; - if($imported){ - $msg.=sprintf(__('The compatible settings from %s have been imported to %s. Further tuning, import, export and reset of options can be done at Settings/Languages configuration page, once %s is running.%sContinue%s', 'qtranslate'), $nm, $qtxnm, $qtxnm, $s, ''); - }else{ - $msg.=sprintf(__('You may import/export compatible settings from %s to %s on Settings/Languages configuration page, once %s is running.%sContinue%s', 'qtranslate'), $nm, $qtxnm, $qtxnm, $s, ''); + + //$cfg_admin = array(); + //$cfg_front = array(); + $cfg_all = array(); + foreach($json_files as $fnm){ + $cfg_json=file_get_contents($fnm); + //$cfg_json=php_strip_whitespace($fnm); + if($cfg_json){ + $cfg=json_decode($cfg_json,true); + if($cfg){ + $cfg_all = array_merge_recursive($cfg_all,$cfg); + //if(isset($cfg['admin-config'])) $cfg_admin = array_merge_recursive($cfg_admin,$cfg['admin-config']); + //if(isset($cfg['front-config'])) $cfg_front = array_merge_recursive($cfg_front,$cfg['front-config']); + }else{ + qtranxf_error_log(sprintf(__('Could not parse %s file "%s" listed in option "%s".', 'qtranslate'), 'JSON', $fnm, __('Configuration Files', 'qtranslate'))); + } + }else{ + qtranxf_error_log(sprintf(__('Could not load file "%s" listed in option "%s".', 'qtranslate'), $fnm, __('Configuration Files', 'qtranslate'))); + } } - //$nonce=wp_create_nonce('deactivate-plugin_'.$plugin); - //$msg=sprintf(__('Plugin %s cannot run concurrently with %s, please %sdeactivate %s%s. You may import compatible settings from %s to %s on Settings/Languages configuration page, once %s is running.','qtranslate'),$qtxlink,$link,'',$nm,'',$nm,$qtxnm,$qtxnm); - //$msg=sprintf(__('Activation of plugin %s deactivated plugin %s since they cannot run simultaneously. You may import compatible settings from %s to %s on Settings/%sLanguages%s configuration page, once %s is running.%sContinue%s','qtranslate'),$qtxlink,$link,$nm,$qtxnm,'','',$qtxnm,'
',''); - wp_die('
'.$msg.'
'); + return $cfg_all; +} + +/** + * @since 3.3.2 + */ +function qtranxf_default_front_config(){ + $json_files = get_option('qtranslate_config_files', array('./qTranslateX.json')); + $cfg = qtranxf_load_config_files($json_files); + $cfg_front = isset($cfg['front-config']) ? $cfg['front-config'] : array(); + return $cfg_front; } function qtranxf_activation_hook() @@ -129,7 +139,13 @@ function qtranxf_activation_hook() if ( is_plugin_active( 'ztranslate/ztranslate.php' ) ) qtranxf_admin_notice_deactivate_plugin('zTranslate','ztranslate/ztranslate.php'); - //deactivate_plugins(plugin_basename(__FILE__)); // Deactivate ourself + //deactivate_plugins(plugin_basename(QTRANSLATE_FILE)); // Deactivate ourself + + if(get_option('qtranslate_front_config')===false){ + //option 'front_config' must exist in order for front-end to function properly + $front_config = qtranxf_default_front_config(); + update_option('qtranslate_front_config', $front_config); + } $next_thanks = get_option('qtranslate_next_thanks'); if($next_thanks !== false && $next_thanks < time()+7*24*60*60){ @@ -157,6 +173,52 @@ function qtranxf_activation_hook() if(file_exists($f)) unlink($f); } +function qtranxf_admin_notice_first_install(){ + $messages = get_option('qtranslate_admin_notices'); + if(isset($messages['initial-install'])) return; + qtranxf_admin_notice_dismiss_script(); + echo '';// text-align: center;
+ printf(__('Are you new to plugin %s?', 'qtranslate'), 'qTranslate‑X');
+ echo '
';
+ echo '
'; + echo __('Read Startup Guide', 'qtranslate'); + echo ' '.__('I have already done it, dismiss this message.', 'qtranslate'); + echo '
'.sprintf(__('It might be a good idea to review %smigration instructions%s, if you have not yet done so.', 'qtranslate'),'','').'
'; + $msg=sprintf(__('Activation of plugin %s deactivated plugin %s since they cannot run simultaneously.', 'qtranslate'), $qtxlink, $link).' '; + if($imported){ + $msg.=sprintf(__('The compatible settings from %s have been imported to %s. Further tuning, import, export and reset of options can be done at Settings/Languages configuration page, once %s is running.%sContinue%s', 'qtranslate'), $nm, $qtxnm, $qtxnm, $s, ''); + }else{ + $msg.=sprintf(__('You may import/export compatible settings from %s to %s on Settings/Languages configuration page, once %s is running.%sContinue%s', 'qtranslate'), $nm, $qtxnm, $qtxnm, $s, ''); + } + //$nonce=wp_create_nonce('deactivate-plugin_'.$plugin); + //$msg=sprintf(__('Plugin %s cannot run concurrently with %s, please %sdeactivate %s%s. You may import compatible settings from %s to %s on Settings/Languages configuration page, once %s is running.','qtranslate'),$qtxlink,$link,'',$nm,'',$nm,$qtxnm,$qtxnm); + //$msg=sprintf(__('Activation of plugin %s deactivated plugin %s since they cannot run simultaneously. You may import compatible settings from %s to %s on Settings/%sLanguages%s configuration page, once %s is running.%sContinue%s','qtranslate'),$qtxlink,$link,$nm,$qtxnm,'','',$qtxnm,'
',''); + wp_die('
'.$msg.'
'); +} + function qtranxf_admin_notices_version() { $ver_cur = qtranxf_version_int(); diff --git a/admin/qtx_admin_options.php b/admin/qtx_admin_options.php index 4606e9b..5ce8f47 100644 --- a/admin/qtx_admin_options.php +++ b/admin/qtx_admin_options.php @@ -1,7 +1,7 @@ './qTranslateX.json', + 'page_configs' => 'qtranxf_default_page_configs', 'custom_fields' => array(), 'custom_field_classes' => array(), 'custom_pages' => array(), @@ -37,6 +39,51 @@ function qtranxf_admin_set_default_options(&$ops) //options processed in a special way } +/** + * Load 'page_configs' from *.json files listed in option 'config_files'. + * @since 3.3.1 + */ +function qtranxf_default_page_configs(){ + global $q_config; + $json_files = $q_config['config_files']; + $cfg = qtranxf_load_config_files($json_files); + if(empty($cfg)) return array(); + if(current_user_can('manage_options')){ + $cfg_front = isset($cfg['front-config']) ? $cfg['front-config'] : array(); + if($q_config['front_config'] !== $cfg_front){ + $q_config['front_config'] = $cfg_front; + qtranxf_update_option('front_config'); + } + } + return $cfg['admin-config']; +} + +/** + * Load enabled languages properties from database + * @since 3.3 + */ +function qtranxf_default_lsb_style_wrap_class() +{ + global $q_config; + switch($q_config['lsb_style']){ + case 'Tabs_in_Block.css': return 'qtranxs-lang-switch-wrap wp-ui-primary'; + default: return 'qtranxs-lang-switch-wrap'; + } +} + +/** + * Load enabled languages properties from database + * @since 3.3 + */ +function qtranxf_default_lsb_style_active_class() +{ + global $q_config; + switch($q_config['lsb_style']){ + case 'Tabs_in_Block.css': return 'wp-ui-highlight'; + default: return 'active'; + } +} + function qtranxf_admin_loadConfig() { global $q_config, $qtranslate_options; @@ -72,13 +119,13 @@ function qtranxf_admin_loadConfig() */ $q_config['admin_sections'] = array(); $admin_sections = &$q_config['admin_sections']; - $admin_sections['general'] = __('General Settings', 'qtranslate'); - $admin_sections['advanced'] = __('Advanced Settings', 'qtranslate'); - $admin_sections['integration'] = __('Custom Integration', 'qtranslate'); - $admin_sections['import'] = __('Import', 'qtranslate').'/'.__('Export', 'qtranslate'); + $admin_sections['general'] = __('General', 'qtranslate');//General Settings + $admin_sections['advanced'] = __('Advanced', 'qtranslate');//Advanced Settings + $admin_sections['integration'] = __('Integration', 'qtranslate');//Custom Integration do_action('qtranslate_admin_loadConfig'); + $admin_sections['import'] = __('Import', 'qtranslate').'/'.__('Export', 'qtranslate'); $admin_sections['languages'] = __('Languages', 'qtranslate');//always last section qtranxf_add_admin_filters(); @@ -129,13 +176,17 @@ function qtranxf_reset_config() function qtranxf_update_option( $nm, $default_value=null ) { global $q_config; - if( !isset($q_config[$nm]) || $q_config[$nm] === '' ){ + if( !isset($q_config[$nm]) || ( !is_integer($q_config[$nm]) && empty($q_config[$nm]) ) ){ delete_option('qtranslate_'.$nm); return; } if(!is_null($default_value)){ - if(is_string($default_value) && function_exists($default_value)){ - $default_value = call_user_func($default_value); + if(is_string($default_value)){ + if(function_exists($default_value)){ + $default_value = call_user_func($default_value); + }elseif(is_array($q_config[$nm])){ + $default_value = preg_split('/[\s,]+/',$default_value,null,PREG_SPLIT_NO_EMPTY); + } } if( $default_value===$q_config[$nm] ){ delete_option('qtranslate_'.$nm); @@ -165,7 +216,9 @@ function qtranxf_update_option_bool( $nm, $default_value=null ) { } } -// saves entire configuration - it should be in admin only? +/** + * saves entire configuration + */ function qtranxf_saveConfig() { global $q_config, $qtranslate_options; @@ -299,11 +352,17 @@ function qtranxf_updateSetting($var, $type = QTX_STRING, $def = null) { qtranxf_update_option($var, $def); return true; case QTX_ARRAY: - if(is_array($_POST[$var])){ - $val = $_POST[$var]; - }else{ - $val = sanitize_text_field($_POST[$var]); - $val=preg_split('/[\s,]+/',$val,null,PREG_SPLIT_NO_EMPTY); + $val = $_POST[$var]; + if(!is_array($_POST[$var])){ + $val = sanitize_text_field($val); + $val = preg_split('/[\s,]+/',$val,null,PREG_SPLIT_NO_EMPTY); + } + if(empty($val) && !is_null($def)){ + if(is_string($def)){ + $val = preg_split('/[\s,]+/',$def,null,PREG_SPLIT_NO_EMPTY); + }else if(is_array($def)){ + $val = $def; + } } if( isset($q_config[$var]) && qtranxf_array_compare($q_config[$var],$val) ) return false; $q_config[$var] = $val; @@ -393,6 +452,7 @@ function qtranxf_parse_post_type_excluded() { function qtranxf_updateSettings() { global $qtranslate_options, $q_config; + $errors = array(); // update front settings qtranxf_updateSetting('default_language', QTX_LANGUAGE); @@ -447,6 +507,20 @@ function qtranxf_updateSettings() // update admin settings //special cases handling + + if(isset($_POST['json_page_configs'])){ + $cfg_json = sanitize_text_field(stripslashes($_POST['json_page_configs'])); + if(empty($cfg_json)){ + $_POST['page_configs'] = array(); + }else{ + $cfg = json_decode($cfg_json,true); + if($cfg){ + $_POST['page_configs'] = $cfg; + }else{ + $errors[] = sprintf(__('Cannot parse JSON code in the field "%s".', 'qtranslate'), __('Page Configurations', 'qtranslate')); + } + } + } if($_POST['highlight_mode'] != QTX_HIGHLIGHT_MODE_CUSTOM_CSS){ $_POST['highlight_mode_custom_css'] = ''; } @@ -480,4 +554,6 @@ function qtranxf_updateSettings() foreach($qtranslate_options['admin']['array'] as $nm => $def){ qtranxf_updateSetting($nm, QTX_ARRAY, $def); } + + return $errors; } diff --git a/admin/qtx_admin_utils.php b/admin/qtx_admin_utils.php index cfaeb2d..25444db 100644 --- a/admin/qtx_admin_utils.php +++ b/admin/qtx_admin_utils.php @@ -1,4 +1,66 @@ $js){ + if(isset($js['javascript']) && !empty($js['javascript'])){ + echo $js['javascript']; + }else if(isset($js['src'])){ + if($enqueue_script){ + $handle = isset($js['handle']) ? $js['handle'] : (is_string($k) ? $k : 'qtranslate-admin-js-'.(++$cnt) ); + $ver = isset($js['ver']) ? $js['ver'] : QTX_VERSION; + $src = $js['src']; + if(file_exists(WP_CONTENT_DIR.'/plugins/'.$src)){ + $url = plugins_url($src); + }else{ + $url = content_url($src); + } + wp_register_script( $handle, $url, $deps, $ver, true); + wp_enqueue_script( $handle ); + $deps[] = $handle; + }else{ + $fp = WP_CONTENT_DIR. DIRECTORY_SEPARATOR .$js['src']; + if(!file_exists($fp)) $fp = WP_CONTENT_DIR.'/plugins/'.$js['src']; + if(!file_exists($fp)) $fp = $js['src']; + if(!file_exists($fp)){ + qtranxf_error_log('Could not read file '.$js['src']); + continue; + } + readfile($fp); + } + } + } +} function qtranxf_detect_admin_language($url_info) { global $q_config; @@ -45,10 +107,18 @@ function qtranxf_detect_admin_language($url_info) { function qtranxf_array_compare($a,$b) { if( !is_array($a) || !is_array($b) ) return false; if(count($a)!=count($b)) return false; + foreach($a as $k => $v){ + if(is_array($v)) return qtranxf_array_compare($v,$b[$k]); + if($b[$k] !== $v) return false; + } + return true; + //$sa = serialize($a); + //$sb = serialize($b); + //return $sa === $sb; //can be optimized - $diff_a=array_diff($a,$b); - $diff_b=array_diff($b,$a); - return empty($diff_a) && empty($diff_b); + //$diff_a=array_diff($a,$b); + //$diff_b=array_diff($b,$a); + //return empty($diff_a) && empty($diff_b); } function qtranxf_join_texts($texts,$sep) { @@ -714,6 +784,29 @@ function qtranxf_get_user_admin_color() { return $_wp_admin_css_colors[$user_admin_color]->colors; } + +function qtranxf_meta_box_LSB() +{ + global $q_config; + $flag_location=qtranxf_flag_location(); + $lsb = ' '; + echo $lsb; +} + +function qtranxf_add_meta_box_LSB() +{ + global $post_type; + if(empty($post_type)) return; + //qtranxf_dbg_log('qtranxf_add_meta_box_LSB'); + //add_meta_box( 'qtranxs-lsb', 'LSB', 'qtranxf_meta_box_LSB', $post_type, 'normal', 'high'); + add_meta_box( 'qtranxs-meta-box-lsb', 'LSB', 'qtranxf_meta_box_LSB', null, 'normal', 'low'); +} +add_action( 'add_meta_boxes', 'qtranxf_add_meta_box_LSB' ); + /** * @since 3.3 * @return true if post type is listed in option 'Post Types'. diff --git a/admin/qtx_configuration.php b/admin/qtx_configuration.php index 865b4c7..8f1e93d 100644 --- a/admin/qtx_configuration.php +++ b/admin/qtx_configuration.php @@ -1,34 +1,18 @@ - $query){ - //qtranxf_dbg_log('qtranxf_load_admin_page_config: $page='.$page.'; query=',$query); - if( preg_match('!'.$page.'!',$pagenow) !== 1 ) continue; - //qtranxf_dbg_log('qtranxf_load_admin_page_config: preg_match($page,$pagenow) ok. $_SERVER[QUERY_STRING]=',$_SERVER['QUERY_STRING']); - if( !empty($query) && (isset($_SERVER['QUERY_STRING']) && preg_match('!'.$query.'!',$_SERVER['QUERY_STRING']) !== 1 ) ) continue; - //qtranxf_dbg_log('qtranxf_load_admin_page_config: preg_match($query,$_SERVER[QUERY_STRING] ok'); - - if( isset($pgcfg['anchors']) && !empty($pgcfg['anchors']) ){ - if( !isset($page_config['anchors']) ) $page_config['anchors'] = $pgcfg['anchors']; - else $page_config['anchors'] = array_merge($page_config['anchors'],$pgcfg['anchors']); + $d = isset($pgcfg['preg_delimiter']) ? $pgcfg['preg_delimiter'] : '!'; + if(isset($pgcfg['pages'])){//test $pagenow and $_SERVER['QUERY_STRING'] + $matched = false; + foreach($pgcfg['pages'] as $page => $query){ + if( preg_match($d.$page.$d,$pagenow) !== 1 ) continue; + //qtranxf_dbg_log('qtranxf_load_admin_page_config: preg_match('.$d.$query.$d.', '.$page_query.')'); + if( !empty($query) && preg_match($d.$query.$d,$page_query) !== 1 ) continue; + $matched = true; + break; } + if(!$matched) continue; + } - if( isset($pgcfg['forms']) && !empty($pgcfg['forms']) ){ - if( !isset($page_config['forms']) ) $page_config['forms'] = $pgcfg['forms']; - else $page_config['forms'] = array_merge($page_config['forms'],$pgcfg['forms']); - } + if(isset($pgcfg['post_type'])){//test post_type + if(!$post_type) continue; + if( preg_match($d.$pgcfg['post_type'].$d,$post_type) !== 1 ) continue; + } + + //if(isset($pgcfg['pages'])){// not really needed, stored for information purpose only + // if( !isset($page_config['pages']) ) $page_config['pages'] = $pgcfg['pages']; + // else $page_config['pages'] = array_merge($page_config['pages'],$pgcfg['pages']); + //} - if( isset($pgcfg['js-conf']) && !empty($pgcfg['js-conf']) ){ - if( !isset($page_config['js-conf']) ) $page_config['js-conf'] = $pgcfg['js-conf']; - else $page_config['js-conf'] = array_merge($page_config['js-conf'],$pgcfg['js-conf']); + if( isset($pgcfg['anchors']) && !empty($pgcfg['anchors']) ){ + if( !isset($page_config['anchors']) ) $page_config['anchors'] = array(); + //Anchor elements are defined by id only. + //Merge unique id values only: + foreach($pgcfg['anchors'] as $anchor){ + $id = isset($anchor['id']) ? $anchor['id'] : $anchor; + if(!is_string($id)) continue; + if(isset($anchors[$id])) continue; + if(!is_array($anchor)){ + $anchor = array(); + $anchor['id'] = $id; + $anchor['where'] = 'before'; + } + $anchors[$id] = true;// temporary flag + $page_config['anchors'][] = $anchor; } + } - if( isset($pgcfg['js-exec']) && !empty($pgcfg['js-exec']) ){ - if( !isset($page_config['js-exec']) ) $page_config['js-exec'] = $pgcfg['js-exec']; - else $page_config['js-exec'] = array_merge($page_config['js-exec'],$pgcfg['js-exec']); + if( isset($pgcfg['forms']) && !empty($pgcfg['forms']) ){ + if( !isset($page_config['forms']) ){ + $page_config['forms'] = $pgcfg['forms']; + }else{ + //$page_config['forms'] = array_merge($page_config['forms'],$pgcfg['forms']); + foreach($pgcfg['forms'] as $pgcfg_form){ + if(!isset($pgcfg_form['fields'])) continue; + $key = null; + if(isset($pgcfg_form['form'])){ + $form = $pgcfg_form['form']; + foreach($page_config['forms'] as $k => $f){ + if(!isset($f['form'])) continue; + if($f['form'] !== $form) continue; + $key = $k; + break; + } + }else{ + foreach($page_config['forms'] as $k => &$f){ + if(isset($f['form'])) continue; + $key = $k; + break; + } + } + if(is_null($key)){ + $page_config['forms'][] = $pgcfg_form; + }else{ + if(!isset($page_config['forms'][$key]['fields'])) $page_config['forms'][$key]['fields'] = $pgcfg_form['fields']; + else $page_config['forms'][$key]['fields'] = array_merge($page_config['forms'][$key]['fields'],$pgcfg_form['fields']); + } + } } + } + + if( isset($pgcfg['js-conf']) && !empty($pgcfg['js-conf']) ){ + if( !isset($page_config['js-conf']) ) $page_config['js-conf'] = $pgcfg['js-conf']; + else $page_config['js-conf'] = array_merge($page_config['js-conf'],$pgcfg['js-conf']); + } + + if( isset($pgcfg['js-exec']) && !empty($pgcfg['js-exec']) ){ + if( !isset($page_config['js-exec']) ) $page_config['js-exec'] = $pgcfg['js-exec']; + else $page_config['js-exec'] = array_merge($page_config['js-exec'],$pgcfg['js-exec']); + } + } + + $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'); - break;//each $pgcfg should not have more than one configuration for the same page + 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_qtranslate_basename(); + foreach($page_config['js'] as $k => $js){ + if(!isset($js['src'])) continue; + $src = $js['src']; + if( $src[0] != '.' || $src[1] != '/') continue; + $page_config['js'][$k]['src'] = $bnm.substr($src,1); + } + + /** + * Last chance to customize the whole $page_config. + */ + $page_config = apply_filters('qtranslate_admin_request_config',$page_config); + //qtranxf_dbg_log('qtranxf_load_admin_page_config: $pagenow='.$pagenow.'; $page_query='.$page_query.'; $post_type='.$post_type.'; $page_config: ',$page_config); return $page_config; } @@ -273,26 +359,39 @@ function qtranxf_add_admin_footer_js ( $enqueue_script=false ) { default: break; } } - $script_file = qtranxf_select_admin_js($enqueue_script); + + //$script_file = null; + //if(defined('page_configs33')){ + // $script_file = qtranxf_select_admin_js($enqueue_script); + //} + $page_config = qtranxf_load_admin_page_config(); - if(!$script_file && empty($page_config)) - return; + //qtranxf_dbg_log('qtranxf_add_admin_footer_js: $page_config: ',$page_config); + //if(!$script_file && empty($page_config)) return; + if(empty($page_config)) return; wp_dequeue_script('autosave'); wp_deregister_script( 'autosave' );//autosave script saves the active language only and messes it up later in a hard way - if( $enqueue_script ){ +/* // replaced with function qtranxf_loadfiles_js since 3.3.2 + if( defined('page_configs33') && $enqueue_script ){ //wp_register_script( 'qtranslate-admin-utils', plugins_url( 'js/utils.min.js', __FILE__ ), array(), QTX_VERSION, true ); //wp_enqueue_script( 'qtranslate-admin-utils' ); $deps = array(); if($script_file) $deps[] = 'qtranslate-admin-edit'; if(isset($page_config['js-conf'])){ $cnt=0; - foreach($page_config['js-conf'] as $js){ + foreach($page_config['js-conf'] as $k => $js){ if(!isset($js['src'])) continue; - $handle = isset($js['handle']) ? $js['handle'] : 'qtranslate-admin-js-conf-'.(++$cnt); + $handle = isset($js['handle']) ? $js['handle'] : (is_string($k) ? $k : 'qtranslate-admin-js-conf-'.(++$cnt) ); $ver = isset($js['ver']) ? $js['ver'] : QTX_VERSION; - wp_register_script( $handle, plugins_url($js['src']), $deps, $ver, true); + $src = $js['src']; + if(file_exists(WP_CONTENT_DIR.'/plugins/'.$src)){ + $url = plugins_url($src); + }else{ + $url = content_url($src); + } + wp_register_script( $handle, $url, $deps, $ver, true); $deps[] = $handle; wp_enqueue_script( $handle ); } @@ -302,16 +401,23 @@ function qtranxf_add_admin_footer_js ( $enqueue_script=false ) { if(isset($page_config['js-exec'])){ $deps[] = 'qtranslate-admin-common'; $cnt=0; - foreach($page_config['js-exec'] as $js){ + foreach($page_config['js-exec'] as $k => $js){ if(!isset($js['src'])) continue; - $handle = isset($js['handle']) ? $js['handle'] : 'qtranslate-admin-js-exec-'.(++$cnt); + $handle = isset($js['handle']) ? $js['handle'] : (is_string($k) ? $k : 'qtranslate-admin-js-exec-'.(++$cnt) ); $ver = isset($js['ver']) ? $js['ver'] : QTX_VERSION; - wp_register_script( $handle, plugins_url($js['src']), $deps, $ver, true); + $src = $js['src']; + if(file_exists(WP_CONTENT_DIR.'/plugins/'.$src)){ + $url = plugins_url($src); + }else{ + $url = content_url($src); + } + wp_register_script( $handle, $url, $deps, $ver, true); $deps[] = $handle; wp_enqueue_script( $handle ); } } } +*/ $config=array(); // since 3.2.9.9.0 'enabled_languages' is replaced with 'language_config' structure @@ -340,34 +446,26 @@ function qtranxf_add_admin_footer_js ( $enqueue_script=false ) { $config['language_config'][$lang]['name'] = $q_config['language_name'][$lang]; $config['language_config'][$lang]['locale'] = $q_config['locale'][$lang]; } - if(!empty($page_config)) $config['page_config'] = $page_config; + if(!empty($page_config)){ + $config['page_config'] = $page_config; + //no need for javascript: + unset($config['page_config']['js']); + //unset($config['page_config']['js-conf']); + //unset($config['page_config']['js-exec']); + } $config['LSB'] = $q_config['editor_mode'] == QTX_EDITOR_MODE_LSB; + /** + * Last chance to customize Java script variable qTranslateConfig. + */ $config = apply_filters('qtranslate_admin_page_config', $config); ?>