From fa87157e52e99cda69578db2584746827dbe6f20 Mon Sep 17 00:00:00 2001 From: John Clause Date: Sat, 16 May 2015 11:18:27 -0600 Subject: [PATCH] Integration framework with JSON-encoded files, beta --- admin/js/common.js | 505 ++++++++++++----- admin/js/common.min.js | 2 +- admin/js/edit-custom-page.js | 21 - admin/js/edit-custom-page.min.js | 1 - admin/js/edit-nav-menus.js | 16 +- admin/js/edit-nav-menus.min.js | 2 +- admin/js/edit-options-general.js | 14 +- admin/js/edit-options-general.min.js | 2 +- admin/js/edit-post.js | 14 +- admin/js/edit-post.min.js | 2 +- admin/js/edit-tag-exec.js | 19 + admin/js/edit-tag-exec.min.js | 1 + admin/js/edit-tag.js | 6 +- admin/js/edit-tag.min.js | 2 +- admin/js/edit-tags-exec.js | 34 ++ admin/js/edit-tags-exec.min.js | 1 + admin/js/edit-tags.js | 6 +- admin/js/edit-tags.min.js | 2 +- admin/js/nav-menus-exec.js | 57 ++ admin/js/nav-menus-exec.min.js | 1 + admin/js/post-exec.js | 102 ++++ admin/js/post-exec.min.js | 1 + admin/js/widgets-exec.js | 27 + admin/js/widgets-exec.min.js | 1 + admin/qtx_activation_hook.php | 182 +++++-- admin/qtx_admin_options.php | 106 +++- admin/qtx_admin_utils.php | 99 +++- admin/qtx_configuration.php | 781 +++++++++++++++------------ admin/qtx_import_export.php | 71 +-- admin/qtx_languages.php | 15 +- admin/qtx_update_gettext_db.php | 1 + admin/qtx_user_options.php | 6 +- dev/qtx-tests.php | 28 +- lang/qtranslate-ar.mo | Bin 14893 -> 14879 bytes lang/qtranslate-ar.po | 6 +- lang/qtranslate-az_AZ.mo | Bin 12407 -> 12330 bytes lang/qtranslate-az_AZ.po | 6 +- lang/qtranslate-bg_BG.mo | Bin 25928 -> 25831 bytes lang/qtranslate-bg_BG.po | 6 +- lang/qtranslate-cs_CZ.mo | Bin 21010 -> 20928 bytes lang/qtranslate-cs_CZ.po | 6 +- lang/qtranslate-da_DK.mo | Bin 19326 -> 19253 bytes lang/qtranslate-da_DK.po | 6 +- lang/qtranslate-de_DE.mo | Bin 59581 -> 59562 bytes lang/qtranslate-de_DE.po | 6 +- lang/qtranslate-el_GR.mo | Bin 11593 -> 11429 bytes lang/qtranslate-el_GR.po | 6 +- lang/qtranslate-eo.mo | Bin 926 -> 945 bytes lang/qtranslate-eo.po | 6 +- lang/qtranslate-es_CA.mo | Bin 20081 -> 19997 bytes lang/qtranslate-es_CA.po | 6 +- lang/qtranslate-es_ES.mo | Bin 20278 -> 20193 bytes lang/qtranslate-es_ES.po | 6 +- lang/qtranslate-fr_FR.mo | Bin 56814 -> 56047 bytes lang/qtranslate-fr_FR.po | 6 +- lang/qtranslate-hr_HR.mo | Bin 2719 -> 2707 bytes lang/qtranslate-hr_HR.po | 6 +- lang/qtranslate-hu_HU.mo | Bin 53854 -> 53129 bytes lang/qtranslate-hu_HU.po | 6 +- lang/qtranslate-id_ID.mo | Bin 19555 -> 19412 bytes lang/qtranslate-id_ID.po | 6 +- lang/qtranslate-it_IT.mo | Bin 23255 -> 23115 bytes lang/qtranslate-it_IT.po | 6 +- lang/qtranslate-ja.mo | Bin 21891 -> 21788 bytes lang/qtranslate-ja.po | 6 +- lang/qtranslate-mk_MK.mo | Bin 24549 -> 24435 bytes lang/qtranslate-mk_MK.po | 6 +- lang/qtranslate-ms_MY.mo | Bin 20548 -> 20452 bytes lang/qtranslate-ms_MY.po | 6 +- lang/qtranslate-nl_NL.mo | Bin 59006 -> 58981 bytes lang/qtranslate-nl_NL.po | 6 +- lang/qtranslate-pl_PL.mo | Bin 20173 -> 20081 bytes lang/qtranslate-pl_PL.po | 6 +- lang/qtranslate-pt_BR.mo | Bin 7270 -> 7182 bytes lang/qtranslate-pt_BR.po | 6 +- lang/qtranslate-pt_PT.mo | Bin 59982 -> 59957 bytes lang/qtranslate-pt_PT.po | 6 +- lang/qtranslate-ro_RO.mo | Bin 20104 -> 20020 bytes lang/qtranslate-ro_RO.po | 6 +- lang/qtranslate-ru_RU.mo | Bin 36060 -> 35942 bytes lang/qtranslate-ru_RU.po | 6 +- lang/qtranslate-sr_RS.mo | Bin 18594 -> 18507 bytes lang/qtranslate-sr_RS.po | 6 +- lang/qtranslate-sv_SE.mo | Bin 8628 -> 8634 bytes lang/qtranslate-sv_SE.po | 6 +- lang/qtranslate-tr_TR.mo | Bin 12062 -> 11973 bytes lang/qtranslate-tr_TR.po | 6 +- lang/qtranslate-zh_CN.mo | Bin 18395 -> 18316 bytes lang/qtranslate-zh_CN.po | 6 +- lang/qtranslate.pot | 661 ++++++++++++----------- qTranslateX.json | 144 +++-- qtranslate.php | 22 +- qtranslate_compatibility.php | 2 + qtranslate_core.php | 72 +-- qtranslate_frontend.php | 102 ++-- qtranslate_hooks.php | 39 +- qtranslate_options.php | 31 +- qtranslate_services.php | 117 ++-- qtranslate_utils.php | 23 +- qtranslate_widget.php | 39 +- readme.txt | 8 + 101 files changed, 2187 insertions(+), 1369 deletions(-) delete mode 100644 admin/js/edit-custom-page.js delete mode 100644 admin/js/edit-custom-page.min.js create mode 100644 admin/js/edit-tag-exec.js create mode 100644 admin/js/edit-tag-exec.min.js create mode 100644 admin/js/edit-tags-exec.js create mode 100644 admin/js/edit-tags-exec.min.js create mode 100644 admin/js/nav-menus-exec.js create mode 100644 admin/js/nav-menus-exec.min.js create mode 100644 admin/js/post-exec.js create mode 100644 admin/js/post-exec.min.js create mode 100644 admin/js/widgets-exec.js create mode 100644 admin/js/widgets-exec.min.js diff --git a/admin/js/common.js b/admin/js/common.js index 4c016a3..378cf32 100644 --- a/admin/js/common.js +++ b/admin/js/common.js @@ -19,6 +19,10 @@ * Search for 'Designed as interface for other plugin integration' in comments to functions * to find out which functions are safe to use in the 3rd-party integration. * Avoid accessing internal variables directly, as they are subject to be re-designed at any time. + * Single global variable 'qTranslateConfig' is an entry point to the interface. + * - qTranslateConfig.qtx - is a shorthand reference to the only global object of type 'qTranslateX'. + * - qTranslateConfig.js - is a place where custom Java script functions are stored, if needed. + * Read Integration Guide, https://qtranslatexteam.wordpress.com/integration/, for more information. */ /* // debugging tools, do not check in @@ -62,7 +66,7 @@ qtranxj_split_blocks = function(blocks) //if(!qtranxj_isArray(blocks))//since 3.2.7 if(!blocks || !blocks.length) return result; - if(blocks.length==1){//no language separator found, enter it to all languages + if(blocks.length==1){ //no language separator found, enter it to all languages var b=blocks[0]; //for(var j=0; j 2 && inpField.name.lastIndexOf('[]') == inpField.name.length-2 ){ - inpField.id += (++contentHookId);// then second call to addContentHook for the same field will create additional set - no good, but should not happen - } + if(inpField.id){ + if(contentHooks[inpField.id]){ + if(jQuery.contains(document,inpField)) + return contentHooks[inpField.id]; + //otherwise some Java script already removed previously hooked element + qtx.removeContentHook(inpField); + } + }else{ + jQuery(inpField).uniqueId(); } - if(contentHooks[inpField.id]) return true; - var h=contentHooks[inpField.id]={}; - //h.id=inpField.id; - h.name=inpField.name; + //co('addContentHook: id=',inpField.id); + var h = contentHooks[inpField.id]={}; + //h.id = inpField.id; + h.name = inpField.name; h.contentField=inpField; //c('addContentHook: inpField.value='+inpField.value); - h.lang=qTranslateConfig.activeLanguage; - var contents=qtranxj_split(inpField.value);//keep neutral text from older times, just in case. + h.lang = qTranslateConfig.activeLanguage; + var contents = qtranxj_split(inpField.value);//keep neutral text from older times, just in case. //inpField.tagName inpField.value = contents[h.lang]; var bfnm, sfnm, p = h.name.indexOf('['); @@ -323,20 +355,11 @@ var qTranslateX=function(pg) h.fields[lang] = f; inpField.parentNode.insertBefore(f,inpField); } - /* since 3.2.9.8 - h.contents -> h.fields - //h.mlContentField=qtranxj_ce('input', {name: inpField.name, type: 'hidden', className: 'hidden', value: inpField.value}, form); - h.mlContentField=qtranxj_ce('input', {name: inpField.name, type: 'hidden', className: 'hidden', value: inpField.value}); - inpField.name='edit-'+inpField.name; - inpField.parentNode.insertBefore(h.mlContentField,inpField); - inpField.onblur=function(){ updateFusedValueH(this.id,this.value); } - var text = h.contents[h.lang]; - inpField.value=text; - */ if(!separator){ //if(inpField.tagName==='TEXTAREA') // separator='<'; //else - separator='[';//since 3.1 we get rid of <--:--> encoding + separator='[';//since 3.1 we get rid of <--:--> encoding } // since 3.2.9.8 - h.contents -> h.fields h.sepfield = qtranxj_ce('input', {name: bfnm+'[qtranslate-separator]', type: 'hidden', className: 'hidden', value: separator }); @@ -356,7 +379,7 @@ var qTranslateX=function(pg) for(var i=0; i h.fields inpField.onblur = function(){}; inpField.name=inpField.name.replace(/^edit-/,''); inpField.value=h.mlContentField.value; jQuery(h.mlContentField).remove(); */ - if(h.sepfield) jQuery(h.sepfield).remove(); - for(var lang in h.fields){ - jQuery(h.fields[lang]).remove(); - } jQuery(inpField).removeClass('qtranxs-translatable'); - delete contentHooks[inpField.id]; return true; }; + /** + * Designed as interface for other plugin integration. The documentation is available at + * https://qtranslatexteam.wordpress.com/integration/ + * Re-create a hook, after a piece of HTML is dynamically replaced with a custom Java script. + */ + this.refreshContentHook=function(inpField) + { + if( !inpField ) return false; + if( !inpField.id ) return false; + var h = contentHooks[inpField.id]; + if( h ) removeContentHookH(h); + return qtx.addContentHook(inpField); + } + /** * @since 3.2.7 */ var displayHookNodes=[]; - addDisplayHookNode=function(nd) + var addDisplayHookNode=function(nd) { if(!nd.nodeValue) return 0; var blocks = qtranxj_get_split_blocks(nd.nodeValue); if( !blocks || !blocks.length || blocks.length == 1 ) return 0; + //co('addDisplayHookNode: nd: ',nd); + //co('addDisplayHookNode: blocks: ',blocks); var h={}; h.nd=nd; //co('addDisplayHookNode: nd=',nd); @@ -431,11 +530,12 @@ var qTranslateX=function(pg) * @since 3.2.7 */ var displayHookAttrs=[]; - addDisplayHookAttr=function(nd) + var addDisplayHookAttr=function(nd) { if(!nd.value) return 0; var blocks = qtranxj_get_split_blocks(nd.value); if( !blocks || !blocks.length || blocks.length == 1 ) return 0; + //co('addDisplayHookAttr: nd: ',nd); var h={}; h.nd=nd; h.contents = qtranxj_split_blocks(blocks); @@ -445,10 +545,14 @@ var qTranslateX=function(pg) } /** + * Designed as interface for other plugin integration. The documentation is available at + * https://qtranslatexteam.wordpress.com/integration/ + * * @since 3.2.7 switched to use of nodeValue instead of innerHTML. */ - addDisplayHook=function(elem) + this.addDisplayHook=function(elem) { + //co('addDisplayHook: this: ',this); if(!elem || !elem.tagName) return 0; switch(elem.tagName){ case 'TEXTAREA': return 0; @@ -459,13 +563,14 @@ var qTranslateX=function(pg) } default: break; } + //co('addDisplayHook: elem: ',elem); var cnt = 0; if(elem.childNodes && elem.childNodes.length){ for(var i = 0; i < elem.childNodes.length; ++i){ var nd = elem.childNodes[i]; switch(nd.nodeType){//http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1950641247 case 1://ELEMENT_NODE - cnt += addDisplayHook(nd);//recursive call + cnt += qtx.addDisplayHook(nd);//recursive call break; case 2://ATTRIBUTE_NODE case 3://TEXT_NODE @@ -478,9 +583,15 @@ var qTranslateX=function(pg) return cnt; } - this.addDisplayHookById=function(id) { return addDisplayHook(this.ge(id)); } + /** + * Designed as interface for other plugin integration. The documentation is available at + * https://qtranslatexteam.wordpress.com/integration/ + * + * @since 3.0 + */ + this.addDisplayHookById=function(id) { return qtx.addDisplayHook(document.getElementById(id)); } - updateTinyMCE=function(h) + var updateTinyMCE=function(h) { text = h.contentField.value; //co('updateTinyMCE: window.switchEditors: ',window.switchEditors); @@ -493,7 +604,7 @@ var qTranslateX=function(pg) h.mce.setContent(text,{format: 'html'}); } - onTabSwitch=function(lang) + var onTabSwitch=function(lang) { //var qtx = this; setLangCookie(lang); @@ -524,7 +635,6 @@ var qTranslateX=function(pg) } } - qTranslateConfig.qtx = this; /* onTabSwitchCustom=function() { @@ -534,26 +644,44 @@ var qTranslateX=function(pg) } */ - addDisplayHooks=function(elems) + /** + * Designed as interface for other plugin integration. The documentation is available at + * https://qtranslatexteam.wordpress.com/integration/ + * + * @since 3.0 + */ + this.addDisplayHooks=function(elems) { //c('addDisplayHooks: elems.length='+elems.length); for(var i=0; i= 0 ){ + //var langSwitchWrap=qtranxj_ce('ul', {className: qTranslateConfig.lsb_style_wrap_class}); + //var languageSwitch = new qtranxj_LanguageSwitch(langSwitchWrap); + var langSwitchWrap = createSetOfLSB(); + anchor.f.parentNode.insertBefore( langSwitchWrap, anchor.f ); + } + if( anchor.where && anchor.where.indexOf('after') >= 0 ){ + //var langSwitchWrap=qtranxj_ce('ul', {className: qTranslateConfig.lsb_style_wrap_class}); + //var languageSwitch = new qtranxj_LanguageSwitch(langSwitchWrap); + var langSwitchWrap = createSetOfLSB(); + anchor.f.parentNode.insertBefore( langSwitchWrap, anchor.f.nextSibling ); + } + if( anchor.where && anchor.where.indexOf('first') >= 0 ){ + var langSwitchWrap = createSetOfLSB(); + anchor.f.insertBefore( langSwitchWrap, anchor.f.firstChild ); + } + if( anchor.where && anchor.where.indexOf('last') >= 0 ){ + var langSwitchWrap = createSetOfLSB(); + anchor.f.insertBefore( langSwitchWrap, null ); + } } + /** * @since 3.2.4 Synchronization of multiple sets of Language Switching Buttons */ @@ -958,9 +1212,10 @@ var qTranslateX=function(pg) } } -/** +/* + * @since 3.3.2 Moved code to two functions instead of having this object * @since 3.2.4 Multiple sets of Language Switching Buttons - */ + * function qtranxj_LanguageSwitch(langSwitchWrap) { //var langs=qTranslateConfig.enabled_languages, langNames=qTranslateConfig.language_name; @@ -1031,10 +1286,18 @@ function qtranxj_LanguageSwitch(langSwitchWrap) if(!qTranslateConfig.tabSwitches[lang]) qTranslateConfig.tabSwitches[lang] = []; qTranslateConfig.tabSwitches[lang].push(tabSwitch); } -} +}// */ /** + * Designed as interface for other plugin integration. The documentation is available at + * https://qtranslatexteam.wordpress.com/integration/ + * * qTranslateX instance is saved in global variable qTranslateConfig.qtx, * which can be used by theme or plugins to dynamically change content hooks. + * @since 3.4 */ -jQuery(document).ready(function($){ new qTranslateX(qTranslateConfig.js); }); +qTranslateConfig.js.get_qtx = function(){ + if(!qTranslateConfig.qtx) new qTranslateX(qTranslateConfig.js); + return qTranslateConfig.qtx; +} +jQuery(document).ready(qTranslateConfig.js.get_qtx); diff --git a/admin/js/common.min.js b/admin/js/common.min.js index bfe8180..e0cf80a 100644 --- a/admin/js/common.min.js +++ b/admin/js/common.min.js @@ -1 +1 @@ -function qtranxj_get_cookie(n){for(var e=document.cookie.split(";"),a=0;a||\[:[a-z]{2}\]|\[:\])/gi;return n.xsplit(e)},qtranxj_split=function(n){var e=qtranxj_get_split_blocks(n);return qtranxj_split_blocks(e)},qtranxj_split_blocks=function(n){var e=new Object;for(var a in qTranslateConfig.language_config)e[a]="";if(!n||!n.length)return e;if(1==n.length){var t=n[0];for(var a in qTranslateConfig.language_config)e[a]+=t;return e}for(var i,o=//gi,r=/\[:([a-z]{2})\]/gi,a=!1,s=0;s"!=t&&"[:]"!=t)if(a)e[a]+=t,a=!1;else for(var l in e)e[l]+=t;else a=!1;else a=i[1];else a=i[1]}return e},String.prototype.xsplit=function(n){if(3==="a~b".split(/(~)/).length)return this.split(n);n.global||(n=new RegExp(n.source,"g"+(n.ignoreCase?"i":"")));for(var e,a=0,t=[];null!=(e=n.exec(this));)t.push(this.slice(a,e.index)),e.length>1&&t.push(e[1]),a=n.lastIndex;return a2&&n.name.lastIndexOf("[]")==n.name.length-2&&(n.id+=++a)),e[n.id])return!0;var o=e[n.id]={};o.name=n.name,o.contentField=n,o.lang=qTranslateConfig.activeLanguage;var r=qtranxj_split(n.value);n.value=r[o.lang];var s,l,g=o.name.indexOf("[");if(0>g)s="qtranslate-fields["+o.name+"]";else if(s="qtranslate-fields["+o.name.substring(0,g)+"]",o.name.lastIndexOf("[]")<0)s+=o.name.substring(g);else{var c=o.name.length-2;c>g&&(s+=o.name.substring(g,c)),l="[]"}o.fields={};for(var f in r){var d=r[f],u=s+"["+f+"]";l&&(u+=l);var h=qtranxj_ce("input",{name:u,type:"hidden",className:"hidden",value:d});o.fields[f]=h,n.parentNode.insertBefore(h,n)}return i||(i="["),o.sepfield=qtranxj_ce("input",{name:s+"[qtranslate-separator]",type:"hidden",className:"hidden",value:i}),n.parentNode.insertBefore(o.sepfield,n),o.separator=i,n.className+=" qtranxs-translatable",o},this.addContentHookC=function(n,e){return addContentHook(n,e,"[")},this.addContentHookB=function(n,e){return addContentHook(n,e,"[")},this.addContentHookById=function(n,e,a){return addContentHook(this.ge(n),e,a)},this.addContentHookByIdName=function(n,e){var a;switch(n[0]){case"<":case"[":a=n.substring(0,1),n=n.substring(1)}return this.addContentHookById(n,e,a)},this.addContentHookByIdC=function(n,e){return this.addContentHookById(n,e,"[")},this.addContentHookByIdB=function(n,e){return this.addContentHookById(n,e,"[")},this.removeContentHook=function(n){if(!n)return!1;if(!n.id)return!1;if(!e[n.id])return!1;var a=e[n.id];a.sepfield&&jQuery(a.sepfield).remove();for(var t in a.fields)jQuery(a.fields[t]).remove();return jQuery(n).removeClass("qtranxs-translatable"),delete e[n.id],!0};var t=[];addDisplayHookNode=function(n){if(!n.nodeValue)return 0;var e=qtranxj_get_split_blocks(n.nodeValue);if(!e||!e.length||1==e.length)return 0;var a={};return a.nd=n,a.contents=qtranxj_split_blocks(e),n.nodeValue=a.contents[qTranslateConfig.activeLanguage],t.push(a),1};var i=[];if(addDisplayHookAttr=function(n){if(!n.value)return 0;var e=qtranxj_get_split_blocks(n.value);if(!e||!e.length||1==e.length)return 0;var a={};return a.nd=n,a.contents=qtranxj_split_blocks(e),n.value=a.contents[qTranslateConfig.activeLanguage],i.push(a),1},addDisplayHook=function(n){if(!n||!n.tagName)return 0;switch(n.tagName){case"TEXTAREA":return 0;case"INPUT":switch(n.type){case"submit":if(n.value)return addDisplayHookAttr(n);default:return 0}}var e=0;if(n.childNodes&&n.childNodes.length)for(var a=0;a||\[:[a-z]{2}\]|\[:\])/gi;return e.xsplit(n)},qtranxj_split=function(e){var n=qtranxj_get_split_blocks(e);return qtranxj_split_blocks(n)},qtranxj_split_blocks=function(e){var n=new Object;for(var a in qTranslateConfig.language_config)n[a]="";if(!e||!e.length)return n;if(1==e.length){var t=e[0];for(var a in qTranslateConfig.language_config)n[a]+=t;return n}for(var i,r=//gi,o=/\[:([a-z]{2})\]/gi,a=!1,s=0;s"!=t&&"[:]"!=t)if(a)n[a]+=t,a=!1;else for(var l in n)n[l]+=t;else a=!1;else a=i[1];else a=i[1]}return n},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 n,a=0,t=[];null!=(n=e.exec(this));)t.push(this.slice(a,n.index)),n.length>1&&t.push(n[1]),a=e.lastIndex;return al)o="qtranslate-fields["+i.name+"]";else if(o="qtranslate-fields["+i.name.substring(0,l)+"]",i.name.lastIndexOf("[]")<0)o+=i.name.substring(l);else{var g=i.name.length-2;g>l&&(o+=i.name.substring(l,g)),s="[]"}i.fields={};for(var f in r){var c=r[f],u=o+"["+f+"]";s&&(u+=s);var d=qtranxj_ce("input",{name:u,type:"hidden",className:"hidden",value:c});i.fields[f]=d,e.parentNode.insertBefore(d,e)}return a||(a="["),i.sepfield=qtranxj_ce("input",{name:o+"[qtranslate-separator]",type:"hidden",className:"hidden",value:a}),e.parentNode.insertBefore(i.sepfield,e),i.separator=a,e.className+=" qtranxs-translatable",i},this.addContentHookC=function(e){return n.addContentHook(e,"[")},this.addContentHookB=function(e){return n.addContentHook(e,"[")},this.addContentHookById=function(e,a){return n.addContentHook(document.getElementById(e),a)},this.addContentHookByIdName=function(e){var a;switch(e[0]){case"<":case"[":a=e.substring(0,1),e=e.substring(1)}return n.addContentHookById(e,a)},this.addContentHookByIdC=function(e){return n.addContentHookById(e,"[")},this.addContentHookByIdB=function(e){return n.addContentHookById(e,"[")},this.addContentHooks=function(e,a){for(var t=0;t=0){var w=m();p.f.parentNode.insertBefore(w,p.f)}if(p.where&&p.where.indexOf("after")>=0){var w=m();p.f.parentNode.insertBefore(w,p.f.nextSibling)}if(p.where&&p.where.indexOf("first")>=0){var w=m();p.f.insertBefore(w,p.f.firstChild)}if(p.where&&p.where.indexOf("last")>=0){var w=m();p.f.insertBefore(w,null)}}this.addLanguageSwitchListener(c),e.onTabSwitch&&this.addLanguageSwitchListener(e.onTabSwitch)}};qTranslateConfig.js.get_qtx=function(){return qTranslateConfig.qtx||new qTranslateX(qTranslateConfig.js),qTranslateConfig.qtx},jQuery(document).ready(qTranslateConfig.js.get_qtx); \ No newline at end of file diff --git a/admin/js/edit-custom-page.js b/admin/js/edit-custom-page.js deleted file mode 100644 index 3e1ac3d..0000000 --- a/admin/js/edit-custom-page.js +++ /dev/null @@ -1,21 +0,0 @@ -/* -Loaded for a page requested by the user on configuration -*/ -qTranslateConfig.js={ - addContentHooks: function(qtx) - { - var form = qtx.getWrapForm(); - if(!form) return false; - qtx.addCustomContentHooks(form); - this.langSwitchWrapAnchor=form; - return true; - } -/* -, - onTabSwitch: function(lang) - { - var qtx = this;// object of qTranslateX - //implement additional actions on tab click, if applicable. - } -*/ -}; diff --git a/admin/js/edit-custom-page.min.js b/admin/js/edit-custom-page.min.js deleted file mode 100644 index 4e0ae1c..0000000 --- a/admin/js/edit-custom-page.min.js +++ /dev/null @@ -1 +0,0 @@ -qTranslateConfig.js={addContentHooks:function(n){var o=n.getWrapForm();return o?(n.addCustomContentHooks(o),this.langSwitchWrapAnchor=o,!0):!1}}; \ No newline at end of file diff --git a/admin/js/edit-nav-menus.js b/admin/js/edit-nav-menus.js index cdd6b90..08dc00c 100644 --- a/admin/js/edit-nav-menus.js +++ b/admin/js/edit-nav-menus.js @@ -7,29 +7,29 @@ qTranslateConfig.js={ var form=document.getElementById('update-nav-menu'); if(!form) return false; - addMenuItemHooks=function(li,form) + addMenuItemHooks=function(li) { - qtx.addContentHooksByClass('edit-menu-item-title',form,li); - qtx.addContentHooksByClass('edit-menu-item-attr-title',form,li); - qtx.addContentHooksByClass('[edit-menu-item-description',form,li);//must use '[:]' separator style + qtx.addContentHooksByClass('edit-menu-item-title',li); + qtx.addContentHooksByClass('edit-menu-item-attr-title',li); + qtx.addContentHooksByClass('[edit-menu-item-description',li);//must use '[:]' separator style qtx.addDisplayHooksByClass('menu-item-title',li); qtx.addDisplayHooksByClass('item-title',li); qtx.addDisplayHooksByTagInClass('link-to-original','A',li); } - function addMenuPageHooks(qtx,form) + function addMenuPageHooks(qtx) { var items=document.getElementsByClassName('menu-item'); for(var i=0; i tr > td.name span.inline').css('display','none'); + + //make page to reload page on submit of a new taxonomy + var submit_button = document.getElementById('submit'); + if(submit_button){ + submit_button.addEventListener('click',function(){ + setTimeout(function(){window.location.reload();},800); + //addDisplayHookRows(theList);//does not work, because the updates on theList has not yet propagated + }); + } + +}); diff --git a/admin/js/edit-tags-exec.min.js b/admin/js/edit-tags-exec.min.js new file mode 100644 index 0000000..a24de47 --- /dev/null +++ b/admin/js/edit-tags-exec.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function(){var e=qTranslateConfig.js.get_qtx(),n=document.getElementById("addtag");if(n){var a=e.addContentHookByIdB("tag-name");if(a){qtranxj_ce("input",{name:"qtrans_term_field_name",type:"hidden",className:"hidden",value:a.name},n,!0);var t=a.fields[qTranslateConfig.default_language].value;qtranxj_ce("input",{name:"qtrans_term_field_default_name",type:"hidden",className:"hidden",value:t},n,!0),jQuery("#the-list > tr > td.name span.inline").css("display","none");var d=document.getElementById("submit");d&&d.addEventListener("click",function(){setTimeout(function(){window.location.reload()},800)})}}}); \ No newline at end of file diff --git a/admin/js/edit-tags.js b/admin/js/edit-tags.js index 7554454..5febed6 100644 --- a/admin/js/edit-tags.js +++ b/admin/js/edit-tags.js @@ -1,5 +1,5 @@ /* loaded in - /wp-admin/edit-tag.php + /wp-admin/edit-tags.php */ qTranslateConfig.js={ addContentHooks: function(qtx) @@ -7,10 +7,10 @@ qTranslateConfig.js={ var form = document.getElementById('addtag');//AjaxForm if(!form) return false; - var h=qtx.addContentHookByIdB('tag-name',form); + var h=qtx.addContentHookByIdB('tag-name'); if(!h) return false; - qtx.addContentHookByIdC('tag-description',form); + qtx.addContentHookByIdC('tag-description'); qtranxj_ce('input', {name: 'qtrans_term_field_name', type: 'hidden', className: 'hidden', value: h.name }, form, true); diff --git a/admin/js/edit-tags.min.js b/admin/js/edit-tags.min.js index d378c51..085a7e5 100644 --- a/admin/js/edit-tags.min.js +++ b/admin/js/edit-tags.min.js @@ -1 +1 @@ -qTranslateConfig.js={addContentHooks:function(e){var a=document.getElementById("addtag");if(!a)return!1;var n=e.addContentHookByIdB("tag-name",a);if(!n)return!1;e.addContentHookByIdC("tag-description",a),qtranxj_ce("input",{name:"qtrans_term_field_name",type:"hidden",className:"hidden",value:n.name},a,!0);var t=n.fields[qTranslateConfig.default_language].value;qtranxj_ce("input",{name:"qtrans_term_field_default_name",type:"hidden",className:"hidden",value:t},a,!0),e.addDisplayHookById("parent");var d=document.getElementById("the-list");hideQuickEditRow=function(e){var a=e.getElementsByTagName("TD");if(a.length)for(var n=a[0],t=n.getElementsByClassName("inline"),d=0;d $opn){ + if(empty($cfg[$nm])) delete_option($opn); + else update_option($opn,$cfg[$nm]); + } + return $cfg; +} + /** * since 3.2.9.2 */ @@ -66,50 +64,62 @@ function qtranxf_default_default_language() return $default_language; } -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 '

'; -} -add_action('admin_notices', 'qtranxf_admin_notice_first_install'); - -function qtranxf_admin_notice_deactivate_plugin($nm,$plugin) -{ - deactivate_plugins($plugin,true); - $d=dirname($plugin); - $link=''.$nm.''; - $qtxnm='qTranslate‑X'; - $qtxlink=''.$qtxnm.''; - $imported=false; - //if($first_install){ - $f='qtranxf_migrate_import_'.str_replace('-','_',dirname($plugin)); - if(function_exists($f)){ - global $wpdb; - $options = $wpdb->get_col("SELECT `option_name` FROM {$wpdb->options} WHERE `option_name` LIKE 'qtranslate_%'"); - if(empty($options)){ - $f(); - $imported=true; +/** + * @since 3.3.2 + */ +function qtranxf_load_config_files($json_files){ + $content_dir = null; + $qtransx_dir = null; + foreach($json_files as $k => $fnm){ + //$fnm = trim($v,'/\\'); + if(file_exists($fnm)) continue; + $ffnm = null; + if($fnm[0] == '.' && $fnm[1] == '/'){ + if(!$qtransx_dir) $qtransx_dir = QTRANSLATE_DIR; + $ffnm = $qtransx_dir.substr($fnm,1); + } + if(!file_exists($ffnm)){ + if(!$content_dir) $content_dir = trailingslashit(WP_CONTENT_DIR); + $ffnm = $content_dir.$fnm; + } + if(file_exists($ffnm)){ + $json_files[$k] = $ffnm; + }else{ + qtranxf_error_log(sprintf(__('Could not find file "%s" listed in option "%s".', 'qtranslate'), $fnm, __('Configuration Files', 'qtranslate'))); + unset($json_files[$k]); } } - //} - $s = '

'.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 '

'; +} +add_action('admin_notices', 'qtranxf_admin_notice_first_install'); + +function qtranxf_admin_notice_deactivate_plugin($nm,$plugin) +{ + deactivate_plugins($plugin,true); + $d=dirname($plugin); + $link=''.$nm.''; + $qtxnm='qTranslate‑X'; + $qtxlink=''.$qtxnm.''; + $imported=false; + //if($first_install){ + $f='qtranxf_migrate_import_'.str_replace('-','_',dirname($plugin)); + if(function_exists($f)){ + global $wpdb; + $options = $wpdb->get_col("SELECT `option_name` FROM {$wpdb->options} WHERE `option_name` LIKE 'qtranslate_%'"); + if(empty($options)){ + $f(); + $imported=true; + } + } + //} + $s = '

'.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 = '
    '; + foreach($q_config['enabled_languages'] as $lang){ + $lsb .= '
  • '.$q_config['language_name'][$lang].'
  • '; + } + $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); ?>