HEX
Server: LiteSpeed
System: Linux s166.bitcommand.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: h340499 (1922)
PHP: 8.2.16
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/h340499/public_html/wp-content/plugins/learnpress/assets/js/admin/generate-with-openai.min.js
import*as lpUtils from"./../utils.js";import SweetAlert from"sweetalert2";import*as lpToastify from"lpAssetsJsPath/lpToastify.js";let lp_structure_course,popupSweetAlert=null,lp_is_generating_course_data=!1;const lp_course_ai_setting=JSON.parse(localStorage.getItem("lp_course_ai_setting"))||{};let selectGutenberg,dispatchGutenberg,editorGutenberg,isLayoutGutenberg=!1;export class GenerateWithOpenai{constructor(){this.init()}static selectors={elBtnGenerateWithAi:".lp-btn-generate-with-ai",elGenerateDataAiWrap:".lp-generate-data-ai-wrap"};init(){lpData?.enable_open_ai&&(lpUtils.lpOnElementReady("#titlewrap",t=>{t.insertAdjacentHTML("afterend",`<button type="button"\n\t\t\t\t\tclass="lp-btn-generate-with-ai lp-btn-ai-style"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-title-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t</button>`)}),lpUtils.lpOnElementReady("#wp-content-media-buttons",t=>{t.insertAdjacentHTML("beforeend",`<button type="button"\n\t\t\t\t\tclass="lp-btn-generate-with-ai lp-btn-ai-style"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-description-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t</button>`)}),lpUtils.lpOnElementReady("#postimagediv",t=>{t.querySelector(".postbox-header").insertAdjacentHTML("afterend",`<button type="button"\n\t\t\t\t\tstyle="margin: 12px 12px 0 12px;"\n\t\t\t\t\tclass="lp-btn-generate-with-ai lp-btn-ai-style"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-image-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t</button>`)}),wp.data&&wp.data.select("core/editor")&&(isLayoutGutenberg=!0,selectGutenberg=wp.data.select,dispatchGutenberg=wp.data.dispatch,editorGutenberg=selectGutenberg("core/editor"),lpUtils.lpOnElementReady(".editor-document-bar",t=>{t.insertAdjacentHTML("afterend",`<button type="button"\n\t\t\t\t\tstyle="margin-left: 5px"\n\t\t\t\t\tclass="lp-btn-generate-with-ai"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-title-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t</button>`)}),lpUtils.lpOnElementReady(".editor-post-featured-image",t=>{t.insertAdjacentHTML("beforebegin",'<button type="button"\n\t\t\t\t\tstyle="padding: 5px 10px; justify-content: center;"\n\t\t\t\t\tclass="lp-btn-generate-with-ai"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-description-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>Generate description with AI</span>\n\t\t\t\t</button>')}),lpUtils.lpOnElementReady(".editor-post-featured-image",t=>{t.insertAdjacentHTML("afterend",`<button type="button"\n\t\t\t\t\tstyle="padding: 5px 10px; justify-content: center;"\n\t\t\t\t\tclass="lp-btn-generate-with-ai"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-image-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t</button>`)})),this.events())}events(){lpUtils.eventHandlers("click",[{selector:GenerateWithOpenai.selectors.elBtnGenerateWithAi,class:this,callBack:this.showPopup.name},{selector:".lp-btn-step",class:this,callBack:this.showStep.name},{selector:".lp-btn-generate-prompt",class:this,callBack:this.generatePrompt.name},{selector:".lp-btn-call-open-ai",class:this,callBack:this.generateData.name},{selector:".lp-btn-copy",class:this,callBack:this.copyGeneratedData.name},{selector:".lp-btn-apply",class:this,callBack:this.applyGeneratedData.name},{selector:".lp-btn-ai-apply-image",class:this,callBack:this.applyImageData.name},{selector:".lp-btn-close-ai-popup",callBack:t=>{const{e:e,target:a}=t,s=lpData.i18n.confirm_close_ai;lp_is_generating_course_data?confirm(s)&&SweetAlert.close():SweetAlert.close()}}])}showPopup(t){const{e:e,target:a}=t,s=a.dataset.template||a.closest(".lp-btn-generate-with-ai").dataset.template||a.closest(".lp-generate-data-ai-wrap").dataset.template||"",l=document.querySelector(s);l?SweetAlert.fire({html:l.innerHTML,width:"60%",showCloseButton:!1,showConfirmButton:!1,allowOutsideClick:!1,allowEscapeKey:!1,didOpen:()=>{popupSweetAlert=SweetAlert.getPopup(),popupSweetAlert.click();const t=document.querySelector("input[name=post_title]");let e="";if(t)e=t.value;else if(isLayoutGutenberg){const t=document.querySelector(".editor-post-card-panel__title-name");t&&(e=t.textContent)}let a="";if(isLayoutGutenberg){a=editorGutenberg.getEditedPostContent().replace(/(<([^>]+)>)/gi,"")}else a=window.tinymce&&window.tinymce.get("content")?window.tinymce.get("content").getContent({format:"text"}):document.querySelector("#content").value;const s=popupSweetAlert.querySelector("form"),l=s.querySelector("[name=post-title]");if(l&&(l.value=e,!e)){const t=l.closest(".form-group").querySelector(".lp-ai-warning-refer");t&&lpUtils.lpShowHideEl(t,1)}const n=s.querySelector("[name=post-content]");if(n&&(n.value=a,a.length<2)){const t=n.closest(".form-group").querySelector(".lp-ai-warning-refer");t&&lpUtils.lpShowHideEl(t,1)}const o=popupSweetAlert.querySelector('select[name="target_audience"]');o&&(lp_course_ai_setting?.target_audience&&o.tomselect.setValue(lp_course_ai_setting.target_audience),o.addEventListener("change",t=>{lp_course_ai_setting.target_audience=o.tomselect.getValue(),localStorage.setItem("lp_course_ai_setting",JSON.stringify(lp_course_ai_setting))}));const i=popupSweetAlert.querySelector('select[name="tone"]');i&&(lp_course_ai_setting?.tone&&i.tomselect.setValue(lp_course_ai_setting.tone),i.addEventListener("change",t=>{lp_course_ai_setting.tone=i.tomselect.getValue(),localStorage.setItem("lp_course_ai_setting",JSON.stringify(lp_course_ai_setting))}));const r=popupSweetAlert.querySelector('select[name="language"]');r&&(lp_course_ai_setting?.language&&r.tomselect.setValue(lp_course_ai_setting.language),r.addEventListener("change",t=>{const e=r.tomselect.getValue();lp_course_ai_setting.language=e?[e]:[],localStorage.setItem("lp_course_ai_setting",JSON.stringify(lp_course_ai_setting))}))}}).then(t=>{t.isDismissed&&lp_is_generating_course_data&&(lp_is_generating_course_data=!1)}):console.error(`Template ${s} not found!`)}showStep(t){const{e:e,target:a}=t;e.preventDefault();const s=a.closest(".button-actions"),l=s.closest(GenerateWithOpenai.selectors.elGenerateDataAiWrap);let n=parseInt(s.dataset.step);const o=a.dataset.action;"next"===o?n++:"prev"===o&&n--,s.dataset.step=n;const i=a.closest("form"),r=i.querySelector(`.step-content[data-step="${n}"]`),p=l.querySelector(`.step-item[data-step="${n}"]`);i.querySelectorAll(".step-content").forEach(t=>t.classList.remove("active")),r.classList.add("active"),l.querySelectorAll(".step-item").forEach(t=>t.classList.remove("active")),p.classList.add("active");a.closest("form").querySelectorAll("button[data-step-show]").forEach(t=>{t.dataset.stepShow.split(",").map(t=>parseInt(t.trim())).includes(n)?lpUtils.lpShowHideEl(t,1):lpUtils.lpShowHideEl(t,0)})}generatePrompt(t){const{e:e,target:a}=t;e.preventDefault(),lpUtils.lpSetLoadingEl(a,!0);const s=a.closest("form");let l=JSON.parse(a.dataset.send);l=lpUtils.mergeDataWithDatForm(s,l);const n={success:t=>{const{message:e,status:a,data:l}=t;if(lpToastify.show(e,a),"success"===a){s.querySelector("textarea[name=lp-openai-prompt-generated-field]").value=l;s.querySelector(".lp-btn-step[data-action=next]").click()}},error:t=>{lpToastify.show(t,"error")},completed:()=>{lpUtils.lpSetLoadingEl(a,!1)}};window.lpAJAXG.fetchAJAX(l,n)}generateData(t){const{e:e,target:a}=t;e.preventDefault(),lpUtils.lpSetLoadingEl(a,!0);const s=a.closest("form");let l=JSON.parse(a.dataset.send);l=lpUtils.mergeDataWithDatForm(s,l);const n=s.querySelector(".lp-btn-step[data-action=prev]");lpUtils.lpShowHideEl(n,0);const o={success:t=>{const{message:e,status:a,data:l}=t;if(lp_is_generating_course_data&&lpToastify.show(e,a),"success"===a){lp_structure_course=l.lp_structure_course;s.querySelector(".lp-ai-generated-results").innerHTML=l.lp_html_preview;s.querySelector(".lp-btn-step[data-action=next]").click()}},error:t=>{lpToastify.show(t,"error")},completed:()=>{lpUtils.lpSetLoadingEl(a,!1),lpUtils.lpShowHideEl(n,1),lp_is_generating_course_data=!1}};lp_is_generating_course_data=!0,window.lpAJAXG.fetchAJAX(l,o)}applyGeneratedData(t){const{e:e,target:a}=t;e.preventDefault();const s=a.dataset.apply,l=a.dataset.target;if(l)if(isLayoutGutenberg)"set-wp-editor-content"===l?dispatchGutenberg("core/editor").editPost({content:s}):"set-wp-title"===l&&dispatchGutenberg("core/editor").editPost({title:s});else if("set-wp-editor-content"===l)this.setWPEditorContent(s);else if("set-wp-title"===l){const t=document.querySelector("input[name=post_title]");t&&(t.value=s)}popupSweetAlert&&SweetAlert.close()}copyGeneratedData(t){const{e:e,target:a}=t;e.preventDefault();const s=a.dataset.copy;if(navigator.clipboard)navigator.clipboard.writeText(s).then(()=>{lpToastify.show("Copied to clipboard!","success")}).catch(t=>{lpToastify.show("Failed to copy text: "+t,"error")});else{const t=document.createElement("textarea");t.value=s,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select();try{const t=document.execCommand("copy");lpToastify.show(t?"Copied to clipboard!":"Failed to copy text",t?"success":"error")}catch(t){lpToastify.show("Failed to copy text: "+t,"error")}document.body.removeChild(t)}}setWPEditorContent(t){window.tinymce.get("content").setContent(t)}applyImageData(t){const{e:e,target:a}=t;let s=JSON.parse(a.dataset.send);s=lpUtils.mergeDataWithDatForm(a.closest("form"),s),lpUtils.lpSetLoadingEl(a,!0);const l={success:t=>{const{message:e,status:a,data:s}=t;if(lpToastify.show(e,a),"success"===a){if(isLayoutGutenberg)dispatchGutenberg("core/editor").editPost({featured_media:s.attachment_id});else{document.querySelector("#postimagediv .inside").outerHTML=s.html_image}popupSweetAlert&&SweetAlert.close()}},error:t=>{lpToastify.show(t,"error")},completed:()=>{lpUtils.lpSetLoadingEl(a,!1)}};window.lpAJAXG.fetchAJAX(s,l)}}