/*! * phpwcms * * @author Oliver Georgi * @copyright Copyright (c) 2002-2026, Oliver Georgi * @license http://opensource.org/licenses/GPL-2.0 GNU GPL-2 * */ "use strict";let temp_url=null;function login(e){return"2"==e.json.value?(e.customlang.value=1,e.submit(),!0):(e.json.value=0,e.form_password.value&&e.form_loginname.value?(e.json.value=1,!0):(showLayer("jserr"),!1))}function swapImage(...e){document.MM_sr=document.MM_sr||[];for(let t=0;t/g,">").replace(/"/g,""").replace(/'/g,"'")}function formatConfirmMessage(e){return escapeHtmlText(e).replace(/\r?\n/g,"
")}function bsConfirm(e,t,n,o,i,s){if(window.parent&&window.parent!==window&&"function"==typeof window.parent.bsConfirm)return void window.parent.bsConfirm(e,t,n,o,i,s);const a="bootstrapConfirmModal";let l=$("#"+a);if(0===l.length){const e='';$("body").append(e),l=$("#"+a),l.on("hide.bs.modal",function(){l.has(document.activeElement).length&&document.activeElement.blur()})}const c=i||window.PHPWCMS_LANG&&window.PHPWCMS_LANG.cancel||"Cancel";l.find(".cancel-btn").text(c);const r=o||window.PHPWCMS_LANG&&window.PHPWCMS_LANG.ok||"OK",d=(e||"info").toLowerCase().trim();let u="btn-info text-white",p="text-info",f="fa-solid fa-info-circle";"danger"===d||"delete"===d?(u="btn-danger text-white",p="text-danger",f="fa-solid fa-trash-alt"):"primary"===d||"move"===d?(u="btn-primary text-white",p="text-primary",f="fa-solid fa-arrows-alt"):"warning"===d||"flush"===d?(u="btn-warning text-dark",p="text-warning",f="fa-solid fa-exclamation-triangle"):"success"===d&&(u="btn-success text-white",p="text-success",f="fa-solid fa-check-circle"),l.find(".alert-container").removeClass("alert-warning alert-danger alert-primary alert-info alert-success").addClass("alert-light").css("border","1px solid #dee2e6"),l.find(".icon-container").removeClass("text-warning text-danger text-primary text-info text-success").addClass(p),l.find(".icon-container i").removeClass().addClass(f),l.find(".confirm-btn").removeClass("btn-danger btn-primary btn-info btn-warning btn-success text-white text-dark").addClass(u).text(r),l.find(".confirm-message").html(formatConfirmMessage(t));const m="undefined"!=typeof bootstrap&&bootstrap.Modal?bootstrap.Modal.getOrCreateInstance(l[0]):null;let h=!1;l.find(".confirm-btn").off("click").on("click",function(){h=!0,m?m.hide():l.modal("hide"),"function"==typeof n&&n()}),l.off("hidden.bs.modal").on("hidden.bs.modal",function(){h||"function"!=typeof s||s(),h=!1}),m?m.show():l.modal("show")}function bsConfirmWarning(e,t,n,o,i){bsConfirm("warning",e,t,n,o,i)}function bsConfirmDanger(e,t,n,o,i){bsConfirm("danger",e,t,n,o,i)}function bsConfirmInfo(e,t,n,o){bsConfirm("info",e,t,n,o)}function bsConfirmSuccess(e,t,n,o){bsConfirm("success",e,t,n,o)}function bsConfirmDelete(e,t,n,o){bsConfirm("delete",e,t,n,o)}function initTomSelectTagAutosuggest(e,t,n,o){const i=$(e),s=$(t);if(!i.length||"function"!=typeof TomSelect)return null;if(i[0].tomselect)return i[0].tomselect;const a=(s.val()||"").split(",").map(e=>e.trim()).filter(Boolean),l=a.map(e=>({value:e,text:e})),c=Object.assign({plugins:["remove_button"],valueField:"text",labelField:"text",searchField:"text",create:!0,createFilter:function(e){return e.trim().length>0},options:l,items:a,load:function(e,t){if(!e.length)return t();const o=(window.PHPWCMS_URL||"")+"include/inc_act/ajax_connector.php";$.ajax({url:o,type:"GET",dataType:"json",data:{action:n||"category",method:"json",value:e},error:function(){t()},success:function(e){const n=(e||[]).map(e=>{const t="object"==typeof e?e.cat_name||e.text||e.allowed_lang:e;return{value:t,text:t}});t(n)}})},onChange:function(e){const t=Array.isArray(e)?e.join(", "):e||"";s.val(t)}},o||{}),r=new TomSelect(i[0],c);return i.closest("form").on("submit",function(){const e=r.getValue(),t=Array.isArray(e)?e.join(", "):e||"";s.val(t)}),r}function bsConfirmMove(e,t,n,o){bsConfirm("move",e,t,n,o)}function bsConfirmFlush(e,t,n,o){bsConfirm("flush",e,t,n,o)}function bsAlert(e,t){if(window.parent&&window.parent!==window&&"function"==typeof window.parent.bsAlert)return void window.parent.bsAlert(e,t);const n="bootstrapAlertModal";let o=$("#"+n);if(0===o.length){const e='';$("body").append(e),o=$("#"+n),o.on("hide.bs.modal",function(){o.has(document.activeElement).length&&document.activeElement.blur()})}o.find(".confirm-message").html(formatConfirmMessage(e));const i="undefined"!=typeof bootstrap&&bootstrap.Modal?bootstrap.Modal.getOrCreateInstance(o[0]):null;o.find(".confirm-btn").off("click").on("click",function(){i?i.hide():o.modal("hide"),"function"==typeof t&&t()}),i?i.show():o.modal("show")}function confirmGoUrl(e,t){bsConfirm("info",e,function(){location.href=t})}function wordcount(e){var t=String(e||"").trim();return""===t?0:(t=t.split(/\s+/)).length}function flevPopupLink(e,t,n,o){const i=window.open(e,t,n);return o&&i&&i.focus(),!1}function popupOpen(e,t,n,o){const i=window[t];!i||i.closed?(window[t]=window.open(e,t,n),window[t]&&o&&window[t].focus()):o?i.focus():(window[t]=window.open(e,t,n),window[t]&&window[t].focus())}function popupControl(e,t){if("self"===e)return void window.close();const n=window[e];n&&!n.closed&&("focus()"===t?n.focus():"close()"===t&&n.close())}function tmt_winOpen(e,t,n,o){popupOpen(e,t,n,o)}function tmt_winControl(e,t){popupControl(e,t)}function hideLayer(e){toggleDisplayById(e,"none")}function showLayer(e){toggleDisplayById(e,"")}function toggleDisplayById(e,t){const n=document.getElementById(e);n&&(n.style.display=t)}function doMapChange(){document.articlecontent.cmap_location_edited.value="1"}function setCursorPos(e){e.createTextRange&&(e.cursorPos=document.selection.createRange().duplicate())}function insertAtCursorPos(e,t){if(!e)return;if("string"!=typeof t||""===t)return;if(e._aceEditor)return e._aceEditor.insert(t),void e._aceEditor.focus();const n=e.id||e.name||"";if("undefined"!=typeof CKEDITOR&&CKEDITOR.instances&&(CKEDITOR.instances[n]||CKEDITOR.instances[e.name])){const o=CKEDITOR.instances[n]||CKEDITOR.instances[e.name];return o.insertHtml(t),void o.focus()}if("undefined"!=typeof tinymce&&(tinymce.get(n)||tinymce.get(e.name))){const o=tinymce.get(n)||tinymce.get(e.name);return o.insertContent(t),void o.focus()}if(e.focus(),"number"==typeof e.selectionStart&&"number"==typeof e.selectionEnd){const n=e.selectionStart,o=e.selectionEnd,i=e.value.substring(0,n),s=e.value.substring(o);e.value=i+t+s,e.selectionStart=e.selectionEnd=n+t.length}else e.value+=t}function getFieldById(e){return document.getElementById(e)||null}function enableStatusMessage(e,t,n){const o=document.getElementById(e);return!o||(n&&(o.innerHTML=n),o.style.display=t?"block":"none",!0)}function create_alias(e,t,n,o){o=null==o?aliasAllowSlashes:Boolean(o),"string"!=typeof e&&(e=String(e||""));try{-1!==e.indexOf("%")&&(e=decodeURIComponent(e))}catch(e){}if(e=(e=(e=(e=(e=e.toLowerCase()).replace(/\[br\]/g," ")).replace(/__/g," ")).replace(/\s+/g,"-")).replace(/[\?\+#=]/g,"-"),o||(e=e.replace(/\//g,"-")),e=e.replace(/-+\/+-+/g,"/"),aliasUtf8?e=o?e.replace(/[^a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF0-9_\-\/\.]+/g,""):e.replace(/[^a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF0-9_\-\.]+/g,""):(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace(/[\u00E0\u00E1\u00E2\u00E3\u00E5]/g,"a")).replace(/[\u00E7]/g,"c")).replace(/[\u00E8\u00E9\u00EA\u00EB]/g,"e")).replace(/[\u00EC\u00ED\u00EE\u00EF]/g,"i")).replace(/[\u00F2\u00F3\u00F4\u00F5\u00F8]/g,"o")).replace(/[\u00F9\u00FA\u00FB]/g,"u")).replace(/[\u00FD\u00FF]/g,"y")).replace(/[\u00F1]/g,"n")).replace(/[\u0153\u00F6]/g,"oe")).replace(/[\u00E6\u00E4]/g,"ae")).replace(/[\u00DF]/g,"ss")).replace(/[\u00FC]/g,"ue"),e=o?e.replace(/[^a-z0-9_\-\/\.]+/g,""):e.replace(/[^a-z0-9_\-\.]+/g,"")),o&&(e=(e=e.replace(/\/+/g,"/")).replace(/[\-_]*\/+[\-_]*/g,"/")),e=(e=e.replace(/\-+/g,"-")).replace(/_+/g,"_"),e=o?(e=e.replace(/\/+/g,"/")).replace(/^[\-_\/\.]+|[\-_\/\.]+$/g,""):e.replace(/^[\-_\.]+|[\-_\.]+$/g,""),1===n||!0===n){const t=e.charAt(0);e=t.toUpperCase()+e.slice(1)}if("undefined"!=typeof aliasMaxLength&&aliasMaxLength>0){const t=Array.from(e);t.length>aliasMaxLength&&(e=(e=t.slice(0,aliasMaxLength).join("")).replace(/[\-_.\/]+$/,""))}return e}$(document).on("click","[data-confirm], [data-confirm-danger], [data-confirm-warning]",function(e){const t=$(this),n=t.attr("href"),o=t.attr("data-confirm")||t.attr("data-confirm-danger")||t.attr("data-confirm-warning"),i=t.attr("data-confirm-type")||(t.attr("data-confirm-danger")?"danger":t.attr("data-confirm-warning")?"warning":"danger"),s=t.attr("data-confirm-btn");return!o||(e.preventDefault(),bsConfirm(i,o,function(){n&&"#"!==n&&"javascript:void(0);"!==n?window.location.href=n:(t.is(":submit")||t.is('button[type="submit"]'))&&t.closest("form").submit()},s),!1)}),window.alert=function(e){bsAlert(e)};let fbw=450,fbh=575;function openFileBrowser(e){null!=e&&""!==e&&(window.imageBrowser&&temp_url!==e&&tmt_winControl("imageBrowser","close()"),tmt_winOpen(e,"imageBrowser","width="+fbw+",height="+fbh+",left=8,top=8,scrollbars=yes,resizable=yes",1),temp_url=e)}function set_article_alias(e,t,n){let o="article_title",i="article_alias";"struct"===t&&(o="acat_name",i="acat_alias");const s=document.getElementById(i);if(e&&""!==s.value)return!1;const a=document.getElementById(o);return s.value=create_alias((n?n+"/":"")+a.value),!1}function set_file_alias(e,t,n){const o=t||"file_alias",i=n||"file_name",s=document.getElementById(o);if(!s||e&&""!==s.value)return!1;const a=document.getElementById(i);if(a){let e=a.value;const t=e.lastIndexOf(".");t>0&&(e=e.substring(0,t)),s.value=create_alias(e,null,null,!1)}return!1}function flush_image_cache(e,t,n,o){const i=function(){e.classList.add("ajax-running"),$.ajax({url:t,dataType:"json",xhrFields:{withCredentials:!0},success:function(t){if(e.classList.remove("ajax-running"),t&&"ok"===t.status){const e=o?o.replace("%d",t.file_count||0):"Success";alert(e)}else alert("Error flushing image cache")},error:function(){e.classList.remove("ajax-running"),alert("Error connecting to server")}})};if(n){const t=$(e),o=t.attr("data-confirm-action");bsConfirm(t.attr("data-confirm-type"),n,i,o)}else i();return!1}function togglePasswordVisibility(e,t){const n="string"==typeof e?document.getElementById(e):e;if(n){n.type="password"===n.type?"text":"password";const e="text"===n.type;if(t){const n=t.querySelector("i, svg");n&&(n.classList.contains("fa-eye")||n.classList.contains("fa-eye-slash")?(n.classList.toggle("fa-eye",!e),n.classList.toggle("fa-eye-slash",e)):(n.classList.contains("bi-eye")||n.classList.contains("bi-eye-slash"))&&(n.classList.toggle("bi-eye",!e),n.classList.toggle("bi-eye-slash",e))),t.hasAttribute("aria-pressed")&&t.setAttribute("aria-pressed",e?"true":"false")}return e?"hide":"show"}}function initPasswordToggle(){window._phpwcmsPasswordToggleBound||(window._phpwcmsPasswordToggleBound=!0,document.addEventListener("click",e=>{const t=e.target.closest('[data-coreui-toggle="password"], [data-toggle="password"], [data-bs-toggle="password"], .form-password-action');if(!t)return;e.preventDefault();let n=null;const o=t.getAttribute("data-target")||t.getAttribute("data-bs-target")||t.getAttribute("data-coreui-target")||t.getAttribute("href");if(o&&"#"!==o)n=document.querySelector(o);else{const e=t.closest(".form-password, .input-group");e&&(n=e.querySelector('input[type="password"], input[type="text"]'))}n&&togglePasswordVisibility(n,t)}))}function copyToClipboard(e){if(navigator.clipboard&&window.isSecureContext)return navigator.clipboard.writeText(e);{const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t);const n=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),n&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(n))}}function keyword_submit_action(e,t,n){const o=e.form||document.getElementById("keywordListing");o&&(o.keyword_selected_id.value=t,o.keyword_action.value=n,o.submit())}function toggleKeywordCheckboxes(e){document.querySelectorAll(".keyword-checkbox").forEach(function(t){t.checked=e.checked})}function hasOptions(e){return null!=e&&null!=e.options}function selectUnselectMatchingOptions(e,t,n,o){if(!window.RegExp||!hasOptions(e))return;const i="select"===n,s=!i,a=new RegExp(t);for(let t=0;tnew Option(e.text,e.value,e.defaultSelected,e.selected));if(t.length){t.sort((e,t)=>e.text.localeCompare(t.text));for(let n=0;n=0;t--)e.options[t].selected&&(e.options[t]=null);n&&(sortSelect(e),sortSelect(t)),e.selectedIndex=-1,t.selectedIndex=-1}}function copySelectedOptions(e,t,n=!0){const o={};if(hasOptions(t))for(let e=0;e=0;t--)e.options[t].selected&&t!==e.options.length-1&&!e.options[t+1].selected&&(swapOptions(e,t,t+1),e.options[t+1].selected=!0)}function removeSelectedOptions(e){if(hasOptions(e)){for(let t=e.options.length-1;t>=0;t--)e.options[t].selected&&(e.options[t]=null);e.selectedIndex=-1}}function removeAllOptions(e){if(hasOptions(e)){for(let t=e.options.length-1;t>=0;t--)e.options[t]=null;e.selectedIndex=-1}}function addOption(e,t,n,o){hasOptions(e)&&(e.options[e.options.length]=new Option(t,n,!1,o))}void 0!==screen.width&&(fbw=Math.ceil(Math.max(screen.width/5,fbw))),void 0!==screen.height&&(fbh=Math.ceil(Math.max(screen.height/2,fbh))),$(function(){const e=$(document),t=($(window),$("body")),n=($("#page-wrapper"),$(".modal .modal-body"),$("#browserModal iframe")),o=$("#browserModal h2");$("#button-menu").on("click",function(e){e.preventDefault(),$("#column-left").toggleClass("active")}),e.on("click",".confirm-link",function(e){e.preventDefault();const t=$(this),n=t.attr("data-confirm")||"Are you sure?",o=t.attr("data-confirm-action"),i=t.attr("data-confirm-type")||"info",s=t.attr("href");bsConfirm(i,n,function(){window.location.href=s},o)}),e.on("click",'a[onclick*="confirm("], button[onclick*="confirm("], input[type="submit"][onclick*="confirm("], input[type="button"][onclick*="confirm("]',function(e){const t=$(this),n=t.attr("onclick");if(!n)return;const o=n.match(/confirm\(\s*(['"])([\s\S]*?)\1\s*\)/);if(o){e.preventDefault(),e.stopImmediatePropagation();const i=window.confirm;window.confirm=function(){return!1},setTimeout(function(){window.confirm=i},1);const s=o[2],a=t.attr("data-confirm-action"),l=t.attr("data-confirm-type")||"info";bsConfirm(l,s,function(){if(t.is("a")){const e=t.attr("href");if(e&&"#"!==e){const n=t.attr("target");n&&"_self"!==n?window.open(e,n):window.location.href=e}}else if(t.is('input[type="submit"], button[type="submit"]')){const e=t.attr("name"),n=t.closest("form");n.length&&(e&&$("").attr({type:"hidden",name:e,value:t.val()||"1"}).appendTo(n),n.submit())}else t.attr("onclick",n.replace(/return\s+confirm\(.*?\);?/,"")),t.click(),t.attr("onclick",n)},a,l)}});const i="undefined"!=typeof bootstrap&&bootstrap.Tooltip&&bootstrap.Tooltip.Default?bootstrap.Tooltip.Default.allowList:{},s=Object.assign({},i,{table:["class"],thead:[],tbody:[],tfoot:[],tr:["class"],th:["colspan","rowspan","class"],td:["colspan","rowspan","class"],caption:[],colgroup:[],col:["span"],br:[],small:[],dl:[],dt:[],dd:[],hr:[],u:[],s:[],sub:[],sup:[],pre:[],code:[],p:["class"],div:["class"],span:["class"],i:["class","aria-hidden"],b:[],strong:[],em:[]}),a=Object.assign({},s);delete a.a;const l=Object.assign({},s,{a:["target","href","title","rel"]});function c(e){"undefined"!=typeof bootstrap&&bootstrap.Popover&&(e||document).querySelectorAll('[data-bs-toggle="popover"]').forEach(function(e){bootstrap.Popover.getOrCreateInstance(e,{html:!0,container:"body",sanitize:!0,allowList:l})})}"undefined"!=typeof bootstrap&&bootstrap.Tooltip?document.querySelectorAll('[data-bs-toggle="tooltip"], [data-toggle="tooltip"]').forEach(function(e){bootstrap.Tooltip.getOrCreateInstance(e,{html:!0,delay:{show:200,hide:50},container:"body",sanitize:!0,allowList:a})}):"function"==typeof $.fn.tooltip&&t.tooltip({selector:'[data-bs-toggle="tooltip"], [data-toggle="tooltip"]',html:!0,delay:{show:200,hide:50},container:"body",sanitize:!0,allowList:a}),c(),e.on("mouseenter focusin",'[data-bs-toggle="popover"]',function(){c(this.parentNode)}),e.on("show.bs.popover",'[data-bs-toggle="popover"]',function(){const e=$(this).closest('[data-bs-toggle="tooltip"]'),t=e.length&&bootstrap.Tooltip.getInstance(e[0]);t&&(t.hide(),t.disable())}),e.on("hidden.bs.popover",'[data-bs-toggle="popover"]',function(){const e=$(this).closest('[data-bs-toggle="tooltip"]'),t=e.length&&bootstrap.Tooltip.getInstance(e[0]);t&&t.enable()}),e.on("click",".modalButton",function(e){const t=$(this);let i=t.attr("data-src")||"";if(!i)return;"undefined"!=typeof CSRF_GET_TOKEN&&CSRF_GET_TOKEN&&-1===i.indexOf("csrftoken=")&&(i+=(-1===i.indexOf("?")?"?":"&")+CSRF_GET_TOKEN);const s=t.attr("alt")||t.attr("title")||"";n.attr({src:i,height:"100%",width:"100%"}),o.text(s)}),$("#browserModal").on("hidden.bs.modal",function(){n.attr("src","about:blank")}),$('[id^="abtn"]').on("click",function(e){let t=$(this);const n=t.attr("data-type"),o=t.attr("data-table"),i=t.attr("data-field"),s=t.attr("data-fieldid"),a=t.attr("data-id"),l="#abtn"+n+t.attr("data-id"),c="undefined"!=typeof CSRF_GET_TOKEN&&CSRF_GET_TOKEN?CSRF_GET_TOKEN:"";$.ajax({url:"include/inc_act/ajax_changer.php"+(c?"?"+c:""),xhrFields:{withCredentials:!0},data:{table:o,id:a,field:i,fieldid:s},success:function(e){let n=$(l);n.length||(n=t);const o=n.find("i");n.hasClass("btn-success")?(n.removeClass("btn-success").addClass("btn-warning"),o.length&&o.removeClass("fa-eye fa-lock-open").addClass(n.hasClass("public")?"fa-lock":"fa-eye-slash")):(n.removeClass("btn-warning btn-danger").addClass("btn-success"),o.length&&o.removeClass("fa-eye-slash fa-lock").addClass(n.hasClass("public")?"fa-lock-open":"fa-eye"))},error:function(e,t,n){alert(e.status+" "+n)}})}),$('[id^="imgpos"]').on("click",function(){const e=$(this).attr("id")||"",t=parseInt(e.replace(/\D/g,""),10);$("#cimage_pos").val(isNaN(t)?"":t);for(let e=0;e<=9;e++)e===t?$("#imgpos"+e).removeClass("btn-blue").addClass("btn-success"):$("#imgpos"+e).removeClass("btn-success").addClass("btn-blue")}),$("#side-menu li").on("click",function(){$("#side-menu ul").css("display","none"),$(this).children("ul").css("display","block");let e=window.innerHeight>0?window.innerHeight:screen.height;e-=95;const t=$("#side-menu").height()+190;e{const o=document.getElementById(`${e}_${n}`);o&&(o.style.display="block"===t?"table-row":t)});const s=document.getElementById(e);return s&&(s.innerHTML=o),!1}function insertOptionBefore(e,t,n){const o=document.getElementById(e);if(o&&o.selectedIndex>=0){const e=new Option(n,t),i=o.options[o.selectedIndex];o.add(e,i)}}function removeOptionSelected(e){const t=document.getElementById(e);if(t)for(let e=t.length-1;e>=0;e--)t.options[e].selected&&t.remove(e)}function appendOptionLast(e,t,n){const o=document.getElementById(e);o&&o.add(new Option(n,t))}function removeOptionLast(e){const t=document.getElementById(e);t&&t.length>0&&t.remove(t.length-1)}let phpwcmsThemeInitialized=!1;function initPhpwcmsTheme(){function e(){return localStorage.getItem("phpwcms_theme")||document.documentElement.getAttribute("data-theme")||"auto"}function t(e,t=!0){["light","dark","auto"].includes(e)||(e="auto"),document.documentElement.setAttribute("data-theme",e),document.documentElement.setAttribute("data-bs-theme",function(e){return"auto"===e&&(e=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),"dark"===e?"dark":"light"}(e));try{localStorage.setItem("phpwcms_theme",e)}catch(e){}document.cookie="phpwcmsBETheme="+encodeURIComponent(e)+"; path=/; max-age=31536000; SameSite=Lax",function(e){document.querySelectorAll("[data-set-theme]").forEach(t=>{const n=t.getAttribute("data-set-theme")===e;t.classList.toggle("active",n);const o=t.querySelector(".theme-check");o&&o.classList.toggle("d-none",!n)});const t=document.querySelector(".theme-switcher .theme-icon-active");t&&(t.classList.remove("fa-adjust","fa-sun","fa-moon"),"dark"===e?t.classList.add("fa-moon"):"light"===e?t.classList.add("fa-sun"):t.classList.add("fa-adjust")),document.querySelectorAll("#form_theme, [data-theme-select]").forEach(t=>{t.value!==e&&(t.value=e)})}(e),updatePhpwcmsAceThemes(),!t||"undefined"==typeof $||document.body&&"login"===document.body.id||$.post("include/inc_act/ajax_connector.php",{action:"set_theme",value:e}).catch(()=>{})}t(e(),!1),phpwcmsThemeInitialized||(phpwcmsThemeInitialized=!0,window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{"auto"===e()&&t("auto",!1)}),document.addEventListener("click",e=>{const n=e.target.closest("[data-set-theme]");if(n){e.preventDefault();t(n.getAttribute("data-set-theme"),!0)}}),document.addEventListener("change",e=>{const n=e.target.closest("#form_theme, [data-theme-select]");n&&t(n.value,!0)}))}function getPhpwcmsAceTheme(){return"dark"===document.documentElement.getAttribute("data-bs-theme")?"ace/theme/one_dark":"ace/theme/chrome"}function updatePhpwcmsAceThemes(){if(!window.phpwcmsAceEditors||!window.phpwcmsAceEditors.length)return;const e=getPhpwcmsAceTheme();window.phpwcmsAceEditors.forEach(t=>{t&&"function"==typeof t.setTheme&&t.setTheme(e)})}function initAceForTextarea(e){if(!window.ace||!e||e.dataset.aceInitialized)return;ace.config.get("basePath")||ace.config.set("basePath","include/inc_js/ace/");let t=(e.dataset.mode||"html").toLowerCase();"js"===t&&(t="javascript"),"plain"===t&&(t="text");const n=parseInt(e.dataset.minLines||e.rows||8,10),o=parseInt(e.dataset.maxLines||45,10),i=document.createElement("div");i.className="phpwcms-ace-wrap";const s=document.createElement("div");s.className="phpwcms-ace-toolbar";const a=document.createElement("span");a.className="ace-mode-badge",a.textContent=t.toUpperCase();const l=window.PHPWCMS_LANG&&window.PHPWCMS_LANG.editorWordWrap||"Word wrap",c=window.PHPWCMS_LANG&&window.PHPWCMS_LANG.editorFullscreen||"Fullscreen",r=document.createElement("div");r.className="ace-btn-group";const d=document.createElement("button");d.type="button",d.className="btn-ace-tool active",d.title=l,d.setAttribute("aria-label",l),d.innerHTML='';const u=document.createElement("button");u.type="button",u.className="btn-ace-tool",u.title=c,u.setAttribute("aria-label",c),u.innerHTML='',r.appendChild(d),r.appendChild(u),s.appendChild(a),s.appendChild(r);const p=document.createElement("div");p.className="phpwcms-ace-editor",i.appendChild(s),i.appendChild(p),e.parentNode.insertBefore(i,e),e.style.display="none",e.dataset.aceInitialized="true";const f="url"===t,m=f?"text":t,h=ace.edit(p);if(h.setTheme(getPhpwcmsAceTheme()),h.session.setMode("ace/mode/"+m),h.session.setUseWorker(!1),h.setValue(e.value,-1),h.session.setUseWrapMode(!0),h.setOptions({showPrintMargin:!1,tabSize:4,useSoftTabs:!0,autoScrollEditorIntoView:!0,minLines:f?1:n,maxLines:f?1:o}),f&&(a.textContent="URL"),h.commands.addCommand({name:"disableEnterInUrl",bindKey:{win:"Enter|Shift-Enter",mac:"Enter|Shift-Enter"},exec:function(e){return"URL"===a.textContent},multiSelectAction:"forEach",readOnly:!1}),h.on("paste",function(e){"URL"===a.textContent&&e.text&&(e.text=e.text.replace(/[\r\n]+/g," ").trim())}),h.session.on("change",()=>{let t=h.getValue();"URL"===a.textContent&&/[\r\n]/.test(t)&&(t=t.replace(/[\r\n]+/g,"").trim(),h.setValue(t,1)),e.value=t}),e.form&&e.form.addEventListener("submit",()=>{e.value=h.getValue()}),u.addEventListener("click",e=>{e.preventDefault();const t=i.classList.toggle("ace-fullscreen");if(u.classList.toggle("active",t),u.innerHTML=t?'':'',t)h.setOption("maxLines",null);else{const e="URL"===a.textContent;h.setOption("maxLines",e?1:o)}h.resize()}),d.addEventListener("click",e=>{e.preventDefault();const t=h.session.getUseWrapMode();h.session.setUseWrapMode(!t),d.classList.toggle("active",!t)}),e.form||e.id){const t=e.form||document;e.id?e.id:e.name&&e.name;let i=[];e.id&&(i=Array.from(t.querySelectorAll(`[data-ace-target="#${e.id}"]`))),e.name&&!i.length&&(i=Array.from(t.querySelectorAll(`[data-ace-target="${e.name}"], [data-ace-target="[name='${e.name}']"]`)));const s=e=>{let t=(e||"text").toLowerCase().trim();const i="url"===t||"redirect"===t;if(t="markdown"===t?"markdown":"textile"===t?"textile":"html"===t||"2"===t||"wysiwyg"===t?"html":"php"===t?"php":"javascript"===t||"js"===t?"javascript":"css"===t?"css":"json"===t?"json":"text",h.session.setMode("ace/mode/"+t),h.session.setUseWorker(!1),i){a.textContent="URL";let e=h.getValue();/[\r\n]/.test(e)&&h.setValue(e.replace(/[\r\n]+/g," ").trim(),-1),h.setOptions({minLines:1,maxLines:1})}else a.textContent=t.toUpperCase(),h.setOptions({minLines:n,maxLines:o});h.resize()};if(i.length)i.forEach(e=>{e.addEventListener("change",()=>{if("radio"===e.type||"checkbox"===e.type){if(e.checked){const t=e.dataset.aceMode||e.value;s(t)}}else if("SELECT"===e.tagName){const t=e.options[e.selectedIndex],n=t&&t.dataset.aceMode||e.value;s(n)}})});else if(e.form){const t=e.form.querySelectorAll('input[name="ctext_format"], input[name="cnt_textformat"], input[name$="_format"], input[name$="_textformat"]');t.length&&t.forEach(e=>{e.addEventListener("change",()=>{e.checked&&s(e.value)})})}}if(window.phpwcmsAceEditors.push(h),e._aceEditor=h,e._aceWrap=i,window.ResizeObserver){let e=0,t=0;const n=new ResizeObserver(n=>{for(const o of n){const{width:n,height:i}=o.contentRect;n>0&&i>0&&(n!==e||i!==t)&&(e=n,t=i,h.resize())}});n.observe(i),i._aceResizeObserver=n}return h}function initPhpwcmsCodeEditors(){"undefined"!=typeof ace&&(document.querySelectorAll("textarea.code-editor, textarea[data-ace]").forEach(e=>{initAceForTextarea(e)}),window._phpwcmsAceTabListenersBound||(window._phpwcmsAceTabListenersBound=!0,["shown.bs.tab","shown.bs.collapse","shown.bs.modal"].forEach(e=>{document.addEventListener(e,()=>{window.phpwcmsAceEditors?.forEach(e=>e.resize())})})))}function initSidebarToggle(){const e=document.getElementById("sidebar-toggle");e&&e.addEventListener("click",e=>{e.preventDefault();const t=document.documentElement.classList.toggle("sidebar-collapsed");try{localStorage.setItem("phpwcms_sidebar_collapsed",t?"true":"false")}catch(e){}setTimeout(()=>{window.dispatchEvent(new Event("resize")),window.phpwcmsAceEditors?.forEach(e=>e.resize())},220)})}function initScrollAnchor(){if(window.location.hash)try{const e=window.location.hash.substring(1);if(!e)return;const t=document.getElementById(e)||(window.location.hash?document.querySelector(window.location.hash):null);t&&setTimeout(()=>{t.scrollIntoView({behavior:"smooth",block:"nearest"})},80)}catch(e){try{const e=window.location.hash.substring(1),t=document.getElementById(e);t&&setTimeout(()=>{t.scrollIntoView({behavior:"smooth",block:"nearest"})},80)}catch(e){}}}function initAutoOpenModals(){"undefined"!=typeof bootstrap&&document.querySelectorAll('[data-auto-open="1"]').forEach(function(e){bootstrap.Modal.getOrCreateInstance(e).show()})}window.phpwcmsAceEditors=window.phpwcmsAceEditors||[],"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{initPhpwcmsTheme(),initPhpwcmsCodeEditors(),initSidebarToggle(),initScrollAnchor(),initPasswordToggle()}):(initPhpwcmsTheme(),initPhpwcmsCodeEditors(),initSidebarToggle(),initScrollAnchor(),initPasswordToggle()),window.addEventListener("load",()=>{initScrollAnchor()})),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",initAutoOpenModals):initAutoOpenModals();