add_dependency( new Divi\Module() ); } } /** * The Visual Builder's script (a plain script, no build): the module's fields, the published modules to pick from, * their pictures. Only in the builder, for people who may edit; the list fills the placeable keys (Placeable). */ public static function builder_assets() { if ( ! function_exists( 'et_core_is_fb_enabled' ) || ! et_core_is_fb_enabled() || ! current_user_can( 'edit_posts' ) || ! class_exists( '\ET\Builder\VisualBuilder\Assets\PackageBuildManager' ) ) { return; } \ET\Builder\VisualBuilder\Assets\PackageBuildManager::register_package_build( array( 'name' => self::SCRIPT, 'version' => SRANYWHERE_VERSION, 'script' => array( 'src' => SRANYWHERE_URL . 'divi/builder.js', 'deps' => array( 'divi-module-library', 'divi-vendor-wp-hooks' ), 'enqueue_top_window' => false, 'enqueue_app_window' => true, 'data_app_window' => self::builder_data(), ), ) ); } /** * What the builder's script needs: the module's description (module.json, one source for both sides), the modules * and pages to pick (published, no modals), the SR mark and the words. * * @return array */ private static function builder_data() { $items = array(); foreach ( Picker::items() as $item ) { $items[] = array( 'key' => $item['embedKey'], 'name' => $item['name'], 'kind' => $item['kind'], 'thumb' => $item['thumb'], ); } $json = file_get_contents( dirname( __DIR__ ) . '/divi/module.json' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- a file of the plugin. return array( 'metadata' => json_decode( (string) $json, true ), 'items' => $items, 'connected' => Connection::CONNECTED === Connection::current_state(), 'mark' => self::mark(), 'words' => array( 'pick' => __( 'โ€” Pick a module โ€”', 'sr-anywhere' ), /* translators: %s: the name of an SR Anywhere page (a one-page site). */ 'page' => __( '%s (page)', 'sr-anywhere' ), 'empty' => __( 'Pick a module in the settings.', 'sr-anywhere' ), 'connect' => __( 'Connect SR Anywhere first: Settings โ†’ SR Anywhere.', 'sr-anywhere' ), 'onPage' => __( 'The page shows the module itself.', 'sr-anywhere' ), 'module' => __( 'Module', 'sr-anywhere' ), 'moduleTip' => __( 'A published module or page of the connected SR Anywhere account.', 'sr-anywhere' ), 'offset' => __( 'Leave room for (full screen)', 'sr-anywhere' ), 'offsetTip' => __( 'The CSS selector of the site\'s header, for full-screen modules whose header does not lie over them. The admin bar is left out by itself.', 'sr-anywhere' ), ), ); } /** * The SR mark's path, for the module list's icon. * * @return array `{ viewBox, d }`. */ private static function mark() { $svg = (string) file_get_contents( dirname( __DIR__ ) . '/assets/sr-mark.svg' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- a file of the plugin. $box = preg_match( '/viewBox="([0-9. ]+)"/', $svg, $m ) ? $m[1] : '0 0 100 100'; preg_match_all( '/\sd="([^"]+)"/', $svg, $paths ); return array( 'viewBox' => $box, 'd' => $paths[1], ); } }