diff --git a/admin/js/common.js b/admin/js/common.js index b3745ab8..9cb1186d 100644 --- a/admin/js/common.js +++ b/admin/js/common.js @@ -1,3 +1,20 @@ +/* + Copyright 2014 qTranslate Team (email : qTranslateTeam@gmail.com ) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ /* // debugging tools, do not check in var cc=0; @@ -303,7 +320,8 @@ var qTranslateX=function(pg) setLangCookie(qTranslateConfig.activeLanguage); } - this.getActiveLanguage=function() { return qTranslateConfig.activeLanguage; } + this.getActiveLanguage = function() { return qTranslateConfig.activeLanguage; } + this.getActiveLanguageName = function() { return qTranslateConfig.language_name[qTranslateConfig.activeLanguage]; } var contentHooks={}; var contentHookId = 0; @@ -903,6 +921,26 @@ var qTranslateX=function(pg) */ this.addLanguageSwitchAfterListener=function(func){ qTranslateConfig.onTabSwitchFunctionsLoad.push(func); } + /** + * @since 3.2.9.8.9 + * Designed as interface for other plugin integration. The documentation is available at + * https://qtranslatexteam.wordpress.com/integration/ + * + */ + this.enableLanguageSwitchingButtons=function(on){ + var display = on ? 'block' : 'none'; + for(var lang in qTranslateConfig.tabSwitches){ + var tabSwitches = qTranslateConfig.tabSwitches[lang]; + for(var i=0; i < tabSwitches.length; ++i){ + var tabSwitch = tabSwitches[i]; + var tabSwitchParent = tabSwitches[i].parentElement; + tabSwitchParent.style.display = display; + break; + } + break; + } + } + this.getWrapForm=function(){ var wraps = document.getElementsByClassName('wrap'); for(var i=0; i < wraps.length; ++i){ diff --git a/admin/js/common.min.js b/admin/js/common.min.js index 0af1dd36..e019d52b 100644 --- a/admin/js/common.min.js +++ b/admin/js/common.min.js @@ -1 +1 @@ -function qtranxj_get_cookie(e){for(var a=document.cookie.split(";"),n=0;n||\[:[a-z]{2}\]|\[:\])/gi;return e.xsplit(a)},qtranxj_split=function(e){var a=qtranxj_get_split_blocks(e);return qtranxj_split_blocks(a)},qtranxj_split_blocks=function(e){for(var a=new Object,n=0;n/gi,l=/\[:([a-z]{2})\]/gi,t=!1,n=0;n"!=i&&"[:]"!=i)if(t)a[t]+=i,t=!1;else for(var g in a)a[g]+=i;else t=!1;else t=o[1];else t=o[1]}return a},String.prototype.xsplit=function(e){if(3==="a~b".split(/(~)/).length)return this.split(e);e.global||(e=new RegExp(e.source,"g"+(e.ignoreCase?"i":"")));for(var a,n=0,t=[];null!=(a=e.exec(this));)t.push(this.slice(n,a.index)),a.length>1&&t.push(a[1]),n=e.lastIndex;return n2&&e.name.lastIndexOf("[]")==e.name.length-2&&(e.id+=++n)),a[e.id])return!0;var s=a[e.id]={};s.name=e.name,s.contentField=e,s.lang=qTranslateConfig.activeLanguage;var o=qtranxj_split(e.value);e.value=o[s.lang];var r,l,g=s.name.indexOf("[");if(0>g)r="qtranslate-fields["+s.name+"]";else if(r="qtranslate-fields["+s.name.substring(0,g)+"]",s.name.lastIndexOf("[]")<0)r+=s.name.substring(g);else{var d=s.name.length-2;d>g&&(r+=s.name.substring(g,d)),l="[]"}s.fields={};for(var c in o){var f=o[c],u=r+"["+c+"]";l&&(u+=l);var h=qtranxj_ce("input",{name:u,type:"hidden",className:"hidden",value:f});s.fields[c]=h,e.parentNode.insertBefore(h,e)}return i||(i="["),s.sepfield=qtranxj_ce("input",{name:r+"[qtranslate-separator]",type:"hidden",className:"hidden",value:i}),e.parentNode.insertBefore(s.sepfield,e),s.separator=i,e.className+=" qtranxs-translatable",s},this.addContentHookC=function(e,a){return addContentHook(e,a,"[")},this.addContentHookB=function(e,a){return addContentHook(e,a,"[")},this.addContentHookById=function(e,a,n){return addContentHook(this.ge(e),a,n)},this.addContentHookByIdName=function(e,a){var n;switch(e[0]){case"<":case"[":n=e.substring(0,1),e=e.substring(1)}return this.addContentHookById(e,a,n)},this.addContentHookByIdC=function(e,a){return this.addContentHookById(e,a,"[")},this.addContentHookByIdB=function(e,a){return this.addContentHookById(e,a,"[")},this.removeContentHook=function(e){if(!e)return!1;if(!e.id)return!1;if(!a[e.id])return!1;var n=a[e.id];n.sepfield&&jQuery(n.sepfield).remove();for(var t in n.fields)jQuery(n.fields[t]).remove();return jQuery(e).removeClass("qtranxs-translatable"),delete a[e.id],!0};var t=[];addDisplayHookNode=function(e){if(!e.nodeValue)return 0;var a=qtranxj_get_split_blocks(e.nodeValue);if(!a||!a.length||1==a.length)return 0;var n={};return n.nd=e,n.contents=qtranxj_split_blocks(a),e.nodeValue=n.contents[qTranslateConfig.activeLanguage],t.push(n),1};var i=[];if(addDisplayHookAttr=function(e){if(!e.value)return 0;var a=qtranxj_get_split_blocks(e.value);if(!a||!a.length||1==a.length)return 0;var n={};return n.nd=e,n.contents=qtranxj_split_blocks(a),e.value=n.contents[qTranslateConfig.activeLanguage],i.push(n),1},addDisplayHook=function(e){if(!e||!e.tagName)return 0;switch(e.tagName){case"TEXTAREA":return 0;case"INPUT":switch(e.type){case"submit":if(e.value)return addDisplayHookAttr(e);default:return 0}}var a=0;if(e.childNodes&&e.childNodes.length)for(var n=0;n1){var r=[];if(qTranslateConfig.page_config&&qTranslateConfig.page_config.anchors)for(var l=0;l||\[:[a-z]{2}\]|\[:\])/gi;return e.xsplit(a)},qtranxj_split=function(e){var a=qtranxj_get_split_blocks(e);return qtranxj_split_blocks(a)},qtranxj_split_blocks=function(e){for(var a=new Object,n=0;n/gi,l=/\[:([a-z]{2})\]/gi,t=!1,n=0;n"!=i&&"[:]"!=i)if(t)a[t]+=i,t=!1;else for(var g in a)a[g]+=i;else t=!1;else t=s[1];else t=s[1]}return a},String.prototype.xsplit=function(e){if(3==="a~b".split(/(~)/).length)return this.split(e);e.global||(e=new RegExp(e.source,"g"+(e.ignoreCase?"i":"")));for(var a,n=0,t=[];null!=(a=e.exec(this));)t.push(this.slice(n,a.index)),a.length>1&&t.push(a[1]),n=e.lastIndex;return n2&&e.name.lastIndexOf("[]")==e.name.length-2&&(e.id+=++n)),a[e.id])return!0;var r=a[e.id]={};r.name=e.name,r.contentField=e,r.lang=qTranslateConfig.activeLanguage;var s=qtranxj_split(e.value);e.value=s[r.lang];var o,l,g=r.name.indexOf("[");if(0>g)o="qtranslate-fields["+r.name+"]";else if(o="qtranslate-fields["+r.name.substring(0,g)+"]",r.name.lastIndexOf("[]")<0)o+=r.name.substring(g);else{var c=r.name.length-2;c>g&&(o+=r.name.substring(g,c)),l="[]"}r.fields={};for(var d in s){var f=s[d],u=o+"["+d+"]";l&&(u+=l);var h=qtranxj_ce("input",{name:u,type:"hidden",className:"hidden",value:f});r.fields[d]=h,e.parentNode.insertBefore(h,e)}return i||(i="["),r.sepfield=qtranxj_ce("input",{name:o+"[qtranslate-separator]",type:"hidden",className:"hidden",value:i}),e.parentNode.insertBefore(r.sepfield,e),r.separator=i,e.className+=" qtranxs-translatable",r},this.addContentHookC=function(e,a){return addContentHook(e,a,"[")},this.addContentHookB=function(e,a){return addContentHook(e,a,"[")},this.addContentHookById=function(e,a,n){return addContentHook(this.ge(e),a,n)},this.addContentHookByIdName=function(e,a){var n;switch(e[0]){case"<":case"[":n=e.substring(0,1),e=e.substring(1)}return this.addContentHookById(e,a,n)},this.addContentHookByIdC=function(e,a){return this.addContentHookById(e,a,"[")},this.addContentHookByIdB=function(e,a){return this.addContentHookById(e,a,"[")},this.removeContentHook=function(e){if(!e)return!1;if(!e.id)return!1;if(!a[e.id])return!1;var n=a[e.id];n.sepfield&&jQuery(n.sepfield).remove();for(var t in n.fields)jQuery(n.fields[t]).remove();return jQuery(e).removeClass("qtranxs-translatable"),delete a[e.id],!0};var t=[];addDisplayHookNode=function(e){if(!e.nodeValue)return 0;var a=qtranxj_get_split_blocks(e.nodeValue);if(!a||!a.length||1==a.length)return 0;var n={};return n.nd=e,n.contents=qtranxj_split_blocks(a),e.nodeValue=n.contents[qTranslateConfig.activeLanguage],t.push(n),1};var i=[];if(addDisplayHookAttr=function(e){if(!e.value)return 0;var a=qtranxj_get_split_blocks(e.value);if(!a||!a.length||1==a.length)return 0;var n={};return n.nd=e,n.contents=qtranxj_split_blocks(a),e.value=n.contents[qTranslateConfig.activeLanguage],i.push(n),1},addDisplayHook=function(e){if(!e||!e.tagName)return 0;switch(e.tagName){case"TEXTAREA":return 0;case"INPUT":switch(e.type){case"submit":if(e.value)return addDisplayHookAttr(e);default:return 0}}var a=0;if(e.childNodes&&e.childNodes.length)for(var n=0;n1){var o=[];if(qTranslateConfig.page_config&&qTranslateConfig.page_config.anchors)for(var l=0;l QTX_EDITOR_MODE_LSB, + 'highlight_mode' => QTX_HIGHLIGHT_MODE_LEFT_BORDER, + ); + + $ops['admin']['bool']=array( + 'auto_update_mo' => true,// automatically update .mo files + 'plugin_js_composer_off' => false + ); + + //single line options + $ops['admin']['str']=array( + 'lsb_style' => 'Simple_Buttons.css', + 'lsb_style_wrap_class' => 'qtranxf_default_lsb_style_wrap_class', + 'lsb_style_active_class' => 'qtranxf_default_lsb_style_active_class', + ); + + //multi-line options + $ops['admin']['text']=array( + 'highlight_mode_custom_css' => null, // qtranxf_get_admin_highlight_css + ); + + $ops['admin']['array']=array( + 'custom_fields' => array(), + 'custom_field_classes' => array(), + 'custom_pages' => array(), + 'post_type_excluded' => array(), + ); + + //options processed in a special way +} + +function qtranxf_admin_loadConfig() +{ + global $q_config, $qtranslate_options; + qtranxf_admin_set_default_options($qtranslate_options); + + foreach($qtranslate_options['admin']['int'] as $nm => $def){ + qtranxf_load_option($nm, $def); + } + + foreach($qtranslate_options['admin']['bool'] as $nm => $def){ + qtranxf_load_option_bool($nm,$def); + } + + foreach($qtranslate_options['admin']['str'] as $nm => $def){ + qtranxf_load_option($nm, $def); + } + + foreach($qtranslate_options['admin']['text'] as $nm => $def){ + qtranxf_load_option($nm, $def); + } + + foreach($qtranslate_options['admin']['array'] as $nm => $def){ + qtranxf_load_option_array($nm,$def); + } + + qtranxf_add_admin_filters(); + + do_action('qtranslate_admin_loadConfig'); +} +//add_action('qtranslate_loadConfig','qtranxf_admin_loadConfig'); + +function qtranxf_reset_config() +{ + global $qtranslate_options; + + if(!current_user_can('manage_options')) return; + + $next_thanks = get_option('qtranslate_next_thanks'); + if(!$next_thanks){ + $next_thanks = time() + rand(100,200)*24*60*60; + update_option('qtranslate_next_thanks', $next_thanks); + } + + if( !isset($_POST['qtranslate_reset']) || !isset($_POST['qtranslate_reset2']) ) + return; + // reset all settings + foreach($qtranslate_options['front'] as $ops){ foreach($ops as $nm => $def){ delete_option('qtranslate_'.$nm); } } + foreach($qtranslate_options['admin'] as $ops){ foreach($ops as $nm => $def){ delete_option('qtranslate_'.$nm); } } + foreach($qtranslate_options['default_value'] as $nm => $def){ delete_option('qtranslate_'.$nm); } + foreach($qtranslate_options['languages'] as $nm => $opn){ delete_option($opn); } + + //internal private options not loaded by default + delete_option('qtranslate_admin_notices'); + delete_option('qtranslate_next_thanks'); + delete_option('qtranslate_next_update_mo'); + + // obsolete options + delete_option('qtranslate_widget_css'); + delete_option('qtranslate_version'); + delete_option('qtranslate_disable_header_css'); + + if(isset($_POST['qtranslate_reset3'])) { + delete_option('qtranslate_term_name'); + if(isset($_POST['qtranslate_reset4'])){//not implemented yet + delete_option('qtranslate_version_previous'); + //and delete translations in posts + } + } + remove_filter('locale', 'qtranxf_localeForCurrentLanguage',99); + qtranxf_reloadConfig(); + add_filter('locale', 'qtranxf_localeForCurrentLanguage',99); +} +add_action('qtranslate_saveConfig','qtranxf_reset_config',20); + +function qtranxf_update_option( $nm, $default_value=null ) { + global $q_config; + if( !isset($q_config[$nm]) || $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( $default_value===$q_config[$nm] ){ + delete_option('qtranslate_'.$nm); + return; + } + } + update_option('qtranslate_'.$nm, $q_config[$nm]); +} + +function qtranxf_update_option_bool( $nm, $default_value=null ) { + global $q_config, $qtranslate_options; + if( !isset($q_config[$nm]) ){ + delete_option('qtranslate_'.$nm); + return; + } + if(is_null($default_value)){ + if(isset($qtranslate_options['default_value'][$nm])){ + $default_value = $qtranslate_options['default_value'][$nm]; + }elseif(isset($qtranslate_options['front']['bool'][$nm])){ + $default_value = $qtranslate_options['front']['bool'][$nm]; + } + } + if( !is_null($default_value) && $default_value === $q_config[$nm] ){ + delete_option('qtranslate_'.$nm); + }else{ + update_option('qtranslate_'.$nm, $q_config[$nm]?'1':'0'); + } +} + +// saves entire configuration - it should be in admin only? +function qtranxf_saveConfig() { + global $q_config, $qtranslate_options; + + qtranxf_update_option('default_language'); + qtranxf_update_option('enabled_languages'); + + foreach($qtranslate_options['front']['int'] as $nm => $def){ + qtranxf_update_option($nm,$def); + } + + foreach($qtranslate_options['front']['bool'] as $nm => $def){ + qtranxf_update_option_bool($nm,$def); + } + qtranxf_update_option_bool('qtrans_compatibility'); + qtranxf_update_option_bool('disable_client_cookies'); + + foreach($qtranslate_options['front']['str'] as $nm => $def){ + qtranxf_update_option($nm,$def); + } + + foreach($qtranslate_options['front']['text'] as $nm => $def){ + qtranxf_update_option($nm,$def); + } + + foreach($qtranslate_options['front']['array'] as $nm => $def){ + qtranxf_update_option($nm,$def); + } + qtranxf_update_option('domains'); + + update_option('qtranslate_ignore_file_types', implode(',',$q_config['ignore_file_types'])); + + qtranxf_update_option('flag_location',qtranxf_flag_location_default()); + + //if($q_config['filter_options_mode'] == QTX_FILTER_OPTIONS_LIST) + qtranxf_update_option('filter_options',explode(' ',QTX_FILTER_OPTIONS_DEFAULT)); + + //$qtranslate_options['languages'] are updated in a special way: look for _GET['edit'], $_GET['delete'], $_GET['enable'], $_GET['disable'] + + qtranxf_update_option('term_name');//uniquely special case + + + //save admin options + + foreach($qtranslate_options['admin']['int'] as $nm => $def){ + qtranxf_update_option($nm,$def); + } + + foreach($qtranslate_options['admin']['bool'] as $nm => $def){ + qtranxf_update_option_bool($nm,$def); + } + + foreach($qtranslate_options['admin']['str'] as $nm => $def){ + qtranxf_update_option($nm,$def); + } + + foreach($qtranslate_options['admin']['text'] as $nm => $def){ + qtranxf_update_option($nm,$def); + } + + foreach($qtranslate_options['admin']['array'] as $nm => $def){ + qtranxf_update_option($nm,$def); + } + + do_action('qtranslate_saveConfig'); +} + +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_admin_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_updateSetting($var, $type = QTX_STRING, $def = null) { + global $q_config, $qtranslate_options; + if(!isset($_POST['submit'])) return false; + if(!isset($_POST[$var]) && $type != QTX_BOOLEAN) return false; + + if(is_null($def) && isset($qtranslate_options['default_value'][$var])){ + $def = $qtranslate_options['default_value'][$var]; + } + if(is_string($def) && function_exists($def)){ + $def = call_user_func($def); + } + switch($type) { + case QTX_URL: + case QTX_LANGUAGE: + case QTX_STRING: + $val = sanitize_text_field($_POST[$var]); + if($type == QTX_URL) $val = trailingslashit($val); + else if($type == QTX_LANGUAGE && !qtranxf_isEnabled($val)) return false; + if(isset($q_config[$var])){ + if($q_config[$var] === $val) return false; + }elseif(!is_null($def)){ + if(empty($val) || $def === $val) return false; + } + if(empty($val) && $def) $val = $def; + $q_config[$var] = $val; + qtranxf_update_option($var, $def); + return true; + case QTX_TEXT: + $val = $_POST[$var]; + //standardize multi-line string + $lns = preg_split('/\r?\n\r?/',$val); + foreach($lns as $key => $ln){ + $lns[$key] = sanitize_text_field($ln); + } + $val = implode(PHP_EOL,$lns); + //qtranxf_dbg_log('qtranxf_updateSetting:QTX_TEXT: $_POST[$var]:'.PHP_EOL, $_POST[$var]); + //qtranxf_dbg_log('qtranxf_updateSetting:QTX_TEXT: $val:'.PHP_EOL, $val); + if(isset($q_config[$var])){ + if($q_config[$var] === $val) return false; + }elseif(!is_null($def)){ + if(empty($val) || $def === $val) return false; + } + if(empty($val) && $def) $val = $def; + $q_config[$var] = $val; + 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); + } + if( isset($q_config[$var]) && qtranxf_array_compare($q_config[$var],$val) ) return false; + $q_config[$var] = $val; + qtranxf_update_option($var, $def); + return true; + case QTX_BOOLEAN: + if( isset($_POST[$var]) && $_POST[$var]==1 ) { + if($q_config[$var]) return false; + $q_config[$var] = true; + } else { + if(!$q_config[$var]) return false; + $q_config[$var] = false; + } + qtranxf_update_option_bool($var, $def); + return true; + case QTX_INTEGER: + $val = sanitize_text_field($_POST[$var]); + $val = intval($val); + if($q_config[$var] == $val) return false; + $q_config[$var] = $val; + qtranxf_update_option($var, $def); + return true; + } + return false; +} + +function qtranxf_updateSettingFlagLocation($nm) { + global $q_config; + if(!isset($_POST['submit'])) return false; + if(!isset($_POST[$nm])) return false; + $flag_location=untrailingslashit(sanitize_text_field($_POST[$nm])); + if(empty($flag_location)) $flag_location = qtranxf_flag_location_default(); + $flag_location = trailingslashit($flag_location); + if(!file_exists(trailingslashit(WP_CONTENT_DIR).$flag_location)) + return null; + if($flag_location != $q_config[$nm]){ + $q_config[$nm]=$flag_location; + if($flag_location == qtranxf_flag_location_default()) + delete_option('qtranslate_'.$nm); + else + update_option( 'qtranslate_'.$nm, $flag_location ); + } + return true; +} + +function qtranxf_updateSettingIgnoreFileTypes($nm) { + global $q_config; + if(!isset($_POST['submit'])) return false; + if(!isset($_POST[$nm])) return false; + $posted=preg_split('/[\s,]+/',strtolower(sanitize_text_field($_POST[$nm])),null,PREG_SPLIT_NO_EMPTY); + $val=explode(',',QTX_IGNORE_FILE_TYPES); + if(is_array($posted)){ + foreach($posted as $v){ + if(empty($v)) continue; + if(in_array($v,$val)) continue; + $val[]=$v; + } + } + if( qtranxf_array_compare($q_config[$nm],$val) ) return false; + $q_config[$nm] = $val; + update_option('qtranslate_'.$nm, implode(',',$val)); + return true; +} + +function qtranxf_parse_post_type_excluded() { + global $q_config; + if(!isset($_POST['submit'])) return false; + $post_types = get_post_types(); + if(isset($_POST['post_types'])){ + //qtranxf_dbg_log('qtranxf_conf: $_POST[post_types]: ',$_POST['post_types']); + if(!is_array($_POST['post_types'])) return false; + $post_type_excluded = array(); + foreach ( $post_types as $post_type ) { + if(!qtranxf_post_type_optional($post_type)) continue; + if(isset($_POST['post_types'][$post_type])) continue; + $post_type_excluded[] = $post_type; + } + }else{ + //qtranxf_dbg_log('qtranxf_conf: $_POST[post_types] is not set'); + $post_type_excluded = $post_types; + } + unset($_POST['post_types']); + $_POST['post_type_excluded'] = $post_type_excluded; + //qtranxf_dbg_log('qtranxf_conf: $_POST[post_type_excluded]: ',$_POST['post_type_excluded']); +} + +function qtranxf_updateSettings() +{ + global $qtranslate_options, $q_config; + // update front settings + + qtranxf_updateSetting('default_language', QTX_LANGUAGE); + //enabled_languages are not changed at this place + + qtranxf_updateSettingFlagLocation('flag_location'); + qtranxf_updateSettingIgnoreFileTypes('ignore_file_types'); + + foreach($qtranslate_options['front']['int'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_INTEGER, $def); + } + + foreach($qtranslate_options['front']['bool'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_BOOLEAN, $def); + } + qtranxf_updateSetting('qtrans_compatibility', QTX_BOOLEAN); + + foreach($qtranslate_options['front']['str'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_STRING, $def); + } + + foreach($qtranslate_options['front']['text'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_TEXT, $def); + } + + foreach($qtranslate_options['front']['array'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_ARRAY, $def); + } + qtranxf_updateSetting('filter_options', QTX_ARRAY); + + switch($q_config['url_mode']){ + case QTX_URL_DOMAIN: + case QTX_URL_DOMAINS: $q_config['disable_client_cookies'] = true; break; + case QTX_URL_QUERY: + case QTX_URL_PATH: + default: qtranxf_updateSetting('disable_client_cookies', QTX_BOOLEAN); break; + } + + $domains = isset($q_config['domains']) ? $q_config['domains'] : array(); + foreach($q_config['enabled_languages'] as $lang){ + $id='language_domain_'.$lang; + if(!isset($_POST[$id])) continue; + $domain = preg_replace('#^/*#','',untrailingslashit(trim($_POST[$id]))); + //qtranxf_dbg_echo('qtranxf_conf: domain['.$lang.']: ',$domain); + $domains[$lang] = $domain; + } + if( !empty($domains) && (!isset($q_config['domains']) || !qtranxf_array_compare($q_config['domains'],$domains)) ){ + $q_config['domains'] = $domains; + qtranxf_update_option('domains'); + } + + // update admin settings + + //special cases handling + if($_POST['highlight_mode'] != QTX_HIGHLIGHT_MODE_CUSTOM_CSS){ + $_POST['highlight_mode_custom_css'] = ''; + } + if($_POST['lsb_style'] != $q_config['lsb_style']){ + $_POST['lsb_style_wrap_class'] = ''; + $_POST['lsb_style_active_class'] = ''; + } + + if(!(isset($_POST['plugin_js_composer']) && $_POST['plugin_js_composer']=='1')){ + $_POST['plugin_js_composer_off'] = '1'; + } + + qtranxf_parse_post_type_excluded(); + + foreach($qtranslate_options['admin']['int'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_INTEGER, $def); + } + + foreach($qtranslate_options['admin']['bool'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_BOOLEAN, $def); + } + + foreach($qtranslate_options['admin']['str'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_STRING, $def); + } + + foreach($qtranslate_options['admin']['text'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_TEXT, $def); + } + + foreach($qtranslate_options['admin']['array'] as $nm => $def){ + qtranxf_updateSetting($nm, QTX_ARRAY, $def); + } +} diff --git a/admin/qtx_admin_utils.php b/admin/qtx_admin_utils.php index c38fc7d3..43d6864e 100644 --- a/admin/qtx_admin_utils.php +++ b/admin/qtx_admin_utils.php @@ -1,25 +1,5 @@ _x('Code', 'Language Code', 'qtranslate'), + 'code' => _x('Code', 'Two-letter Language Code meant.', 'qtranslate'), 'flag' => __('Flag', 'qtranslate'), 'name' => __('Name', 'qtranslate'), 'status' => __('Action', 'qtranslate'), @@ -676,6 +665,19 @@ function qtranxf_get_user_admin_color() { return $_wp_admin_css_colors[$user_admin_color]->colors; } +/** + * @since 3.3 + * @return true if post type is listed in option 'Post Types'. + */ +function qtranxf_post_type_optional($post_type) { + switch($post_type){ + case 'revision': + case 'nav_menu_item': + return false; //no option for this type + default: return true; + } +} + add_filter('manage_language_columns', 'qtranxf_language_columns'); add_filter('manage_posts_columns', 'qtranxf_languageColumnHeader'); add_filter('manage_posts_custom_column', 'qtranxf_languageColumn'); diff --git a/admin/qtx_configuration.php b/admin/qtx_configuration.php index a2a549da..9dfc545a 100644 --- a/admin/qtx_configuration.php +++ b/admin/qtx_configuration.php @@ -21,119 +21,11 @@ if ( !defined( 'WP_ADMIN' ) ) exit; require_once(dirname(__FILE__).'/qtx_admin_utils.php'); +require_once(dirname(__FILE__).'/qtx_admin_options.php'); require_once(dirname(__FILE__).'/qtx_languages.php'); require_once(dirname(__FILE__).'/qtx_import_export.php'); require_once(dirname(__FILE__).'/qtx_user_options.php'); -function qtranxf_admin_set_default_options(&$ops) -{ - //options processed in a standardized way - $ops['admin'] = array(); - - $ops['admin']['int']=array( - 'editor_mode' => QTX_EDITOR_MODE_LSB, - 'highlight_mode' => QTX_HIGHLIGHT_MODE_LEFT_BORDER, - ); - - $ops['admin']['bool']=array( - 'auto_update_mo' => true,// automatically update .mo files - ); - - //single line options - $ops['admin']['str']=array( - 'lsb_style' => 'Simple_Buttons.css', - 'lsb_style_wrap_class' => 'qtranxf_default_lsb_style_wrap_class', - 'lsb_style_active_class' => 'qtranxf_default_lsb_style_active_class', - ); - - //multi-line options - $ops['admin']['text']=array( - 'highlight_mode_custom_css' => null, // qtranxf_get_admin_highlight_css - ); - - $ops['admin']['array']=array( - 'custom_fields' => array(), - 'custom_field_classes' => array(), - 'custom_pages' => array(), - ); - - //options processed in a special way -} - -function qtranxf_admin_loadConfig() -{ - global $q_config, $qtranslate_options; - qtranxf_admin_set_default_options($qtranslate_options); - - foreach($qtranslate_options['admin']['int'] as $nm => $def){ - qtranxf_load_option($nm, $def); - } - - foreach($qtranslate_options['admin']['bool'] as $nm => $def){ - qtranxf_load_option_bool($nm,$def); - } - - foreach($qtranslate_options['admin']['str'] as $nm => $def){ - qtranxf_load_option($nm, $def); - } - - foreach($qtranslate_options['admin']['text'] as $nm => $def){ - qtranxf_load_option($nm, $def); - } - - foreach($qtranslate_options['admin']['array'] as $nm => $def){ - qtranxf_load_option_array($nm,$def); - } - - qtranxf_add_admin_filters(); - - do_action('qtranslate_admin_loadConfig'); -} -//add_action('qtranslate_loadConfig','qtranxf_admin_loadConfig'); - -function qtranxf_reset_config() -{ - global $qtranslate_options; - - if(!current_user_can('manage_options')) return; - - $next_thanks = get_option('qtranslate_next_thanks'); - if(!$next_thanks){ - $next_thanks = time() + rand(100,200)*24*60*60; - update_option('qtranslate_next_thanks', $next_thanks); - } - - if( !isset($_POST['qtranslate_reset']) || !isset($_POST['qtranslate_reset2']) ) - return; - // reset all settings - foreach($qtranslate_options['front'] as $ops){ foreach($ops as $nm => $def){ delete_option('qtranslate_'.$nm); } } - foreach($qtranslate_options['admin'] as $ops){ foreach($ops as $nm => $def){ delete_option('qtranslate_'.$nm); } } - foreach($qtranslate_options['default_value'] as $nm => $def){ delete_option('qtranslate_'.$nm); } - foreach($qtranslate_options['languages'] as $nm => $opn){ delete_option($opn); } - - //internal private options not loaded by default - delete_option('qtranslate_admin_notices'); - delete_option('qtranslate_next_thanks'); - delete_option('qtranslate_next_update_mo'); - - // obsolete options - delete_option('qtranslate_widget_css'); - delete_option('qtranslate_version'); - delete_option('qtranslate_disable_header_css'); - - if(isset($_POST['qtranslate_reset3'])) { - delete_option('qtranslate_term_name'); - if(isset($_POST['qtranslate_reset4'])){//not implemented yet - delete_option('qtranslate_version_previous'); - //and delete translations in posts - } - } - remove_filter('locale', 'qtranxf_localeForCurrentLanguage',99); - qtranxf_reloadConfig(); - add_filter('locale', 'qtranxf_localeForCurrentLanguage',99); -} -add_action('qtranslate_saveConfig','qtranxf_reset_config',20); - function qtranxf_collect_translations_deep( $qfields, $sep ) { $content = reset($qfields); //qtranxf_dbg_log('qtranxf_collect_translations_deep: $content: ',$content); @@ -185,52 +77,6 @@ function qtranxf_collect_translations_posted() { } add_action('plugins_loaded', 'qtranxf_collect_translations_posted', 5); -/* -function qtranxf_collect_translations( $request, $sep ) { - $content = reset($request); - //qtranxf_dbg_log('qtranxf_collect_translations: $content: ',$content); - if(is_string($content)) return qtranxf_join_texts($request,$sep); - $result = array(); - foreach($content as $f => $r){ - $texts = array(); - foreach($request as $lang => $vals){ - $texts[$lang] = $vals[$f]; - } - $result[$f] = qtranxf_collect_translations($texts,$sep); // recursive call - } - return $result; -} - -function qtranxf_collect_translations_posted() { - //qtranxf_dbg_log('qtranxf_collect_translations_posted: REQUEST: ',$_REQUEST); - if(!isset($_REQUEST['qtranslate-fields'])) return; - $edit_lang = isset($_COOKIE['qtrans_edit_language']) ? $_COOKIE['qtrans_edit_language'] : qtranxf_getLanguage(); - foreach($_REQUEST['qtranslate-fields'] as $nm => $r){ - if(isset($_REQUEST['qtranslate-fields'][$nm]['sep'])){ - $sep = $_REQUEST['qtranslate-fields'][$nm]['sep']; - unset($_REQUEST['qtranslate-fields'][$nm]['sep']); - }else{ - $sep = '['; - } - $_REQUEST['qtranslate-fields'][$nm][$edit_lang] = $_REQUEST[$nm]; - $_REQUEST[$nm] = qtranxf_collect_translations($_REQUEST['qtranslate-fields'][$nm],$sep); - //qtranxf_dbg_log('qtranxf_collect_translations_posted: REQUEST[qtranslate-fields]['.$nm.']: ',$r); - //qtranxf_dbg_log('qtranxf_collect_translations_posted: collected REQUEST['.$nm.']: ',$_REQUEST[$nm]); - if(isset($_POST[$nm])){ - //qtranxf_dbg_log('qtranxf_collect_translations_posted: POST['.$nm.']: ',$_POST[$nm]); - $_POST[$nm] = $_REQUEST[$nm]; - } - if(isset($_GET[$nm])){ - //qtranxf_dbg_log('qtranxf_collect_translations_posted: GET['.$nm.']: ',$_GET[$nm]); - $_GET[$nm] = $_REQUEST[$nm]; - } - } - unset($_REQUEST['qtranslate-fields']); - unset($_POST['qtranslate-fields']); - unset($_GET['qtranslate-fields']); -} -*/ - function qtranxf_init_admin() { global $q_config; @@ -252,111 +98,6 @@ function qtranxf_init_admin() //add_action('qtranslate_init_begin','qtranxf_init_admin'); add_action('admin_init','qtranxf_init_admin'); -function qtranxf_update_option( $nm, $default_value=null ) { - global $q_config; - if( !isset($q_config[$nm]) || $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( $default_value===$q_config[$nm] ){ - delete_option('qtranslate_'.$nm); - return; - } - } - update_option('qtranslate_'.$nm, $q_config[$nm]); -} - -function qtranxf_update_option_bool( $nm, $default_value=null ) { - global $q_config, $qtranslate_options; - if( !isset($q_config[$nm]) ){ - delete_option('qtranslate_'.$nm); - return; - } - if(is_null($default_value)){ - if(isset($qtranslate_options['default_value'][$nm])){ - $default_value = $qtranslate_options['default_value'][$nm]; - }elseif(isset($qtranslate_options['front']['bool'][$nm])){ - $default_value = $qtranslate_options['front']['bool'][$nm]; - } - } - if( !is_null($default_value) && $default_value === $q_config[$nm] ){ - delete_option('qtranslate_'.$nm); - }else{ - update_option('qtranslate_'.$nm, $q_config[$nm]?'1':'0'); - } -} - -// saves entire configuration - it should be in admin only? -function qtranxf_saveConfig() { - global $q_config, $qtranslate_options; - - qtranxf_update_option('default_language'); - qtranxf_update_option('enabled_languages'); - - foreach($qtranslate_options['front']['int'] as $nm => $def){ - qtranxf_update_option($nm,$def); - } - - foreach($qtranslate_options['front']['bool'] as $nm => $def){ - qtranxf_update_option_bool($nm,$def); - } - qtranxf_update_option_bool('qtrans_compatibility'); - qtranxf_update_option_bool('disable_client_cookies'); - - foreach($qtranslate_options['front']['str'] as $nm => $def){ - qtranxf_update_option($nm,$def); - } - - foreach($qtranslate_options['front']['text'] as $nm => $def){ - qtranxf_update_option($nm,$def); - } - - foreach($qtranslate_options['front']['array'] as $nm => $def){ - qtranxf_update_option($nm,$def); - } - qtranxf_update_option('domains'); - - update_option('qtranslate_ignore_file_types', implode(',',$q_config['ignore_file_types'])); - - qtranxf_update_option('flag_location',qtranxf_flag_location_default()); - - //if($q_config['filter_options_mode'] == QTX_FILTER_OPTIONS_LIST) - qtranxf_update_option('filter_options',explode(' ',QTX_FILTER_OPTIONS_DEFAULT)); - - //$qtranslate_options['languages'] are updated in a special way: look for _GET['edit'], $_GET['delete'], $_GET['enable'], $_GET['disable'] - - qtranxf_update_option('term_name');//uniquely special case - - - //save admin options - - foreach($qtranslate_options['admin']['int'] as $nm => $def){ - qtranxf_update_option($nm,$def); - } - - foreach($qtranslate_options['admin']['bool'] as $nm => $def){ - qtranxf_update_option_bool($nm,$def); - } - - foreach($qtranslate_options['admin']['str'] as $nm => $def){ - qtranxf_update_option($nm,$def); - } - - foreach($qtranslate_options['admin']['text'] as $nm => $def){ - qtranxf_update_option($nm,$def); - } - - foreach($qtranslate_options['admin']['array'] as $nm => $def){ - qtranxf_update_option($nm,$def); - } - - do_action('qtranslate_saveConfig'); -} - function qtranxf_get_custom_admin_js ($pages) { global $pagenow; //qtranxf_dbg_echo('qtranxf_get_custom_admin_js: $pagenow: ',$pagenow); @@ -490,6 +231,17 @@ function qtranxf_load_admin_page_config() { function qtranxf_add_admin_footer_js ( $enqueue_script=false ) { global $q_config; if( $q_config['editor_mode'] == QTX_EDITOR_MODE_RAW) return; + //qtranxf_dbg_log('qtranxf_add_admin_footer_js: pagenow: ',$pagenow); + //qtranxf_dbg_log('qtranxf_add_admin_footer_js: post_type: ',$post_type); + if(isset($q_config['post_type_excluded']) && !empty($q_config['post_type_excluded'])){ + global $pagenow, $post_type; + switch($pagenow){ + case 'post.php': + case 'post-new.php': + if(in_array($post_type,$q_config['post_type_excluded'])) return; + default: break; + } + } $script_file = qtranxf_select_admin_js($enqueue_script); $page_config = qtranxf_load_admin_page_config(); if(!$script_file && empty($page_config)) @@ -512,7 +264,7 @@ function qtranxf_add_admin_footer_js ( $enqueue_script=false ) { } $config=array(); - $keys=array('enabled_languages', 'default_language', 'language', 'url_mode','lsb_style_wrap_class', 'lsb_style_active_class');//,'term_name' + $keys=array('enabled_languages', 'default_language', 'language', 'url_mode', 'language_name', 'lsb_style_wrap_class', 'lsb_style_active_class', 'plugin_js_composer_off');//,'term_name' foreach($keys as $key){ $config[$key]=$q_config[$key]; } @@ -804,213 +556,6 @@ function switch_flag(url) { $ln){ - $lns[$key] = sanitize_text_field($ln); - } - $val = implode(PHP_EOL,$lns); - //qtranxf_dbg_log('qtranxf_updateSetting:QTX_TEXT: $_POST[$var]:'.PHP_EOL, $_POST[$var]); - //qtranxf_dbg_log('qtranxf_updateSetting:QTX_TEXT: $val:'.PHP_EOL, $val); - if(isset($q_config[$var])){ - if($q_config[$var] === $val) return false; - }elseif(!is_null($def)){ - if(empty($val) || $def === $val) return false; - } - if(empty($val) && $def) $val = $def; - $q_config[$var] = $val; - qtranxf_update_option($var, $def); - return true; - case QTX_ARRAY: - $val = sanitize_text_field($_POST[$var]); - $val=preg_split('/[\s,]+/',$val,null,PREG_SPLIT_NO_EMPTY); - if( isset($q_config[$var]) && qtranxf_array_compare($q_config[$var],$val) ) return false; - $q_config[$var] = $val; - qtranxf_update_option($var, $def); - return true; - case QTX_BOOLEAN: - if( isset($_POST[$var]) && $_POST[$var]==1 ) { - if($q_config[$var]) return false; - $q_config[$var] = true; - } else { - if(!$q_config[$var]) return false; - $q_config[$var] = false; - } - qtranxf_update_option_bool($var, $def); - return true; - case QTX_INTEGER: - $val = sanitize_text_field($_POST[$var]); - $val = intval($val); - if($q_config[$var] == $val) return false; - $q_config[$var] = $val; - qtranxf_update_option($var, $def); - return true; - } - return false; -} - -function qtranxf_updateSettingFlagLocation($nm) { - global $q_config; - if(!isset($_POST['submit'])) return false; - if(!isset($_POST[$nm])) return false; - $flag_location=untrailingslashit(sanitize_text_field($_POST[$nm])); - if(empty($flag_location)) $flag_location = qtranxf_flag_location_default(); - $flag_location = trailingslashit($flag_location); - if(!file_exists(trailingslashit(WP_CONTENT_DIR).$flag_location)) - return null; - if($flag_location != $q_config[$nm]){ - $q_config[$nm]=$flag_location; - if($flag_location == qtranxf_flag_location_default()) - delete_option('qtranslate_'.$nm); - else - update_option( 'qtranslate_'.$nm, $flag_location ); - } - return true; -} - -function qtranxf_updateSettingIgnoreFileTypes($nm) { - global $q_config; - if(!isset($_POST['submit'])) return false; - if(!isset($_POST[$nm])) return false; - $posted=preg_split('/[\s,]+/',strtolower(sanitize_text_field($_POST[$nm])),null,PREG_SPLIT_NO_EMPTY); - $val=explode(',',QTX_IGNORE_FILE_TYPES); - if(is_array($posted)){ - foreach($posted as $v){ - if(empty($v)) continue; - if(in_array($v,$val)) continue; - $val[]=$v; - } - } - if( qtranxf_array_compare($q_config[$nm],$val) ) return false; - $q_config[$nm] = $val; - update_option('qtranslate_'.$nm, implode(',',$val)); - return true; -} - -function qtranxf_array_compare($a,$b) { - if( !is_array($a) || !is_array($b) ) return false; - if(count($a)!=count($b)) return false; - //can be optimized - $diff_a=array_diff($a,$b); - $diff_b=array_diff($b,$a); - return empty($diff_a) && empty($diff_b); -} - -function qtranxf_updateSettings() -{ - global $qtranslate_options, $q_config; - // update front settings - - qtranxf_updateSetting('default_language', QTX_LANGUAGE); - //enabled_languages are not changed at this place - - qtranxf_updateSettingFlagLocation('flag_location'); - qtranxf_updateSettingIgnoreFileTypes('ignore_file_types'); - - foreach($qtranslate_options['front']['int'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_INTEGER, $def); - } - - foreach($qtranslate_options['front']['bool'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_BOOLEAN, $def); - } - qtranxf_updateSetting('qtrans_compatibility', QTX_BOOLEAN); - - foreach($qtranslate_options['front']['str'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_STRING, $def); - } - - foreach($qtranslate_options['front']['text'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_TEXT, $def); - } - - foreach($qtranslate_options['front']['array'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_ARRAY, $def); - } - qtranxf_updateSetting('filter_options', QTX_ARRAY); - - switch($q_config['url_mode']){ - case QTX_URL_DOMAIN: - case QTX_URL_DOMAINS: $q_config['disable_client_cookies'] = true; break; - case QTX_URL_QUERY: - case QTX_URL_PATH: - default: qtranxf_updateSetting('disable_client_cookies', QTX_BOOLEAN); break; - } - - $domains = isset($q_config['domains']) ? $q_config['domains'] : array(); - foreach($q_config['enabled_languages'] as $lang){ - $id='language_domain_'.$lang; - if(!isset($_POST[$id])) continue; - $domain = preg_replace('#^/*#','',untrailingslashit(trim($_POST[$id]))); - //qtranxf_dbg_echo('qtranxf_conf: domain['.$lang.']: ',$domain); - $domains[$lang] = $domain; - } - if( !empty($domains) && (!isset($q_config['domains']) || !qtranxf_array_compare($q_config['domains'],$domains)) ){ - $q_config['domains'] = $domains; - qtranxf_update_option('domains'); - } - - // update admin settings - - //special cases handling - if($_POST['highlight_mode'] != QTX_HIGHLIGHT_MODE_CUSTOM_CSS){ - $_POST['highlight_mode_custom_css'] = ''; - } - if($_POST['lsb_style'] != $q_config['lsb_style']){ - $_POST['lsb_style_wrap_class'] = ''; - $_POST['lsb_style_active_class'] = ''; - } - - foreach($qtranslate_options['admin']['int'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_INTEGER, $def); - } - - foreach($qtranslate_options['admin']['bool'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_BOOLEAN, $def); - } - - foreach($qtranslate_options['admin']['str'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_STRING, $def); - } - - foreach($qtranslate_options['admin']['text'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_TEXT, $def); - } - - foreach($qtranslate_options['admin']['array'] as $nm => $def){ - qtranxf_updateSetting($nm, QTX_ARRAY, $def); - } -} - function qtranxf_admin_section_start($section, $nm) { echo '

'.$section.' ( '.__('Show', 'qtranslate').' / '.__('Hide', 'qtranslate').' )

'.PHP_EOL; echo '