芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/www/wp-content/plugins/blocksy-companion/static/js/dashboard/screens/SiteExport.js
import { createElement, Component, useEffect, useState, Fragment, } from '@wordpress/element' import { __ } from 'ct-i18n' import classnames from 'classnames' import useActivationAction from '../helpers/useActivationAction' import fileSaver from 'file-saver' import Overlay from '../../helpers/Overlay' import { getPluginsMap } from './DemoInstall/Wizzard/Plugins' const SiteExport = ({ allPlans, allCategories }) => { const [isLoading, setIsLoading] = useState(false) const [isShowing, setIsShowing] = useState(false) const [remoteDemos, setRemoteDemos] = useState([]) const [demoId, setDemoId] = useState(null) const [builder, setBuilder] = useState('') const [plugins, setPlugins] = useState([]) useEffect(() => { const fetchInitialData = async () => { const body = new FormData() body.append('action', 'blocksy_demo_get_export_data') body.append( 'nonce', ctDashboardLocalizations.dashboard_actions_nonce ) try { const response = await fetch( ctDashboardLocalizations.ajax_url, { method: 'POST', body, } ) if (response.status === 200) { const { success, data } = await response.json() if (success) { const fields = data.data if (fields && fields.builder) { setBuilder(fields.builder) } if (fields && fields.plugins) { setPlugins(fields.plugins) } if (fields && fields.demoId) { setDemoId(parseFloat(fields.demoId)) } } } } catch (e) {} } const fetchRemoteDemos = async () => { try { const response = await fetch( 'https://creativethemes.com/blocksy/wp-json/ct/v1/starter-sites', { method: 'GET', } ) if (response.status === 200) { const data = await response.json() setRemoteDemos(data) } } catch (e) {} } fetchInitialData() fetchRemoteDemos() }, []) const downloadExport = async () => { setIsLoading(true) const body = new FormData() body.append('action', 'blocksy_demo_export') body.append('nonce', ctDashboardLocalizations.dashboard_actions_nonce) body.append('demoId', demoId) body.append('builder', builder) body.append('plugins', plugins.join(',')) body.append('wp_customize', 'on') try { const response = await fetch(ctDashboardLocalizations.ajax_url, { method: 'POST', body, }) if (response.status === 200) { const { success, data } = await response.json() if (success) { const remoteDemo = remoteDemos.find( (demo) => demo.id === demoId ) const finalDemo = { name: remoteDemo.title, url: remoteDemo.demo_live_link, is_pro: remoteDemo.is_pro === 'Pro', categories: remoteDemo.categories, keywords: remoteDemo.keywords, ...(remoteDemo.is_pro === 'Pro' && remoteDemo.plans ? { plans: [ 'personal', 'professional', 'agency', ...remoteDemo.plans.map((plan) => { return `${plan}_v2` }), ], } : {}), ...data.demo, } if (finalDemo.builder.toLowerCase() === 'elementor') { finalDemo.elementor_experiment_container = true } console.log('Blocksy:Dashboard:DemoInstall:exported', { remoteDemo, finalDemo, }) var blob = new Blob([JSON.stringify(finalDemo)], { type: 'text/plain;charset=utf-8', }) fileSaver.saveAs(blob, `${remoteDemo.title}.json`) } } } catch (e) {} setIsLoading(false) } return (
{ setIsShowing(true) }}>
{__('Export Site')}
setIsShowing(false)} render={() => (
Export Settings
{__( 'Starter site', 'blocksy-companion' )}
setDemoId(parseFloat(value)) }>
{__( 'Select a starter site', 'blocksy-companion' )}
{remoteDemos .sort((a, b) => { const fa = a.title.toLowerCase() const fb = b.title.toLowerCase() if (fa < fb) { return -1 } if (fa > fb) { return 1 } return 0 }) .map((demo) => (
{demo.title}
))}
{__('Builder', 'blocksy-companion')}
setBuilder(value) } />
Required plugins
{Object.keys(getPluginsMap()) .filter( (plugin) => plugin !== 'gutenberg' ) .map((plugin) => (
{ e.preventDefault() setPlugins((plugins) => { if ( plugins.includes( plugin ) ) { return plugins.filter( (p) => p !== plugin ) } return [ ...plugins, plugin, ] }) }}>
-1 } onChange={({ target: { checked }, }) => {}} />
{getPluginsMap()[plugin]}
))}
downloadExport()}> {isLoading ? __('Loading...', 'blocksy-companion') : __('Export site', 'blocksy-companion')}
)} />
) } export default SiteExport