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