File: /var/www/html/wptoho/wp-content/themes/themify-ultra/themify/js/admin/import/import-images.js
let TF_ImportImages;((t,e,i,o,a,r,n,l)=>{"use strict";const s=new a,f=()=>t.loadJs(t.url+"js/admin/notification",!!i.TF_Notification);TF_ImportImages={init(r,n,l,c=2,p="themify_upload_image"){return new o((async m=>{const w=this;f(),wp?.heartbeat?.interval(120);const u=(r=w.t(r)).length,{download_fail:d="",upload_fail:g="",stop_webp:h="",custom_data:y=""}=l,_=l.download_images?.replaceAll("%to%",u)||"",b=l.upload_images?.replaceAll("%to%",u)||"",{first:v,second:T,duplicates:F}=w.i(r,c),I=[],N=t.createElement;w.action=p,w.nonce=n,w.custom_data=y,w.stop_webp=!!h;let j=N("div","msg_text"),D=N("div","img_wrap"),U=0,x=0,L=!0,R=[],z=()=>{L="visible"===i.document.visibilityState},A=t=>(t.preventDefault(),t.returnValue="Are you sure");i.tfOn("beforeunload",A).document.tfOn("visibilitychange",z,{passive:!0});for(let t=[v,T,F],i=0;i<t.length;++i)I[i]=new o((async r=>{let n=new a,l=[],s=t[i];for(let t=0;t<s.length;++t){let i=s[t],r=i.length,c=[],p=[f()],m=e.createDocumentFragment(),u=await o.allSettled(w.o(i));for(let t=l.length-1;t>-1;--t)URL.revokeObjectURL(l[t]);l=[];for(let t=0;t<u.length;++t){let e=i[t].url,o=u[t].value;if(o){let t=o,i=new Image(50,50);if(1===t)t=e;else if("string"!=typeof t)try{t=URL.createObjectURL(t),l.push(t),R.push(t)}catch(t){}i.className="tf_box",i.decoding="async",i.src=t;let a=i.decode();a.catch((()=>{})).finally((()=>{m.appendChild(i)})),c.push(o),p.push(a)}else n.set(e,"404"),i[t]="404"}if(i=i.filter((t=>"404"!==t)),w.l(i[t+1]),await o.allSettled(p),D.replaceChildren(m),U+=r,x+=r,j.replaceChildren(_.replaceAll("%from%",U)),!j.isConnected&&L){let t=e.createDocumentFragment();t.append(j,D),await TF_Notification.show("info",t)}let d=w.p(i,c);try{j.replaceChildren(b.replaceAll("%from%",x));let t=await w.upload(d);n=new a([...n,...t])}catch(t){L&&await TF_Notification.show("error",t.message||t.statusText,1500)}}l=s=null,r(n)}));const O=await o.all(I),S=[],k=new a;i.tfOff("beforeunload",A).document.tfOff("visibilitychange",z,{passive:!0}),s.clear();for(let t=R.length-1;t>-1;--t)URL.revokeObjectURL(R[t]);for(let t=O.length-1;t>-1;--t)for(let[e,i]of O[t])"string"==typeof i&&(i="404"===i?d.replaceAll("%post%",e):g.replaceAll("%post%",e).replaceAll("%msg%",i),S.push(e+": "+i),i=!1),k.set(e,i);if(!0===L&&S.length>0){const t=S.length;await TF_Notification.showHide("error",S.join("<br/> "),t>10?4e3:t>5?3e3:2500)}D.remove(),j.remove(),A=z=D=j=R=L=null,m(k)}))},o(e){const i=t.includesURL+"images/media/",o=[],a=["jpg","jpeg","webp","apng","png","gif","bmp","svg","svgz","mp4","mpeg","mp3","tiff"];for(let t=0;t<e.length;++t){let r,n=e[t].url;if(n.type||"string"==typeof n)if("string"==typeof n){let t=n.split("?")[0].split(".");if(r=t[t.length-1],!a.includes(r))continue;r="mp4"===r||"mpeg"===r?"video":"mp3"===r?"audio":"image"}else r=n.type.split("/")[0];"image"!==r?("video"!==r&&"audio"!==r&&(r="document"),n=i+r+".png",o.push(n)):o.push(this.download(n))}return o},t(t){Array.isArray(t)||(t=[...t]);const e=[];for(let i=0;i<t.length;++i){let o=t[i],a="string"==typeof o;if(a||o.url){let t=(o.url||o).trim();e.push({...a?{}:o,url:t.replace("/themes/ultra-agency-2/files/","/themes/ultra-agency2/files/")})}}return e},i(t,e){let i=new a,o=new Set,r=[],n=[],s=t=>{const i=[];while(t.length>0)i.push(t.splice(0,e));return i};for(let e=t.length-1;e>-1;--e){let a=t[e].url;if(a){let t=i.get(a);t!==l?(o.add(e),o.add(t)):i.set(a,e)}}for(let e of o)n.push({...t[e]}),t[e]=null;for(let e=t.length-1;e>-1;--e)null===t[e]&&t.splice(e,1);return r=t.length>1?t.splice(~~(t.length/2)):[],{first:s(t),second:s(r),duplicates:s(n)}},p(t,e){const i=new FormData,o={};for(let a=e.length-1;a>-1;--a)if(t[a]!==l){let r=t[a];i.set(a,e[a]),o[a]={thumb:r.name??r.url??r},"string"!=typeof r&&(r.id&&(o[a].post_id=r.id),r.term_id&&(o[a].term_id=r.term_id),r.data&&(o[a].data=r.data))}return i.set("action",this.action),i.set("nonce",this.nonce),i.set("postData",n.stringify(o)),this.custom_data&&i.set("save_id",this.custom_data),this.stop_webp&&i.set("stop_webp",1),i},async upload(e){let i=n.parse(e.get("postData")),l=new a,s=t=>{for(let o in i){let a=i[o].thumb;t[a]&&(t[a].id&&(e.delete(o),delete i[o]),l.set(a,t[a]))}},f=a=>new o((async(l,c)=>{let p=!1,m=150;try{let o=await t.fetch(e);p=o.success,p&&(s(o.data),r.keys(i).length>0&&(e.set("postData",n.stringify(i)),p=!1))}catch(t){if(!0===a)return void c(t);500===t.status&&(m=2e3)}if(!p&&!0!==a)try{if(await new o(((t,e)=>{setTimeout((()=>{f(!0).then(t).catch(e)}),m)})),r.keys(i).length>0)throw""}catch(t){for(let t in i)e.has(t)&&e.set(t,1);try{await f(!0)}catch(t){return void c(t)}}l()}));try{await f()}catch(t){throw t}finally{i=f=s=null}return l},l(t){if(t)for(let e=t.length-1;e>-1;--e)t[e].url&&this.download(t[e].url)},async download(e,i=!1){if("string"!=typeof e)return e;let a=s.get(e);if(a===l){if(e.includes("themify.me")||e.includes("themify.org"))try{a=await t.fetch("","blob",{credentials:"omit",method:"GET",mode:"cors",priority:"high"},e+"?polish=0")}catch(t){let r=t;if(!1===i)try{a=await new o(((t,i)=>{setTimeout((()=>{this.download(e,!0).then(t).catch(i)}),1e3)}))}catch(t){r=t}a=404!==r.status&&1}else a=1;s.set(e,a)}return a}}})(Themify,document,window.top,Promise,Map,Object,JSON,void 0);