1var gwp_purl=location,_gwp_blink_refresh_timer=null,_gwp_gdrive_tokens={};function gwp_schedule_blink_refresh(){_gwp_blink_refresh_timer&&clearTimeout(_gwp_blink_refresh_timer),_gwp_blink_refresh_timer=setTimeout(gwp_refresh_blink_buttons,500)}function gwp_refresh_blink_buttons(){var e=document.querySelectorAll(".gwp_blink");e.forEach(function(n){var t=n.getAttribute("gwp_fid");if(t){var s=n.getAttribute("gwp_type")||"gdrive",r=document.getElementById("gwp_sfbutton"+t);r&&(s==="ddrive"?r.setAttribute("onclick","gwp_selectditem(`"+t+"`, 'unlink');"):r.setAttribute("onclick","gwp_selectgitem(`"+t+"`, 'unlink');"),r.innerHTML='<i class="las la-sync"></i> Unlink item from bucket')}})}function gwp_rgdtoken(e,n,t){if(n.includes("u")==!0)var s=n.replace("u",""),r="user";else var s=n.replace("o",""),r="org";if(t!=null)var l=t.bslug;else var l="";e!=null&&(gwp_rgdfunc=e);var i=new XMLHttpRequest;i.onreadystatechange=function(){if(this.readyState==4&&this.status==200){var a=this.responseText;a.replace("new","");var o=JSON.parse(a);gwp_authstatus=o.gwp_authstatus,gwp_gatoken=o.access_token,_gwp_gdrive_tokens[n]=gwp_gatoken,_gwp_gdrive_tokens[s]=gwp_gatoken,r==="user"?_gwp_gdrive_tokens["u"+s]=gwp_gatoken:_gwp_gdrive_tokens["o"+s]=gwp_gatoken;for(var p=document.querySelectorAll('[gwp_gapi_id="'+l+n+'"], [gwp_gapi_id="'+n+'"], [gwp_gapi_id="o'+s+'"], [gwp_gapi_id="u'+s+'"], [gwp_tgapi_id="'+s+'"], [gwp_tgapi_id="'+n+'"], [gwp_tgapi_id="u'+s+'"]'),c=0;c<p.length;c++)p[c].setAttribute("gwp_gatoken",gwp_gatoken);if(gwp_gatoken=="Error please reauthorise!"){Swal.fire("Google drive error","Please speak to your website admin and reauthorise google drive");return}if(gwp_gatoken=="")return;if(window[gwp_rgdfunc]("root",n,t),gwp_authstatus!="authorised"){gwp_loadingpopup("stop");return}gwp_loadingpopup("stop")}},i.open("POST",gwp_pluginurl+"data/getgtoken.php",!0),i.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),i.send("gwp_wpid="+gwp_wpid+"&gwp_apikey="+gwp_apikey+"&gwp_gid="+s+"&gwp_call="+r+"&gwp_uid="+gwp_cuserid)}function gwp_togglebstab(e){var n=document.getElementById(e);if(n){var t=n.parentNode;if(t)for(var s=t.getElementsByClassName("gwp_bcstorageo"),r=0;r<s.length;r++)s[r].style.display="none";n.style.display="block";for(var l=document.getElementsByClassName("gwp_sbcstab"),i=0;i<l.length;i++){var a=l[i].innerHTML.replace(' <i class="las la-angle-right"></i>',"");l[i].innerHTML=a,l[i].setAttribute("class","gwp_bcstab")}var o=document.getElementById("gwp_bcstab_"+e)||document.getElementById("gwp_bcstab_gwp_bcstabs_"+e.replace("gwp_bcstorage_",""))||document.getElementById("gwp_bcstab_gwp_alb_bcstabs_"+e.replace("gwp_alb_bcstorage_",""));if(!o){for(var p=document.querySelectorAll(".gwp_bcstab"),c=0;c<p.length;c++)if(p[c].getAttribute("onclick")&&p[c].getAttribute("onclick").indexOf(e)!==-1){o=p[c];break}}if(o){o.setAttribute("class","gwp_sbcstab");var a=o.innerHTML+' <i class="las la-angle-right"></i>';o.innerHTML=a}}}function gwp_gdrefresh(e,n){e=e||"gwp_bcstabs",n=n||"gwp_bcstorage";var t=new XMLHttpRequest;t.onreadystatechange=function(){if(this.readyState==4&&this.status==200){var s=this.responseText;s.replace("new","");for(var r=JSON.parse(s),l=r.gwp_goauth,i=0;i<l.length;i++){var a=l[i].gwp_gaid,o=l[i].gwp_gatitle,p=l[i].gwp_gatoken;_gwp_gdrive_tokens[a]=p,_gwp_gdrive_tokens["o"+a]=p;var c=document.getElementById(e);if(c&&!document.getElementById("gwp_bcstab_"+e+"_gdrive"+a)){var w=document.createElement("div");w.setAttribute("id","gwp_bcstab_"+e+"_gdrive"+a),w.setAttribute("class","gwp_bcstab"),w.setAttribute("gwp_tgapi_id",a),w.setAttribute("gwp_gatoken",p),w.setAttribute("onclick","gwp_togglebstab(`"+n+"_gdrive"+a+"`);"),w.innerHTML='<i class="lab la-google-drive"></i> '+o+"</i>",c.append(w);var _=document.getElementById(n);if(_){var u=document.createElement("div");u.setAttribute("id",n+"_gdrive"+a),u.setAttribute("class","gwp_bcstorageo"),u.setAttribute("style","display: none;");var f=Math.max(0,_.childNodes.length-2);_.insertBefore(u,_.childNodes[f]);var v=document.createElement("div");v.setAttribute("style","display:flex;gap:5px;margin-bottom:5px;border-bottom:1px solid #e5e7eb;padding-bottom:5px;"),v.innerHTML=`<button type="button" onclick="gwp_sdnav_my('`+a+`');" style="padding:2px 9px;font-size:11px;border-radius:3px;background:#f3f4f6;border:1px solid #d1d5db;cursor:pointer;"><i class="lab la-google-drive"></i> My Drive</button><button type="button" onclick="gwp_sdnav_shared('`+a+`');" style="padding:2px 9px;font-size:11px;border-radius:3px;background:#fff;border:1px solid #d1d5db;cursor:pointer;"><i class="las la-hdd"></i> Shared Drives</button>`,u.appendChild(v);var w=document.createElement("div");w.setAttribute("gwp_gapi_id",a),w.setAttribute("gwp_call","org"),w.setAttribute("gwp_uid","org"),w.setAttribute("gwp_gatoken",p),u.appendChild(w);var m=document.createElement("div");m.setAttribute("id","gwp_sdlist_"+a),m.setAttribute("style","display:none;"),u.appendChild(m),gwp_gdrefreshroot("root",a)}}}gwp_loadingpopup("stop")}},t.open("POST",gwp_pluginurl+"data/getgapis.php",!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.send("gwp_wpid="+gwp_wpid+"&gwp_apikey="+gwp_apikey)}
1function gwp_gdurefresh(e,n){e=e||"gwp_bcstabs",n=n||"gwp_bcstorage";var t=new XMLHttpRequest;t.onreadystatechange=function(){if(this.readyState==4&&this.status==200){var s=this.responseText;s.replace("new","");var r=JSON.parse(s),l=r.gwp_goauth;if(l==null)return;for(var i=0;i<l.length;i++){var a=l[i].gwp_gaid,o=l[i].gwp_gatitle,p=l[i].gwp_gatoken;_gwp_gdrive_tokens[a]=p,_gwp_gdrive_tokens["u"+a]=p;var c=document.getElementById(e);if(c&&!document.getElementById("gwp_bcstab_"+e+"_gdriveu"+a)){var u=document.createElement("div");u.setAttribute("id","gwp_bcstab_"+e+"_gdriveu"+a),u.setAttribute("class","gwp_bcstab"),u.setAttribute("gwp_tgapi_id","u"+a),u.setAttribute("gwp_gatoken",p),u.setAttribute("onclick","gwp_togglebstab(`"+n+"_gdriveu"+a+"`);"),u.innerHTML='<i class="lab la-google-drive"></i> '+o+"</i>",c.append(u);var _=document.getElementById(n);if(_){var u=document.createElement("div");u.setAttribute("id",n+"_gdriveu"+a),u.setAttribute("class","gwp_bcstorageo"),u.setAttribute("style","display: none;"),u.setAttribute("gwp_gapi_id","u"+a),u.setAttribute("gwp_call","user"),u.setAttribute("gwp_uid",gwp_cuserid),u.setAttribute("gwp_gatoken",p);var f=Math.max(0,_.childNodes.length-2);_.insertBefore(u,_.childNodes[f]),gwp_gdrefreshroot("root","u"+a)}}}gwp_loadingpopup("stop")}},t.open("POST",gwp_pluginurl+"data/getugapis.php",!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.send("gwp_wpid="+gwp_wpid+"&gwp_apikey="+gwp_apikey+"&gwp_userid="+gwp_cuserid)}function gwp_sdnav_my(e){var n=document.querySelectorAll('[gwp_gapi_id="'+e+'"]');n.length>0&&(n[0].style.display="");var t=document.getElementById("gwp_sdlist_"+e);t&&(t.style.display="none"),gwp_gdrefreshroot("root",e)}function gwp_sdnav_shared(e){var n=document.querySelectorAll('[gwp_gapi_id="'+e+'"]');n.length>0&&(n[0].style.display="none");var t=document.getElementById("gwp_sdlist_"+e);if(t){t.style.display="",t.innerHTML='<div style="padding:6px;font-size:12px;color:#6b7280;"><i class="las la-spinner la-spin"></i> Loading...</div>';var s=e.toString().indexOf("u")===0?e.replace("u",""):e,r=new XMLHttpRequest;r.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var l=JSON.parse(this.responseText),i=l.drives||[],a=l.drives_error;if(a){t.innerHTML='<div style="color:#dc2626;font-size:11px;padding:6px;">'+a+"</div>";return}if(i.length===0){t.innerHTML='<div style="color:#9ca3af;font-size:12px;padding:6px;">No shared drives found</div>';return}for(var o="",p=0;p<i.length;p++){var c=i[p];o+=`<div class="gwp_gitemline"><div class="gwp_gfolder" onclick="gwp_sdenter('`+e+"','"+c.id+`');" style="cursor:pointer;"><i class="las la-hdd" style="margin-right:4px;color:#4285f4;"></i>`+(c.name||c.id)+"</div></div>"}t.innerHTML=o}catch{t.innerHTML='<div style="color:#dc2626;font-size:11px;padding:6px;">Error loading</div>'}},r.open("POST",gwp_pluginurl+"data/gdrivelist.php",!0),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.send("gwp_wpid="+encodeURIComponent(gwp_wpid)+"&gwp_gaid="+encodeURIComponent(s)+"&gwp_list_drives=1")}}function gwp_sdenter(e,n){var t=document.querySelectorAll('[gwp_gapi_id="'+e+'"]');t.length>0&&(t[0].style.display="");var s=document.getElementById("gwp_sdlist_"+e);s&&(s.style.display="none"),gwp_gdrefreshroot(n,e,n)}var gwp_xstrike=0;function gwp_gdrefreshroot(e,n,t){var s=_gwp_gdrive_tokens[n]||null;if(!s){var r=document.querySelectorAll('[gwp_gapi_id="'+n+'"]');r.length>0&&(s=r[0].getAttribute("gwp_gatoken"))}if(!s){console.log("No token for gaid:",n);return}if(e==null)var e="root";t=t||"";var l="https://www.googleapis.com/drive/v3/files?q='"+e+"'+in+parents&fields=files(id,name,kind,parents,thumbnailLink,iconLink,webViewLink,fileExtension,mimeType,trashed)&supportsAllDrives=true&includeItemsFromAllDrives=true&access_token="+s;t&&(l+="&corpora=drive&driveId="+encodeURIComponent(t));var i=new XMLHttpRequest;i.open("GET",l),i.onreadystatechange=function(a){if(i.readyState===4&&i.status===200){var o=JSON.parse(i.response);gwp_refreshfolders(n,o,e,t)}else i.readyState===4&&i.status===401?(console.log("Invalid gdrive token"),gwp_rgdtoken("gwp_gdrefreshroot",n)):i.status===403&&(gwp_xstrike++,gwp_xstrike==3&&(gwp_rgdtoken("gwp_gdrefreshroot",n),gwp_xstrike=0))},i.send()}function gwp_getparent(e,n){var t=_gwp_gdrive_tokens[n]||null;if(!t){var s=document.querySelectorAll('[gwp_gapi_id="'+n+'"]');s.length>0&&(t=s[0].getAttribute("gwp_gatoken"))}if(t){if(e==null)var e="root";var r=new XMLHttpRequest;r.open("GET","https://www.googleapis.com/drive/v3/files/"+e+"?fields=parents&access_token="+t),r.onreadystatechange=function(l){if(r.readyState===4&&r.status===200){var i=JSON.parse(r.response),a=i.parents;gwp_gdrefreshroot(a,n)}else r.readyState===4&&r.status===401?(console.log("Invalid gdrive token"),gwp_rgdtoken("gwp_getparent",n)):r.status===403&&(gwp_xstrike++,gwp_xstrike==3&&(gwp_rgdtoken("gwp_getparent",n),gwp_xstrike=0))},r.send()}}var gwp_bcfirstload=!0;function gwp_refreshfolders(e,a,t,s){s=s||"",e.includes("u")==!0?sid=e:sid="o"+e;var r=document.querySelectorAll('[gwp_gapi_id="'+e+'"]'),l=r[0],i=l.getAttribute("gwp_root");l.innerHTML="";var a=a.files;a.reverse();var o=a[0].parents;if(t!="root"&&gwp_bcfirstload==!1&&i!=t){var p=document.createElement("div");p.setAttribute("id","gwp_gitemline"+u),p.setAttribute("class","gwp_gitemline"),l.appendChild(p);var c=document.createElement("div");c.setAttribute("class","gwp_gfreturn"),c.setAttribute("onclick","gwp_getparent('"+o+"', '"+e+"');"),c.innerHTML='<i class="las la-arrow-circle-left"></i>',p.appendChild(c)}for(var _=0;_<a.length;_++){var u=a[_].id,f=a[_].name,v=a[_].parents;gwp_bcfirstload==!0&&(l.setAttribute("gwp_root",v),gwp_bcfirstload=!1);var w=a[_].trashed;if(w!=!0){var m=a[_].webViewLink,d=a[_].thumbnailLink,d="https://drive.google.com/thumbnail?authuser=0&sz=w320&id="+u;if(d==null)var d="";var y=a[_].fileExtension;if(y==null)var y="";var g=a[_].mimeType;if(g.includes("folder")==!0)var b="folder",h="gwp_gfolder",k='<i class="las la-folder"></i>',A="gwp_gdrefreshroot('"+u+"', '"+e+"', '"+s+"');";else var b="file",h="gwp_gfile",k=gwp_ftypecheck(y,"icon"),A="window.open(`"+m+"`);";var p=document.createElement("div");p.setAttribute("id","gwp_gitemline"+u),p.setAttribute("class","gwp_gitemline"),l.appendChild(p);var x=l.getAttribute("gwp_uid"),c=document.createElement("div");c.setAttribute("id","gwp_gitem"+u),c.setAttribute("gwp_name",f),c.setAttribute("gwp_parent",v),c.setAttribute("gwp_fid",u),c.setAttribute("gwp_pid",v),c.setAttribute("gwp_sid",sid),c.setAttribute("gwp_uid",x),c.setAttribute("gwp_type","gdrive"),c.setAttribute("gwp_ftype",b),c.setAttribute("gwp_drive_id",s),c.setAttribute("gwp_wlink",m),c.setAttribute("gwp_thumb",d),c.setAttribute("class",h),c.setAttribute("onclick",A),c.innerHTML=k+" "+f,p.appendChild(c);var c=document.createElement("button");c.setAttribute("id","gwp_sfbutton"+u),c.setAttribute("class","gwp_gdsbutton");var T=document.getElementById("gwp_blink"+u);T==null?(c.setAttribute("onclick","gwp_selectgitem(`"+u+"`, 'link');"),c.innerHTML="Link item to bucket"):(c.setAttribute("onclick","gwp_selectgitem(`"+u+"`, 'unlink');"),c.innerHTML='<i class="las la-sync"></i> Unlink item from bucket'),p.appendChild(c),gwp_schedule_blink_refresh()}}}function gwp_blinkcheck(){var e=typeof _gwp_cs_blinkstatus_id<"u"?_gwp_cs_blinkstatus_id:"gwp_blinkstatus",n=typeof _gwp_cs_blinks_id<"u"?_gwp_cs_blinks_id:"gwp_blinks",t=document.getElementById(e),s=document.getElementById(n),r=s?s.getElementsByClassName("gwp_blink"):[];r.length==0?t&&(t.innerHTML="<i>No cloud storage folders linked</i>"):t&&(t.innerHTML="")}function gwp_selectgitem(e,n,t){if(window.bloading.gitem=!0,typeof t>"u"&&n=="link"){var s=document.getElementById("gwp_gitem"+e);if(s==null)var s=document.getElementById("gwp_ditem"+e);var r=s.getAttribute("gwp_name"),l=s.getAttribute("gwp_pid"),i=s.getAttribute("gwp_sid"),a=s.getAttribute("gwp_uid"),o=s.getAttribute("gwp_type"),p=s.getAttribute("gwp_ftype"),c=s.getAttribute("gwp_wlink"),_=s.getAttribute("gwp_thumb"),u=s.getAttribute("gwp_drive_id")||"",t={fi
1d:e,name:r,pid:l,sid:i,uid:a,type:o,ftype:p,wlink:c,thumb:_,drive_id:u},f=!0}else if(n=="link")var s=document.getElementById("gwp_gitem"+e),r=t.name,l=t.pid,i=t.sid,a=t.uid,p=t.ftype,c=t.wlink,_=t.thumb,o=t.type,u=t.drive_id||"",f=!1;else var f=!0;var v=document.getElementById("gwp_sfbutton"+e),w=document.getElementById(typeof _gwp_cs_blinks_id<"u"?_gwp_cs_blinks_id:"gwp_blinks");if(n=="link"){if(v!=null&&(v.innerHTML='<i class="las la-sync"></i> Unlink item from bucket',o=="ddrive"?v.setAttribute("onclick","gwp_selectditem(`"+e+"`, 'unlink');"):v.setAttribute("onclick","gwp_selectgitem(`"+e+"`, 'unlink');")),o=="ddrive")var m="gwp_selectditem";else var m="gwp_selectgitem";var d=document.createElement("div");d.setAttribute("id","gwp_blink"+e),d.setAttribute("class","gwp_blink"),d.setAttribute("gwp_fid",e),d.setAttribute("gwp_name",r),d.setAttribute("gwp_pid",l),d.setAttribute("gwp_sid",i),d.setAttribute("gwp_uid",a),d.setAttribute("gwp_type",o),d.setAttribute("gwp_ftype",p),d.setAttribute("gwp_drive_id",u||""),d.setAttribute("gwp_wlink",c),d.setAttribute("gwp_thumb",_);var y=o==="ddrive"?'<i class="lab la-dropbox" style="margin-right:4px;color:#0061ff;"></i>':'<i class="lab la-google-drive" style="margin-right:4px;color:#4285f4;"></i>';d.innerHTML=y+r+' <button type="button" class="gwp_bbutton" onclick="'+m+"(`"+e+'`, `unlink`);">x</button>',w.appendChild(d),gwp_cbucketitem(e,"link",t)}else{v!=null&&(v.innerHTML="Link item to bucket",o=="ddrive"?v.setAttribute("onclick","gwp_selectditem(`"+e+"`, 'link');"):v.setAttribute("onclick","gwp_selectgitem(`"+e+"`, 'link');"));var d=document.getElementById("gwp_blink"+e);d&&d.parentNode.removeChild(d),gwp_cbucketitem(e,"unlink",t)}gwp_blinkcheck(),window.bloading.gitem=!1;var g=!0;for(var b in window.bloading)if(window.bloading[b]==!0){var g=!1;break}g==!0&&(window.loadingbucket=!1,f==!0&&gwp_savebucket())}function gwp_cbucketitem(e,n,t){window.bloading.bitem=!0;var s=document.getElementById(typeof _gwp_cs_bcontents_id<"u"?_gwp_cs_bcontents_id:"gwp_bcontents");if(n=="link"){var r=t.name,l=t.ftype,i=t.type,a=r,o=t.fid,p=t.sid,c=t.uid,_="",u=t.wlink,f=t.thumb,v=document.getElementById("gwp_gbitem"+o);switch(i){case"gdrive":var w='<i class="lab la-google-drive"></i> Gdrive';break;case"ddrive":var w='<i class="lab la-dropbox"></i> Dropbox';break;default:var w="",m='<i class="las la-file-alt"></i>'}var d=document.createElement("div");if(d.setAttribute("id","gwp_gbitem"+o),d.setAttribute("class","gwp_mediaitem gwp_mediafilemargin"),d.setAttribute("gwp_mid",o),d.setAttribute("gwp_sid",p),d.setAttribute("gwp_uid",c),d.setAttribute("gwp_ftype",l),d.setAttribute("gwp_type","gdrive"),d.setAttribute("gwp_medianame",a),d.setAttribute("gwp_src",u),d.setAttribute("onClick","window.open('"+u+"');"),l=="folder"){var m='<i class="las la-folder"></i>';d.setAttribute("gwp_thumb",u),d.setAttribute("gwp_mediaurl",o);var y='gwp_medianame="'+a+'" gwp_type="'+i+'" gwp_ftype="'+l+'" gwp_src="'+u+'"';d.innerHTML='<div class="gwp_moverlay">'+w+'</div><div class="gwp_mediaboxvid" '+y+">"+_+m+'</div><div id="gwp_mediafilename'+o+'" class="gwp_mediafilename"><i id="filegwp_tick'+o+'" class="lar la-check-circle gwp_mediafileselect"></i>'+a+"</div>"}else if(l=="file"){var g=r.substring(r.lastIndexOf(".")+1),b=gwp_ftypecheck(g,"both"),h=b.type,m=b.icon;if(h.includes("image")==!0){d.setAttribute("gwp_thumb",f);var y='gwp_id="'+o+'"gwp_medianame="'+a+'" gwp_type="'+i+'" gwp_ftype="'+h+'" gwp_src="'+f+'"';d.innerHTML='<div class="gwp_moverlay">'+w+'</div><div class="gwp_mediaboximg" '+y+'><img class="gwp_mediaimage" src="'+f+'"/></div><div id="gwp_mediafilename'+o+'" class="gwp_mediafilename"><i id="gwp_tick'+o+'" class="lar la-check-circle gwp_mediafileselect"></i>'+a+"</div>"}else{d.setAttribute("gwp_thumb",u);var y='gwp_id="'+o+'"gwp_medianame="'+a+'" gwp_type="gdrive" gwp_ftype="'+h+'" gwp_src="'+u+'"';d.innerHTML='<div class="gwp_moverlay">'+w+'</div><div class="gwp_mediaboxvid" '+y+">"+_+m+'</div><div id="gwp_mediafilename'+o+'" class="gwp_mediafilename"><i id="filegwp_tick'+o+'" class="lar la-check-circle gwp_mediafileselect"></i>'+a+"</div>"}}s.appendChild(d)}else{var d=document.getElementById("gwp_gbitem"+e);d?.parentNode.removeChild(d)}window.bloading.bitem=!1;var k=!0;for(var A in window.bloading)if(window.bloading[A]==!0){var k=!1;break}k==!0&&(window.loadingbucket=!1)}var _gwp_cs_term_id=0,_gwp_cs_taxonomy="buckets",_gwp_cs_blinks_id="gwp_blinks",_gwp_cs_bcontents_id="gwp_bcontents",_gwp_cs_blinkstatus_id="gwp_blinkstatus",_gwp_cs_ajax=typeof gwp_pluginurl<"u"?gwp_pluginurl+"../../../wp-admin/admin-ajax.php":"/wp-admin/admin-ajax.php";function gwp_cs_load_config(e,n){_gwp_cs_term_id=e,_gwp_cs_taxonomy=n||"buckets";var t=new XMLHttpRequest;t.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var s=JSON.parse(this.responseText);if(!s.success)return;var r=s.data,l=document.getElementById("gwp_cs_enabled"),i=document.getElementById("gwp_cs_interval"),a=document.getElementById("gwp_cs_delete_sync"),o=document.getElementById("gwp_cs_last_sync");
1if(l&&(l.checked=!!r.enabled),i&&(i.value=r.interval||"hourly"),a&&(a.checked=r.delete_sync!==!1),o)if(r.last_sync>0){var p=new Date(r.last_sync*1e3);o.innerHTML="Last synced: "+p.toLocaleString()+(r.last_status?" \u2014 "+r.last_status:"")}else o.innerHTML="Never synced";_gwp_cs_render_linked_folders(r.folders||[],"gwp_blinks","gwp_blinkstatus")}catch(c){console.warn("cs_load_config error",c)}},t.open("POST",_gwp_cs_ajax,!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.send("action=gwp_cloud_sync_config&term_id="+e)}function _gwp_cs_render_linked_folders(e,n,t){var s=document.getElementById(n),r=document.getElementById(t);if(s){if(s.innerHTML="",!e||e.length===0){r&&(r.innerHTML="<i>No cloud storage folders linked</i>");return}r&&(r.innerHTML="");for(var l=0;l<e.length;l++){var i=e[l],a=i.type==="ddrive"?"gwp_selectditem":"gwp_selectgitem",o=document.createElement("div");o.setAttribute("id","gwp_blink"+i.fid),o.setAttribute("class","gwp_blink"),o.setAttribute("gwp_fid",i.fid),o.setAttribute("gwp_name",i.name||""),o.setAttribute("gwp_sid",i.sid||""),o.setAttribute("gwp_type",i.type||"gdrive"),o.setAttribute("gwp_ftype",i.ftype||"folder"),o.setAttribute("gwp_drive_id",i.drive_id||"");var p=i.type==="ddrive"?'<i class="lab la-dropbox" style="margin-right:4px;color:#0061ff;"></i>':'<i class="lab la-google-drive" style="margin-right:4px;color:#4285f4;"></i>';o.innerHTML=p+(i.name||i.fid)+' <button type="button" class="gwp_bbutton" onclick="'+a+"(`"+i.fid+'`, `unlink`);">x</button>',s.appendChild(o)}}}function gwp_cs_save_config(){if(_gwp_cs_term_id){for(var e=document.getElementById("gwp_cs_enabled"),n=document.getElementById("gwp_cs_interval"),t=document.getElementById("gwp_cs_delete_sync"),s=[],r=document.querySelectorAll("#gwp_blinks .gwp_blink"),l=0;l<r.length;l++){var i=r[l];s.push({fid:i.getAttribute("gwp_fid"),name:i.getAttribute("gwp_name"),sid:i.getAttribute("gwp_sid"),type:i.getAttribute("gwp_type")||"gdrive",ftype:i.getAttribute("gwp_ftype")||"folder",drive_id:i.getAttribute("gwp_drive_id")||""})}var a=new XMLHttpRequest;a.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var o=JSON.parse(this.responseText);if(o.success){var p=document.getElementById("gwp_cs_status");p&&(p.innerHTML='<i class="las la-check" style="color:#16a34a;"></i> Saved',setTimeout(function(){p.innerHTML=""},2e3))}}catch{}},a.open("POST",_gwp_cs_ajax,!0),a.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),a.send("action=gwp_cloud_sync_save&term_id="+_gwp_cs_term_id+"&enabled="+(e&&e.checked?"1":"0")+"&interval="+(n?n.value:"hourly")+"&delete_sync="+(t&&t.checked?"1":"0")+"&folders="+encodeURIComponent(JSON.stringify(s)))}}function gwp_cs_sync_now(){if(_gwp_cs_term_id){gwp_cs_save_config();var e=document.getElementById("gwp_cs_status");e&&(e.innerHTML='<i class="las la-spinner la-spin"></i> Syncing...');var n=new XMLHttpRequest;n.onreadystatechange=function(){this.readyState==4&&this.status==200&&setTimeout(function(){gwp_cs_poll_status()},2e3)},n.open("POST",_gwp_cs_ajax,!0),n.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),n.send("action=gwp_cloud_sync_start&term_id="+_gwp_cs_term_id+"&taxonomy="+_gwp_cs_taxonomy)}}function gwp_cs_open_dialog(e,n){var t=new XMLHttpRequest;t.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var s=JSON.parse(this.responseText);s.success&&s.data.term_id?_gwp_cs_show_dialog(s.data.term_id,e,n):Swal.fire({title:"Error",text:"Could not find "+n.slice(0,-1)+' "'+e+'"',icon:"error"})}catch(r){console.warn(r)}},t.open("POST",_gwp_cs_ajax,!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.send("action=gwp_cloud_sync_term_id&term_name="+encodeURIComponent(e)+"&taxonomy="+encodeURIComponent(n))}function _gwp_cs_show_dialog(e,n,t){_gwp_cs_term_id=e,_gwp_cs_taxonomy=t;var s=new XMLHttpRequest;s.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var r=JSON.parse(this.responseText),l=r.success?r.data:{},i="";if(l.last_sync>0){var a=new Date(l.last_sync*1e3);
1i="Last synced: "+a.toLocaleString()+(l.last_status?" \u2014 "+l.last_status:"")}Swal.fire({title:'<i class="las la-cloud-download-alt"></i> Cloud Sync \u2014 '+n,html:'<div style="text-align:left;"><div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;"><label style="font-size:13px;">Enable auto-sync</label><input type="checkbox" id="swal_cs_en" '+(l.enabled?"checked":"")+' style="width:18px;height:18px;" /></div><div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;"><label style="font-size:13px;">Sync interval</label><select id="swal_cs_int" class="swal2-select" style="width:auto;margin:0;"><option value="5min"'+(l.interval==="5min"?" selected":"")+'>Every 5 min</option><option value="15min"'+(l.interval==="15min"?" selected":"")+'>Every 15 min</option><option value="30min"'+(l.interval==="30min"?" selected":"")+'>Every 30 min</option><option value="hourly"'+(l.interval==="hourly"||!l.interval?" selected":"")+'>Hourly</option><option value="daily"'+(l.interval==="daily"?" selected":"")+'>Daily</option><option value="manual"'+(l.interval==="manual"?" selected":"")+'>Manual</option></select></div><div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;"><label style="font-size:13px;">Delete local when removed from cloud</label><input type="checkbox" id="swal_cs_del" '+(l.delete_sync!==!1?"checked":"")+' style="width:18px;height:18px;" /></div><div style="font-size:11px;color:#9ca3af;margin-top:8px;">'+i+'</div><p style="font-size:12px;color:#9ca3af;margin-top:8px;">Linked folders are managed from the bucket edit popup. This syncs files from those folders to your media library.</p></div>',showCancelButton:!0,confirmButtonText:'<i class="las la-sync"></i> Save & Sync Now',cancelButtonText:"Save",showDenyButton:!1}).then(function(o){if(o.isConfirmed||o.isDismissed){var p=document.getElementById("swal_cs_en"),c=document.getElementById("swal_cs_int"),_=document.getElementById("swal_cs_del"),u=new XMLHttpRequest;u.onreadystatechange=function(){if(this.readyState==4&&this.status==200&&o.isConfirmed){Swal.fire({title:"Syncing...",allowOutsideClick:!1,didOpen:function(){Swal.showLoading()}});var f=new XMLHttpRequest;f.onreadystatechange=function(){this.readyState==4&&this.status==200&&setTimeout(function(){var v=new XMLHttpRequest;v.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var w=JSON.parse(this.responseText);w.success&&Swal.fire({title:"Sync complete",text:w.data.last_status||"Done",icon:"success",timer:3e3,showConfirmButton:!1})}catch{}},v.open("POST",_gwp_cs_ajax,!0),v.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),v.send("action=gwp_cloud_sync_status&term_id="+e)},5e3)},f.open("POST",_gwp_cs_ajax,!0),f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.send("action=gwp_cloud_sync_start&term_id="+e+"&taxonomy="+t)}},u.open("POST",_gwp_cs_ajax,!0),u.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),u.send("action=gwp_cloud_sync_save&term_id="+e+"&enabled="+(p&&p.checked?"1":"0")+"&interval="+(c?c.value:"hourly")+"&delete_sync="+(_&&_.checked?"1":"0")+"&folders="+encodeURIComponent(JSON.stringify(l.folders||[])))}})}catch(o){console.warn(o)}},s.open("POST",_gwp_cs_ajax,!0),s.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),s.send("action=gwp_cloud_sync_config&term_id="+e)}var _gwp_cs_album_term_id=0;function gwp_cs_load_config_album(e){_gwp_cs_album_term_id=e;var n=new XMLHttpRequest;n.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var t=JSON.parse(this.responseText);if(!t.success)return;var s=t.data,r=document.getElementById("gwp_alb_cs_enabled"),l=document.getElementById("gwp_alb_cs_interval"),i=document.getElementById("gwp_alb_cs_delete_sync"),a=document.getElementById("gwp_alb_cs_last_sync");if(r&&(r.checked=!!s.enabled),l&&(l.value=s.interval||"hourly"),i&&(i.checked=s.delete_sync!==!1),a)if(s.last_sync>0){var o=new Date(s.last_sync*1e3);
1a.innerHTML="Last synced: "+o.toLocaleString()+(s.last_status?" \u2014 "+s.last_status:"")}else a.innerHTML="Never synced";_gwp_cs_render_linked_folders(s.folders||[],"gwp_alb_blinks","gwp_alb_blinkstatus")}catch(p){console.warn("cs_load_config_album error",p)}},n.open("POST",_gwp_cs_ajax,!0),n.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),n.send("action=gwp_cloud_sync_config&term_id="+e)}function gwp_cs_save_config_album(){if(_gwp_cs_album_term_id){for(var e=document.getElementById("gwp_alb_cs_enabled"),n=document.getElementById("gwp_alb_cs_interval"),t=document.getElementById("gwp_alb_cs_delete_sync"),s=[],r=document.querySelectorAll("#gwp_alb_blinks .gwp_blink"),l=0;l<r.length;l++){var i=r[l];s.push({fid:i.getAttribute("gwp_fid"),name:i.getAttribute("gwp_name"),sid:i.getAttribute("gwp_sid"),type:i.getAttribute("gwp_type")||"gdrive",ftype:i.getAttribute("gwp_ftype")||"folder",drive_id:i.getAttribute("gwp_drive_id")||""})}var a=new XMLHttpRequest;a.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var o=JSON.parse(this.responseText);if(o.success){var p=document.getElementById("gwp_alb_cs_status");p&&(p.innerHTML='<i class="las la-check" style="color:#16a34a;"></i> Saved',setTimeout(function(){p.innerHTML=""},2e3))}}catch{}},a.open("POST",_gwp_cs_ajax,!0),a.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),a.send("action=gwp_cloud_sync_save&term_id="+_gwp_cs_album_term_id+"&enabled="+(e&&e.checked?"1":"0")+"&interval="+(n?n.value:"hourly")+"&delete_sync="+(t&&t.checked?"1":"0")+"&folders="+encodeURIComponent(JSON.stringify(s)))}}function gwp_cs_sync_now_album(){if(_gwp_cs_album_term_id){gwp_cs_save_config_album();var e=document.getElementById("gwp_alb_cs_status");e&&(e.innerHTML='<i class="las la-spinner la-spin" style="color:#F83600;"></i> <strong>Syncing in progress...</strong>'),Swal.fire({title:"Syncing Album",html:'<div style="text-align:center;"><i class="las la-sync la-spin" style="font-size:40px;color:#F83600;display:block;margin-bottom:12px;"></i><p>Downloading images from cloud storage...</p><p style="font-size:12px;color:#8c8f94;">This runs in the background. You can close this dialog.</p></div>',showConfirmButton:!1,showCancelButton:!0,cancelButtonText:"Close",allowOutsideClick:!0});var n=_gwp_cs_album_term_id,t=new XMLHttpRequest;t.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var s=JSON.parse(this.responseText);s.success?gwp_cs_poll_album_sync(n,e):(e&&(e.innerHTML='<i class="las la-times-circle" style="color:#d63638;"></i> Sync failed: '+(s.data||"Unknown error")),Swal.fire("Sync Failed",s.data||"Unknown error","error"))}catch{e&&(e.innerHTML='<i class="las la-times-circle" style="color:#d63638;"></i> Sync error')}},t.open("POST",_gwp_cs_ajax,!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.send("action=gwp_cloud_sync_start&term_id="+n+"&taxonomy=albums")}}function gwp_cs_poll_album_sync(e,n){var t=0,s=12,r=function(){t++;var l=new XMLHttpRequest;l.onreadystatechange=function(){if(this.readyState==4&&this.status==200){try{var i=JSON.parse(this.responseText);if(i.success&&i.data){var a=document.getElementById("gwp_alb_cs_last_sync");if(i.data.last_sync>0){var o=new Date(i.data.last_sync*1e3);a&&(a.innerHTML="Last synced: "+o.toLocaleString());var p=i.data.last_status||"Sync complete";n&&(n.innerHTML='<i class="las la-check-circle" style="color:#16a34a;"></i> '+p),Swal.fire({icon:"success",title:"Sync Complete",text:p,timer:3e3,showConfirmButton:!1});return}}}catch{}t<s?setTimeout(r,5e3):(n&&(n.innerHTML='<i class="las la-clock" style="color:#dba617;"></i> Sync still running in background...'),Swal.close())}},l.open("POST",_gwp_cs_ajax,!0),l.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),l.send("action=gwp_cloud_sync_status&term_id="+e)};setTimeout(r,5e3)}var _gwp_cs_poll_count=0;function gwp_cs_poll_status(){_gwp_cs_poll_count++;var e=new XMLHttpRequest;e.onreadystatechange=function(){if(this.readyState==4&&this.status==200)try{var n=JSON.parse(this.responseText);if(!n.success)return;var t=n.data,s=document.getElementById("gwp_cs_status"),r=document.getElementById("gwp_cs_last_sync");if(t.last_status&&t.last_status==="Syncing...")s&&(s.innerHTML='<i class="las la-spinner la-spin"></i> Syncing...'),_gwp_cs_poll_count<60?setTimeout(function(){gwp_cs_poll_status()},3e3):s&&(s.innerHTML='<i class="las la-exclamation-circle" style="color:#f59e0b;"></i> Sync taking longer than expected. Check back later.');else{if(_gwp_cs_poll_count=0,t.last_sync>0){var l=new Date(t.last_sync*1e3);
1r&&(r.innerHTML="Last synced: "+l.toLocaleString()+(t.last_status?" \u2014 "+t.last_status:""))}s&&(s.innerHTML='<i class="las la-check-circle" style="color:#16a34a;"></i> '+(t.last_status||"Done"))}}catch{}},e.open("POST",_gwp_cs_ajax,!0),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.send("action=gwp_cloud_sync_status&term_id="+_gwp_cs_term_id)}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.