PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.4.3
Kubio AI Page Builder v2.4.3
2.9.1 2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / editor-assets.php
kubio / lib Last commit date
AI 1 year ago admin-pages 2 years ago api 1 year ago blog 3 years ago customizer 2 years ago filters 1 year ago full-site-editing 2 years ago importer 4 years ago integrations 1 year ago menu 3 years ago polyfills 3 years ago preview 2 years ago shapes 2 years ago shortcodes 2 years ago src 1 year ago add-edit-in-kubio.php 1 year ago editor-assets.php 1 year ago env.php 1 year ago filters.php 1 year ago frontend.php 4 years ago global-data.php 1 year ago init.php 2 years ago kubio-block-library.php 2 years ago kubio-editor.php 1 year ago load.php 1 year ago
editor-assets.php
571 lines
1 <?php
2
3 use IlluminateAgnostic\Arr\Support\Arr;
4 use Kubio\AssetsDependencyInjector;
5 use Kubio\Core\Utils;
6 use Kubio\DemoSites\DemoSitesRepository;
7 use Kubio\Flags;
8
9 function kubio_override_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
10 $script = $scripts->query( $handle, 'registered' );
11 if ( $script ) {
12
13 $script->src = $src;
14 $script->deps = $deps;
15 $script->ver = $ver;
16 $script->args = $in_footer;
17
18 unset( $script->extra['group'] );
19 if ( $in_footer ) {
20 $script->add_data( 'group', 1 );
21 }
22 } else {
23 $scripts->add( $handle, $src, $deps, $ver, $in_footer );
24 }
25
26 if ( in_array( 'wp-i18n', $deps, true ) ) {
27 $translation_path = wp_normalize_path( KUBIO_ROOT_DIR . '/languages' );
28 $scripts->set_translations( $handle, 'kubio', $translation_path );
29 }
30 }
31
32 function kubio_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
33 $style = $styles->query( $handle, 'registered' );
34 if ( $style ) {
35 $styles->remove( $handle );
36 }
37 $styles->add( $handle, $src, $deps, $ver, $media );
38 }
39
40 function kubio_register_kubio_scripts_scripts_dependencies( $version ) {
41 $scripts = array(
42 array(
43 'handle' => 'typed',
44 'deps' => array( 'jquery' ),
45 'src' => 'typed.js',
46 ),
47 array(
48 'handle' => 'fancybox',
49 'deps' => array( 'jquery' ),
50 'src' => 'fancybox/jquery.fancybox.min.js',
51 ),
52 array(
53 'handle' => 'swiper',
54 'deps' => array( 'jquery' ),
55 'src' => 'swiper/js/swiper.js',
56 ),
57 );
58
59 foreach ( $scripts as $script ) {
60 AssetsDependencyInjector::registerKubioScriptsDependency(
61 $script['handle'],
62 kubio_url( "/static/{$script['src']}" ),
63 $script['deps'],
64 $version
65 );
66 }
67
68 }
69
70 function kubio_register_frontend_script( $handle ) {
71 add_filter(
72 'kubio/frontend/scripts',
73 function( $scripts ) use ( $handle ) {
74
75 if ( ! in_array( $handle, $scripts ) ) {
76 $scripts[] = $handle;
77 }
78
79 return $scripts;
80 }
81 );
82 }
83
84 function kubio_get_frontend_scripts() {
85 return apply_filters( 'kubio/frontend/scripts', array() );
86 }
87
88 function kubio_enqueue_frontend_scripts() {
89 $scripts = apply_filters( 'kubio/frontend/scripts', array() );
90 foreach ( $scripts as $handle ) {
91 wp_enqueue_script( $handle );
92 }
93 }
94
95 function kubio_register_packages_scripts() {
96
97 $registered = array();
98
99 $translation_path = wp_normalize_path( KUBIO_ROOT_DIR . '/languages' );
100
101 $paths = glob( KUBIO_ROOT_DIR . 'build/*/index.js' );
102 foreach ( $paths as $path ) {
103 $handle = 'kubio-' . basename( dirname( $path ) );
104 $asset_file = substr( $path, 0, - 3 ) . '.asset.php';
105 $asset = file_exists( $asset_file )
106 ? require( $asset_file )
107 : null;
108 $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
109
110 if ( Utils::isDebug() ) {
111 $version = uniqid( time() . '-' );
112 } else {
113 $version = isset( $asset['version'] ) ? $asset['version'] : filemtime( $path );
114 }
115
116 switch ( $handle ) {
117 case 'kubio-editor':
118 array_push( $dependencies, 'wp-dom-ready', 'editor', 'wp-editor' );
119
120 if ( kubio_is_kubio_editor_page() ) {
121 array_push( $dependencies, 'kubio-interface-store' );
122 }
123
124 break;
125
126 case 'kubio-format-library':
127 array_push( $dependencies, 'wp-format-library' );
128 break;
129
130 case 'kubio-scripts':
131 kubio_register_kubio_scripts_scripts_dependencies( $version );
132 $dependencies = array_merge( $dependencies, array( 'jquery' ) );
133 $dependencies = array_diff( $dependencies, array( 'wp-polyfill' ) );
134 break;
135
136 case 'kubio-frontend':
137 $dependencies = array( 'kubio-scripts' );
138 kubio_register_frontend_script( 'kubio-frontend' );
139 break;
140
141 case 'kubio-block-library':
142 array_push( $dependencies, 'kubio-format-library' );
143 break;
144
145 case 'kubio-block-editor':
146 if ( wp_script_is( 'wp-private-apis', 'registered' ) ) {
147 $dependencies[] = 'wp-private-apis';
148 }
149
150 if ( wp_script_is( 'wp-experiments', 'registered' ) ) {
151 $dependencies[] = 'wp-experiments';
152 }
153
154 //For backward compatability to 6.1
155 if ( Utils::wpVersionCompare( '6.4', '<' ) ) {
156 if ( ( $key = array_search( 'wp-commands', $dependencies ) ) !== false ) {
157 unset( $dependencies[ $key ] );
158 }
159 }
160 array_push( $dependencies, 'wp-block-directory' );
161 break;
162
163 }
164
165 $kubio_path = substr( $path, strlen( KUBIO_ROOT_DIR ) );
166
167 $registered[] = array(
168 $handle,
169 kubio_url( $kubio_path ),
170 $dependencies,
171 $version,
172 true,
173 );
174 }
175
176 foreach ( $registered as $script ) {
177
178 if ( is_array( $script ) && count( $script ) >= 2 ) {
179 $handle = $script[0];
180 $deps = $script[2];
181 if ( in_array( 'wp-i18n', $deps, true ) ) {
182 wp_set_script_translations( $handle, 'kubio' );
183 }
184
185 call_user_func_array( 'wp_register_script', $script );
186 \wp_set_script_translations( $script[0], 'kubio', $translation_path );
187 do_action( 'kubio_registered_script', $script[0], $script[3] );
188 }
189 }
190
191 do_action( 'kubio_scripts_registered', $registered );
192 }
193
194
195 function kubio_replace_default_scripts( $scripts ) {
196
197 if ( ! kubio_is_kubio_editor_page() ) {
198 return;
199 }
200
201 $to_replace = array(
202 'wp-block-editor' => 'block-editor',
203 );
204
205 foreach ( $to_replace as $old => $new ) {
206 $script_path = KUBIO_ROOT_DIR . "/build/{$new}/index.js";
207 $asset_file = KUBIO_ROOT_DIR . "/build/{$new}/index.asset.php";
208
209 $asset = file_exists( $asset_file )
210 ? require( $asset_file )
211 : null;
212 $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
213 $version = isset( $asset['version'] ) ? $asset['version'] : filemtime( $script_path );
214
215 //For backward compatability to 6.1
216 if ( Utils::wpVersionCompare( '6.4', '<' ) ) {
217 if ( ( $key = array_search( 'wp-commands', $dependencies ) ) !== false ) {
218 unset( $dependencies[ $key ] );
219 }
220 }
221 kubio_override_script(
222 $scripts,
223 $old,
224 kubio_url( "/build/{$new}/index.js" ),
225 $dependencies,
226 $version,
227 true
228 );
229 }
230
231 }
232
233
234 function kubio_register_kubio_block_library_style_dependencies( $version ) {
235 $styles = array(
236 array(
237 'handle' => 'fancybox',
238 'src' => 'fancybox/jquery.fancybox.min.css',
239 ),
240 array(
241 'handle' => 'swiper',
242 'src' => 'swiper/css/swiper.min.css',
243 ),
244 );
245
246 foreach ( $styles as $style ) {
247 AssetsDependencyInjector::registerKubioFrontendStyleDependency(
248 $style['handle'],
249 kubio_url( "/static/{$style['src']}" ),
250 isset( $style['deps'] ) ? $style['deps'] : array(),
251 $version
252 );
253 }
254
255 }
256
257
258 function kubio_register_packages_styles() {
259
260 $registered = array();
261
262 foreach ( glob( KUBIO_ROOT_DIR . 'build/*/style.css' ) as $path ) {
263 $handle = 'kubio-' . basename( dirname( $path ) );
264 $kubio_path = substr( $path, strlen( KUBIO_ROOT_DIR ) );
265 $version = filemtime( $path );
266 $dependencies = array();
267
268 switch ( $handle ) {
269 case 'kubio-editor':
270 $dependencies = array( 'wp-edit-blocks' );
271 break;
272
273 case 'kubio-format-library':
274 array_push( $dependencies, 'wp-format-library' );
275 break;
276
277 case 'kubio-admin-panel':
278 array_push( $dependencies, 'kubio-utils' );
279 break;
280
281 case 'kubio-ai':
282 array_push( $dependencies, 'wp-components' );
283 break;
284
285 case 'kubio-block-library':
286 kubio_register_kubio_block_library_style_dependencies( $version );
287 break;
288 }
289
290 $registered[] = array(
291 $handle,
292 kubio_url( $kubio_path ),
293 $dependencies,
294 $version,
295 );
296 }
297
298 foreach ( glob( KUBIO_ROOT_DIR . 'build/*/editor.css' ) as $path ) {
299 $handle = 'kubio-' . basename( dirname( $path ) );
300 $kubio_path = substr( $path, strlen( KUBIO_ROOT_DIR ) );
301 $version = filemtime( $path );
302 $dependencies = array();
303
304 switch ( $handle ) {
305 case 'kubio-editor':
306 $dependencies = array( 'wp-edit-blocks' );
307 break;
308
309 case 'kubio-block-library':
310 $dependencies = array( /* 'wp-block-library' */ );
311 break;
312 }
313
314 $registered[] = array(
315 "{$handle}-editor",
316 kubio_url( $kubio_path ),
317 $dependencies,
318 $version,
319 );
320 }
321
322 foreach ( $registered as $style ) {
323
324 if ( is_array( $style ) && count( $style ) >= 2 ) {
325
326 call_user_func_array( 'wp_register_style', $style );
327
328 }
329 }
330 }
331
332
333 function kubio_replace_default_styles( $styles ) {
334
335 if ( ! kubio_is_kubio_editor_page() ) {
336 return;
337 }
338
339 // Editor Styles .
340 kubio_override_style(
341 $styles,
342 'wp-block-editor',
343 kubio_url( 'build/block-editor/style.css' ),
344 array( 'wp-components', 'wp-editor-font' ),
345 filemtime( KUBIO_ROOT_DIR . 'build/editor/style.css' )
346 );
347 $styles->add_data( 'wp-block-editor', 'rtl', 'replace' );
348
349 }
350
351 add_action( 'init', 'kubio_register_packages_scripts' );
352 add_action( 'init', 'kubio_register_packages_styles' );
353
354 add_action( 'wp_default_styles', 'kubio_replace_default_styles' );
355 add_action( 'wp_default_scripts', 'kubio_replace_default_scripts' );
356
357
358 add_action(
359 'kubio_registered_script',
360 function ( $handle, $version ) {
361 global $wp_version;
362 if ( $handle === 'kubio-utils' || $handle === 'kubio-admin-panel' ) {
363 $include_test_templates = defined( 'KUBIO_INCLUDE_TEST_TEMPLATES' ) && KUBIO_INCLUDE_TEST_TEMPLATES === true;
364 $is_wpml_active = kubio_wpml_is_active();
365 $is_polylang_active = kubio_polylang_is_active();
366
367 $data = 'window.kubioUtilsData=' . wp_json_encode(
368 array_merge(
369 kubio_get_site_urls(),
370 array(
371 'defaultAssetsURL' => kubio_url( 'static/default-assets' ),
372 'staticAssetsURL' => kubio_url( 'static' ),
373 'patternsAssetsUrl' => kubio_url( 'static/patterns' ),
374 'kubioRemoteContentFile' => 'https://static-assets.kubiobuilder.com/content-2022-05-17.json',
375 'kubioCloudPresetsUrl' => Utils::getGlobalSnippetsURL(),
376 'kubioCloudPresetCategoriesUrl' => Utils::getGlobalSnippetsCategoriesURL(),
377 'kubioCloudPresetTagsUrl' => Utils::getGlobalSnippetsTagsURL(),
378 'kubioCloudUrl' => Utils::getCloudURL(),
379 'kubioRemoteContent' => Utils::getSnippetsURL( '/globals' ),
380 'kubioLocalContentFile' => kubio_url( 'static/patterns/content-converted.json' ),
381 'kubioEditorURL' => add_query_arg( 'page', 'kubio', admin_url( 'admin.php' ) ),
382 'patternsOnTheFly' => ( defined( 'KUBIO_PATTERNS_ON_THE_FLY' ) && KUBIO_PATTERNS_ON_THE_FLY ) ? KUBIO_PATTERNS_ON_THE_FLY : '',
383 'base_url' => site_url(),
384 'admin_url' => admin_url(),
385 'admin_plugins_url' => admin_url( 'plugins.php' ),
386 'demo_sites_url' => Utils::getStarterSitesURL(),
387 'demo_parts_url' => Utils::getStarterPartsURL(),
388 'plugins_states' => DemoSitesRepository::getInstance()->getPluginsStates(),
389 'last_imported_starter' => Flags::get( 'last_imported_starter' ),
390 'demo_site_ajax_nonce' => wp_create_nonce( 'kubio-ajax-demo-site-verification' ),
391 'ajax_url' => admin_url( 'admin-ajax.php' ),
392 'kubio_ajax_nonce' => wp_create_nonce( 'kubio_ajax_nonce' ),
393 'enable_starter_sites' => apply_filters( 'kubio/starter-sites/enabled', true ),
394 'wpVersion' => preg_replace( '/([0-9]+).([0-9]+).*/', '$1.$2', $wp_version ),
395 'enable_try_online' => Utils::isTryOnlineEnabled(),
396 'supplementary_upgrade_to_pro' => apply_filters( 'kubio/show-supplementary-upgrade-to-pro', false ),
397 'kubioAIPricingURL' => Utils::getCloudURL( '/ui-route/my-plans?purchase_ai=1' ),
398 'kubioAIParallelCalls' => apply_filters( 'kubio/ai/parallel-calls', 5 ),
399 'showInternalFeatures' => defined( '\KUBIO_INTERNAL' ) && \KUBIO_INTERNAL,
400 'sectionStylesTags' => array( 'shadow', 'flat', 'outlined', 'rounded', 'minimal' ),
401 'activatedOnStage2' => Flags::getSetting( 'activatedOnStage2', false ),
402 'aiStage2' => Flags::getSetting( 'aiStage2', false ),
403 'advancedMode' => Flags::getSetting( 'advancedMode', true ),
404 'featuresVersion' => Flags::getSetting( 'featuresVersion', 1 ),
405 'wpAdminUpgradePage' => add_query_arg(
406 array(
407 'tab' => 'pro-upgrade',
408 'page' => 'kubio-get-started',
409 ),
410 admin_url( 'admin.php' )
411 ),
412 'adminLanguage' => get_user_locale(),
413 'autoStartBlackWizardOnboarding' => get_option( '_kubio_auto_start_black_wizard_onboarding', false ),
414 'importDesignIndex' => Flags::get( 'import_design_index', null ),
415 'importDesignAiStructure' => Flags::get( 'import_design_ai_structure', null ),
416 'aiWizardDescriptionOptional' => Flags::getSetting( 'aiWizardDescriptionOptional', false ),
417 'allow3rdPartyBlogOverride' => apply_filters( 'kubio/allow_3rd_party_blog_override', true ),
418 'multilanguage' => array(
419 'hasTranslator' => $is_wpml_active || $is_polylang_active,
420 'isWpmlActive' => $is_wpml_active,
421 'isPolylangActive' => $is_polylang_active,
422 'polylang_add_page_translation_nonce' => wp_create_nonce( 'kubio_api_polylang_add_page_translation' ),
423 ),
424 ),
425 apply_filters( 'kubio/kubio-utils-data/extras', array() )
426 )
427 );
428
429 wp_add_inline_script( $handle, $data, 'before' );
430 }
431
432 if ( $handle === 'kubio-style-manager' ) {
433
434 $url = add_query_arg(
435 array(
436 'action' => 'kubio_style_manager_web_worker',
437 '_wpnonce' => wp_create_nonce( 'kubio_style_manager_web_worker_nonce' ),
438 'v' => filemtime( KUBIO_ROOT_DIR . '/defaults/style-manager-web-worker-template.js' ) . '-' . ( Utils::isDebug() ? time() : KUBIO_VERSION . '-' . $wp_version ),
439 ),
440 admin_url( 'admin-ajax.php' )
441 );
442
443 wp_add_inline_script(
444 $handle,
445 'var _kubioStyleManagerWorkerURL=' . wp_json_encode( $url ),
446 'before'
447 );
448 }
449 },
450 10,
451 2
452 );
453
454 function kubio_print_style_manager_web_worker() {
455 check_ajax_referer( 'kubio_style_manager_web_worker_nonce' );
456 header( 'content-type: application/javascript' );
457
458 $script = '';
459 $done = wp_scripts()->done;
460 ob_start();
461 wp_scripts()->done = array( 'wp-inert-polyfill', 'wp-polyfill' );
462 wp_scripts()->do_items( 'kubio-style-manager' );
463 wp_scripts()->done = $done;
464 $script = ob_get_clean();
465
466 $script = preg_replace_callback(
467 '#<script(.*?)>(.*?)</script>#s',
468 function( $matches ) {
469 $script_attrs = Arr::get( $matches, 1, '' );
470 preg_match( "#src=(\"|')(.*?)(\"|')#", $script_attrs, $attrs_match );
471 $url = Arr::get( $attrs_match, 2, '' );
472 $content = trim( Arr::get( $matches, 2, '' ) );
473
474 $result = array();
475
476 if ( ! empty( $url ) ) {
477 $result[] = sprintf( "importScripts('%s');", $url );
478 }
479
480 if ( ! empty( $content ) ) {
481 $result[] = $content;
482 }
483
484 return trim( implode( "\n", $result ) ) . "\n\n";
485 },
486 $script
487 );
488
489 $content = file_get_contents( KUBIO_ROOT_DIR . '/defaults/style-manager-web-worker-template.js' );
490 $content = str_replace( '// {{{importScriptsPlaceholder}}}', $script, $content );
491
492 if ( ! Utils::isDebug() ) {
493 header( 'Cache-control: public' );
494 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', time() ) . ' GMT' );
495 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + YEAR_IN_SECONDS ) . ' GMT' );
496 header( 'Etag: ' . md5( $content ) );
497 }
498
499 die( $content );
500 }
501
502 add_action( 'wp_ajax_kubio_style_manager_web_worker', 'kubio_print_style_manager_web_worker' );
503
504 // quick test for safari
505 add_action(
506 'admin_init',
507 function () {
508 ob_start();
509 ?>
510 <script>
511 window.requestIdleCallback =
512 window.requestIdleCallback ||
513 function (cb) {
514 var start = Date.now();
515 return setTimeout(function () {
516 cb({
517 didTimeout: false,
518 timeRemaining: function () {
519 return Math.max(0, 50 - (Date.now() - start));
520 },
521 });
522 }, 1);
523 };
524
525 window.cancelIdleCallback =
526 window.cancelIdleCallback ||
527 function (id) {
528 clearTimeout(id);
529 };
530 </script>
531 <?php
532
533 $content = strip_tags( ob_get_clean() );
534
535 wp_add_inline_script( 'wp-polyfill', $content, 'after' );
536 }
537 );
538
539 function kubio_defer_kubio_scripts( $tag, $handle, $src ) {
540
541 if ( is_admin() ) {
542 return $tag;
543 }
544
545 if ( strpos( $src, kubio_url() ) === 0 ) {
546 $tag = str_replace( 'src=', 'defer src=', $tag );
547 }
548
549 return $tag;
550 }
551
552 add_filter( 'script_loader_tag', 'kubio_defer_kubio_scripts', 10, 3 );
553
554 function kubio_defer_kubio_styles( $tag, $handle, $href, $media ) {
555
556 if ( is_admin() ) {
557 return $tag;
558 }
559
560 $defferable_handles = array( 'kubio-google-fonts', 'kubio-third-party-blocks' );
561
562 if ( in_array( $handle, $defferable_handles ) ) {
563 $tag = preg_replace( "#rel='(.*?)'#", 'rel="preload" as="style" onload="this.onload=null;this.rel=\'$1\'"', $tag );
564 $tag .= "<noscript><link rel='stylesheet' href='{$href}' media='{$media}'></noscript>";
565 }
566
567 return $tag;
568 }
569
570 add_filter( 'style_loader_tag', 'kubio_defer_kubio_styles', 10, 4 );
571