| 1 |
"use strict";(globalThis.webpackChunkextendify=globalThis.webpackChunkextendify||[]).push([[884],{5402(e,t,n){var i=n(8969);const{products:s=[]}=window.extSharedData,a=e=>e.isSearchPluginsLoading||e.isInstalledPluginsLoading,r=e=>e.isSearchPluginsError||e.isInstalledPluginsError,l=e=>{const t=new Map,{searchPlugins:n,installedPlugins:i,searchPluginsLimit:a}=e,r=i.filter(({status:e})=>"active"===e),l=n.slice(0,a);return s.filter(e=>e.slots.includes("plugin-search")).filter(e=>e.pluginSearchTriggerSlugs.some(n=>{const i=l.includes(n);return i&&t.set(e.slug,n),i})).filter(e=>"plugin"!==e.ctaType||!i.find(({slug:t})=>t===e.ctaPluginSlug)).filter(e=>e.pluginExclusions.every(e=>!r.find(({slug:t})=>t===e))).filter(e=>e.pluginDependencies.every(e=>i.find(({slug:t})=>t===e))).filter(Boolean).map(e=>({...e,title:e.pluginSearchCustomTitle||e.title,description:e.pluginSearchCustomDescription||e.description,ctaContent:e.pluginSearchCustomCtaContent||e.ctaContent,triggerContent:t.get(e.slug),triggerType:"plugin-slug"})).sort((e,t)=>l.indexOf(e.triggerContent)-l.indexOf(t.triggerContent))},o=e=>l(e).slice(0,e.recommendationsLimit),c=e=>{if(!e||!e.querySelectorAll)return[];const t=e.querySelectorAll(".plugin-card").values().map(e=>{const t=e.getAttribute("class"),n=t.match(/^plugin-card plugin-card-([\w-]*)$/)?.[1];return n}).filter(Boolean);return Array.from(t)};var d=n(9324),u=n(1621),g=n(7134);const p=(e,t)=>({query:null,searchPlugins:[],installedPlugins:[],searchPluginsLimit:6,recommendationsLimit:2,isSearchPluginsLoading:!1,isSearchPluginsError:!1,isInstalledPluginsLoading:!1,isInstalledPluginsError:!1,initialize:()=>{t().startListeningToAjax(),t().fetchInstalledPlugins()},startListeningToAjax:()=>{const t=new URLSearchParams(window.location.search).get("s");if(t){const n=document.getElementById("plugin-filter"),i=c(n);e({query:t,searchPlugins:i})}const n=new DOMParser;window.jQuery?.ajaxSetup({beforeSend:(t,i)=>{const s=new URLSearchParams(i.data),a=s.get("action"),r=s.get("s");"search-install-plugins"===a&&(i.success=t=>{if("string"==typeof t&&t?.startsWith("<!DOCTYPE html>")){const e=window.jQuery("#search-plugins"),t=e.val();return e.val(t.endsWith(" ")?t.trim():`${t} `),void e.trigger("keyup")}try{const i=n.parseFromString(t?.data?.items||"","text/html"),s=c(i);e({searchPlugins:s,isSearchPluginsLoading:!1,isSearchPluginsError:!1})}catch(t){e({searchPlugins:[],isSearchPluginsLoading:!1,isSearchPluginsError:!0})}},i.error=()=>{e({searchPlugins:[],isSearchPluginsLoading:!1,isSearchPluginsError:!0})},e({query:r||null,searchPlugins:[],isSearchPluginsLoading:!!r,isSearchPluginsError:!1}))}})},fetchInstalledPlugins:async(n=!1)=>{if(!t().installedPlugins.length||n)try{e({isInstalledPluginsLoading:!0,isInstalledPluginsError:!1});const t=await(0,d.OH)();e({installedPlugins:t?.map(e=>({slug:e.plugin.split("/")[0],status:e.status})),isInstalledPluginsLoading:!1,isInstalledPluginsError:!1})}catch(t){e({installedPlugins:[],isInstalledPluginsLoading:!1,isInstalledPluginsError:!0})}}}),m=(()=>{const e=(0,u.vt)((0,g.lt)(p,{name:"Extendify Plugin Search"}));return e.getState().initialize(),e})(),{extSharedData:h,extRecommendationsData:x}=window,w=!(!x?.showPartnerBranding||!h?.partnerLogo),f={"plugin-search":m},y=Object.keys(f),P=({slot:e,event:t,product:n})=>{if(!t||!y.includes(e))return;const s=f[e].getState(),a=(e=>e.installedPlugins.map(e=>e.slug))(s),r=(e=>e.installedPlugins.filter(e=>"active"===e.status).map(e=>e.slug))(s),o=l(s).map(e=>{return t=e,n=["slug","title","description","ctaContent","ctaType","triggerContent","triggerType"],Object.entries(t).filter(([e])=>n.includes(e)).reduce((e,[t,n])=>(e[t]=n,e),{});var t,n}),c=o.find(e=>e.slug===n)?.slug,d={event:t,timestamp:(new Date).toISOString(),slot:e,recommendation:c,recommendations:o,recommendationsLimit:s.recommendationsLimit,query:decodeURIComponent(s.query),searchResults:s.searchPlugins,searchResultsLimit:s.searchPluginsLimit,installedPlugins:a,activePlugins:r,partnerBrandingEnabled:w,partnerId:h.partnerId,siteId:h.siteId,wpVersion:h.wpVersion,wpLocale:h.wpLanguage,extendifyVersion:h.version,devbuild:h.devbuild},u=new AbortController;window.setTimeout(()=>{u.abort()},900),fetch(`${i.Dq}/api/v1/recommendations/activity`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Extendify-Site-ID":h.siteId},signal:u.signal,body:JSON.stringify(d)}).catch(()=>null)};var v=n(6935),j=n(365),S=n(6427),b=n(6087),L=n(8537),k=n(7723),E=n(319),C=n(7516),I=n(6963),N=n(2344),T=n(790);const A=({slug:e,title:t,description:n,ctaContent:i,provider:s,image:a,ctaType:r,ctaPluginSlug:l,ctaExternalLink:o,ctaInternalLink:c,priceTag:d})=>((0,b.useEffect)(()=>{P({slot:"plugin-search",event:"view",product:e})},[e]),(0,T.jsxs)("div",{className:"flex flex-col rounded-sm border border-gray-300","data-test":"extendify-recommendations-card",children:[(0,T.jsxs)("div",{className:"row-auto grid grow grid-cols-[2fr_3fr] grid-rows-[min-content_1fr] gap-x-5 gap-y-3 p-5 xs:grid-cols-[8rem_1fr]",children:[(0,T.jsx)("div",{className:"row-span-1 xs:row-span-2",children:a&&("plugin"===r?(0,T.jsx)("a",{onClick:()=>P({slot:"plugin-search",event:"click-logo",product:e}),className:"thickbox open-plugin-details-modal block no-underline",href:`${window.extSharedData?.adminUrl}/plugin-install.php?tab=plugin-information&plugin=${l}&TB_iframe=true&width=600&height=550`,children:(0,T.jsx)("img",{className:"w-full xs:min-h-[8rem]",src:a,alt:t})}):(0,T.jsx)("img",{className:"w-full xs:min-h-[8rem]",src:a,alt:t}))}),(0,T.jsxs)("div",{className:"flex flex-col justify-center xs:justify-start",children:[(0,T.jsx)("h3",{className:"m-0 text-lg leading-tight text-wp-theme-main",children:"plugin"===r?(0,T.jsx)("a",{onClick:()=>P({slot:"plugin-search",event:"click-title",product:e}),className:"thickbox open-plugin-details-modal no-underline focus:shadow-none",href:`${window.extSharedData?.adminUrl}/plugin-install.php?tab=plugin-information&plugin=${l}&TB_iframe=true&width=600&height=550`,children:(0,L.decodeEntities)(t)}):(0,L.decodeEntities)(t)}),(0,T.jsx)("p",{className:"m-0 mt-1 text-xs italic",children:(0,k.sprintf)( |
| 2 |
// translators: %s is a name |
| 3 |
// translators: %s is a name |
| 4 |
(0,k._x)("By %s",'Preposition for "By Author Name"',"extendify-local"),s)})]}),(0,T.jsx)("p",{className:"col-span-2 m-0 text-sm xs:col-span-1",children:(0,L.decodeEntities)(n)})]}),(0,T.jsxs)("div",{className:"flex min-h-14 shrink-0 flex-col items-center justify-center p-3 px-5 xxs:flex-row xxs:justify-end",children:[d&&(0,T.jsx)("p",{className:"m-0 mb-3 xxs:mb-0 xxs:mr-4",dangerouslySetInnerHTML:{__html:(0,L.decodeEntities)(d)}}),"plugin"===r&&(0,T.jsx)(_,{product:e,ctaContent:(0,L.decodeEntities)(i),ctaPluginSlug:l}),"external-link"===r&&(0,T.jsx)(D,{product:e,ctaContent:(0,L.decodeEntities)(i),ctaExternalLink:o}),"internal-link"===r&&(0,T.jsx)(B,{product:e,ctaContent:(0,L.decodeEntities)(i),ctaInternalLink:c})]})]})),_=({product:e,ctaContent:t,ctaPluginSlug:n})=>{const[i,s]=(0,b.useState)("idle"),[a,r]=(0,b.useState)(null),l=(0,b.useCallback)(async()=>{P({slot:"plugin-search",event:"click-install",product:e});try{s("installing"),await Promise.all([(0,j.Uq)(()=>(0,d.xZ)(n),{maxAttempts:2}),(0,j.yy)(1e3)])}catch(e){return r((0,k.__)("Failed to install the plugin","extendify-local")),void s("error")}(0,v.yB)({slug:n,source:"search-recommendation-card"});try{s("activating"),await Promise.all([(0,j.Uq)(()=>(0,d.Bf)(n),{maxAttempts:2}),(0,j.yy)(1e3)])}catch(e){return r((0,k.__)("Failed to activate the plugin","extendify-local")),void s("error")}s("activated")},[e,n]),o={idle:t,installing:(0,k._x)("Installing...","Plugin installation status","extendify-local"),activating:(0,k._x)("Activating...","Plugin activation status","extendify-local"),activated:(0,k._x)("Activated","Plugin activation status","extendify-local"),error:a};return"error"===i?(0,T.jsxs)("p",{className:"m-0 flex items-center fill-wp-alert-red text-sm text-wp-alert-red",children:[(0,T.jsx)(E.A,{icon:C.A}),o[i]]}):"activated"===i?(0,T.jsxs)("p",{className:"m-0 flex items-center fill-wp-alert-green text-sm text-wp-alert-green",children:[(0,T.jsx)(E.A,{icon:I.A}),o[i]]}):(0,T.jsx)(S.Button,{className:"min-w-24 whitespace-normal wrap-break-word rounded-xs bg-wp-theme-main px-3 align-middle text-sm text-design-text shadow-none hover:opacity-90 disabled:opacity-80",type:"button",variant:"secondary",size:"compact",disabled:"idle"!==i,isBusy:"idle"!==i,onClick:l,children:o[i]})},D=({product:e,ctaContent:t,ctaExternalLink:n})=>{const i=(0,L.decodeEntities)(n).replace("{PARTNERID}",window.extSharedData?.partnerId);return(0,T.jsxs)("a",{onClick:()=>P({slot:"plugin-search",event:"click-link-external",product:e}),href:i,target:"_blank",className:"relative flex min-h-8 min-w-24 cursor-pointer items-center justify-center whitespace-normal wrap-break-word rounded-xs bg-wp-theme-main fill-design-text py-1.5 pl-3 pr-9 text-center text-sm leading-tight text-design-text no-underline hover:opacity-90 focus:shadow-none",children:[t,(0,T.jsx)(E.A,{className:"absolute right-3 h-5 w-5",icon:N.A})]})},B=({product:e,ctaContent:t,ctaInternalLink:n})=>(0,T.jsx)("a",{onClick:()=>P({slot:"plugin-search",event:"click-link-internal",product:e}),href:n,className:"relative flex min-h-8 min-w-24 cursor-pointer items-center justify-center whitespace-normal break-words rounded-xs bg-wp-theme-main fill-design-text px-3 py-[6px] text-center text-sm leading-tight text-design-text no-underline hover:opacity-90 focus:shadow-none",children:t}),R=({recommendations:e})=>(0,T.jsx)("div",{className:"grid grid-cols-1 gap-4 px-6 pb-8 md:grid-cols-2 3xl:grid-cols-3 5xl:grid-cols-4","data-test":"extendify-recommendations-grid",children:e.map(e=>["plugin","external-link","internal-link"].includes(e.ctaType)?(0,T.jsx)(A,{...e},e.slug):null)});var O=n(3832);const q=window.extRecommendationsData?.showPartnerBranding&&window.extSharedData?.partnerLogo,U=()=>{const e=m(e=>e.query),t=m(a),n=m(r),i=m(e=>e.recommendationsLimit),s=m(o),l=m(e=>e.fetchInstalledPlugins);return(0,b.useEffect)(()=>{e&&!t&&P({slot:"plugin-search",event:"search"})},[e,t]),(0,b.useEffect)(()=>{e&&l(!0)},[e,l]),!e||!s?.length||t||n?null:(0,T.jsxs)("div",{className:"my-8 flex w-full flex-col overflow-hidden rounded-sm border border-gray-400 bg-white","data-test":"extendify-recommendations-banner",children:[(0,T.jsxs)("div",{className:`flex h-14 ${q?"bg-banner-main":""} px-6 py-4`,children:[q?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)("img",{alt:window.extSharedData?.partnerName||"Partner Logo",className:"mr-3 h-full",src:window.extSharedData?.partnerLogo}),(0,T.jsx)("div",{className:"mr-3 border-l border-banner-text opacity-80"})]}):null,(0,T.jsx)("h2",{className:`m-0 flex h-full items-center ${q?"text-banner-text":""} `,children:(0,k.sprintf)( |
| 5 |
// translators: %s: The search query term |
| 6 |
// translators: %s: The search query term |
| 7 |
(0,k.__)("Recommended Solutions for: %s","extendify-local"),(0,O.safeDecodeURIComponent)(e))})]}),(0,T.jsx)(R,{recommendations:s.slice(0,i)})]})};var $=n(8490),F=n.n($),W=n(7828);F()(()=>{const e=new URL(window.location.href),t=e.pathname.endsWith("plugin-install.php"),n=e.pathname.endsWith("post-new.php")&&"page"!==e.searchParams.get("post_type"),i=e.pathname.endsWith("post-new.php")&&"page"===e.searchParams.get("post_type");if((t||n||i)&&t){const e=document.getElementById("plugin-filter");if(e){const t="ext-recommendations-plugin-search";if(document.getElementById(t))return;const n=Object.assign(document.createElement("div"),{id:t,className:"extendify-recommendations"});return e.parentNode.insertBefore(n,e),(0,W.X)((0,T.jsx)(U,{}),n)}}})},1609(e){e.exports=window.React},790(e){e.exports=window.ReactJSXRuntime},1455(e){e.exports=window.wp.apiFetch},6427(e){e.exports=window.wp.components},8490(e){e.exports=window.wp.domReady},6087(e){e.exports=window.wp.element},8537(e){e.exports=window.wp.htmlEntities},7723(e){e.exports=window.wp.i18n},5573(e){e.exports=window.wp.primitives},3832(e){e.exports=window.wp.url}},e=>{e.O(0,[65,223],()=>e(e.s=5402)),e.O()}]); |