PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.3
Kubio AI Page Builder v2.8.3
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 9 months ago admin-pages 2 days ago api 6 days ago blog 1 year ago customizer 1 year ago filters 2 days ago full-site-editing 1 month ago importer 1 year ago integrations 1 month ago menu 1 year ago polyfills 1 year ago preview 7 months ago recommendations 1 month ago shapes 2 years ago shortcodes 1 year ago src 2 days ago add-edit-in-kubio.php 11 months ago editor-assets.php 6 days 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 month ago kubio-editor.php 1 month ago load.php 1 month 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 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' => Utils::getIsImageHubPluginActive(),
370 'iConvertEmailMarketerIsActive' => Utils::getIsIconvertEmailMarketerActive(),
371 'patternsOnTheFly' => ( defined( 'KUBIO_PATTERNS_ON_THE_FLY' ) && KUBIO_PATTERNS_ON_THE_FLY ) ? KUBIO_PATTERNS_ON_THE_FLY : '',
372 'base_url' => site_url(),
373 'admin_url' => admin_url(),
374 'admin_plugins_url' => admin_url( 'plugins.php' ),
375 'demo_sites_url' => Utils::getStarterSitesURL(),
376 'demo_parts_url' => Utils::getStarterPartsURL(),
377 'plugins_states' => DemoSitesRepository::getInstance()->getPluginsStates(),
378 'last_imported_starter' => Flags::get( 'last_imported_starter' ),
379 'demo_site_ajax_nonce' => wp_create_nonce( 'kubio-ajax-demo-site-verification' ),
380 'ajax_url' => admin_url( 'admin-ajax.php' ),
381 'kubio_ajax_nonce' => wp_create_nonce( 'kubio_ajax_nonce' ),
382 'enable_starter_sites' => apply_filters( 'kubio/starter-sites/enabled', true ),
383 'wpVersion' => preg_replace( '/([0-9]+).([0-9]+).*/', '$1.$2', $wp_version ),
384 'enable_try_online' => Utils::isTryOnlineEnabled(),
385 'supplementary_upgrade_to_pro' => apply_filters( 'kubio/show-supplementary-upgrade-to-pro', false ),
386 'kubioAIPricingURL' => Utils::getCloudURL( '/ui-route/my-plans?purchase_ai=1' ),
387 'kubioAIParallelCalls' => apply_filters( 'kubio/ai/parallel-calls', 5 ),
388 'showInternalFeatures' => defined( '\KUBIO_INTERNAL' ) && \KUBIO_INTERNAL,
389 'sectionStylesTags' => array( 'shadow', 'flat', 'outlined', 'rounded', 'minimal' ),
390 'kubio_is_ai_site_editor' => Utils::getIsAISiteEditor(),
391 'activatedOnStage2' => Flags::getSetting( 'activatedOnStage2', false ),
392 'aiStage2' => Flags::getSetting( 'aiStage2', false ),
393 'advancedMode' => Flags::getSetting( 'advancedMode', true ),
394 'featuresVersion' => Flags::getSetting( 'featuresVersion', 1 ),
395 'allowSiteLeadsRecommendations' => Flags::getSetting( 'allowSiteLeadsRecommendations', false ),
396 'siteName' => get_bloginfo( 'name' ),
397 'wpAdminUpgradePage' => add_query_arg(
398 array(
399 'tab' => 'pro-upgrade',
400 'page' => 'kubio-get-started',
401 ),
402 admin_url( 'admin.php' )
403 ),
404 'adminLanguage' => get_user_locale(),
405 'autoStartBlackWizardOnboarding' => Flags::get( 'auto_start_black_wizard_onboarding', false ),
406 'importDesignIndex' => Flags::get( 'import_design_index', null ),
407 'importDesignAiStructure' => Flags::get( 'import_design_ai_structure', null ),
408 'aiWizardDescriptionOptional' => Flags::getSetting( 'aiWizardDescriptionOptional', false ),
409 'showFrontPageRevertNotice' => KubioFrontPageRevertNotice::getShowNoticeInEditor(),
410 'frontPageRevertBackupData' => KubioFrontPageRevertNotice::getInstance()->getFrontPageBackupData(),
411 'frontPageRevertNoticeNonce' => wp_create_nonce( KubioFrontPageRevertNotice::$nonceKey ),
412 'allow3rdPartyBlogOverride' => apply_filters( 'kubio/allow_3rd_party_blog_override', true ),
413 'kubioRecommendationSettings' => (object) kubio_get_recommendations_settings(),
414 'multilanguage' => array(
415 'hasTranslator' => $is_wpml_active || $is_polylang_active,
416 'isWpmlActive' => $is_wpml_active,
417 'isPolylangActive' => $is_polylang_active,
418 'polylang_add_page_translation_nonce' => wp_create_nonce( 'kubio_api_polylang_add_page_translation' ),
419 ),
420
421 'bpaNonce' => wp_create_nonce( 'bpa_wp_nonce' ),
422 ),
423 apply_filters( 'kubio/kubio-utils-data/extras', array() )
424 )
425 );
426
427 wp_add_inline_script( $handle, $data, 'before' );
428 }
429
430 if ( $handle === 'kubio-style-manager' ) {
431
432 $url = add_query_arg(
433 array(
434 'action' => 'kubio_style_manager_web_worker',
435 '_wpnonce' => wp_create_nonce( 'kubio_style_manager_web_worker_nonce' ),
436 'v' => filemtime( KUBIO_ROOT_DIR . '/defaults/style-manager-web-worker-template.js' ) . '-' . ( Utils::isDebug() ? time() : KUBIO_VERSION . '-' . $wp_version ),
437 ),
438 admin_url( 'admin-ajax.php' )
439 );
440
441 wp_add_inline_script(
442 $handle,
443 'var _kubioStyleManagerWorkerURL=' . wp_json_encode( $url ),
444 'before'
445 );
446 }
447 },
448 10,
449 2
450 );
451
452 function kubio_print_style_manager_web_worker() {
453 check_ajax_referer( 'kubio_style_manager_web_worker_nonce' );
454 header( 'content-type: application/javascript' );
455
456 $script = '';
457 $done = wp_scripts()->done;
458 ob_start();
459 wp_scripts()->done = array( 'wp-inert-polyfill', 'wp-polyfill' );
460 wp_scripts()->do_items( 'kubio-style-manager' );
461 wp_scripts()->done = $done;
462 $script = ob_get_clean();
463
464 $script = preg_replace_callback(
465 '#<script(.*?)>(.*?)</script>#s',
466 function ( $matches ) {
467 $script_attrs = Arr::get( $matches, 1, '' );
468 preg_match( "#src=(\"|')(.*?)(\"|')#", $script_attrs, $attrs_match );
469 $url = Arr::get( $attrs_match, 2, '' );
470 $content = trim( Arr::get( $matches, 2, '' ) );
471
472 $result = array();
473
474 if ( ! empty( $url ) ) {
475 $result[] = sprintf( "importScripts('%s');", $url );
476 }
477
478 if ( ! empty( $content ) ) {
479 $result[] = $content;
480 }
481
482 return trim( implode( "\n", $result ) ) . "\n\n";
483 },
484 $script
485 );
486
487 $content = file_get_contents( KUBIO_ROOT_DIR . '/defaults/style-manager-web-worker-template.js' );
488 $content = str_replace( '// {{{importScriptsPlaceholder}}}', $script, $content );
489
490 if ( ! Utils::isDebug() ) {
491 header( 'Cache-control: public' );
492 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', time() ) . ' GMT' );
493 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + YEAR_IN_SECONDS ) . ' GMT' );
494 header( 'Etag: ' . md5( $content ) );
495 }
496
497 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
498 die( $content );
499 }
500
501 add_action( 'wp_ajax_kubio_style_manager_web_worker', 'kubio_print_style_manager_web_worker' );
502
503 // quick test for safari
504 add_action(
505 'admin_init',
506 function () {
507 ob_start();
508 ?>
509 <script>
510 window.requestIdleCallback =
511 window.requestIdleCallback ||
512 function (cb) {
513 var start = Date.now();
514 return setTimeout(function () {
515 cb({
516 didTimeout: false,
517 timeRemaining: function () {
518 return Math.max(0, 50 - (Date.now() - start));
519 },
520 });
521 }, 1);
522 };
523
524 window.cancelIdleCallback =
525 window.cancelIdleCallback ||
526 function (id) {
527 clearTimeout(id);
528 };
529 </script>
530 <?php
531
532 $content = wp_strip_all_tags( ob_get_clean() );
533
534 wp_add_inline_script( 'wp-polyfill', $content, 'after' );
535 }
536 );
537
538 function kubio_defer_kubio_scripts( $tag, $handle, $src ) {
539
540 if ( is_admin() ) {
541 return $tag;
542 }
543
544 if ( strpos( $src, kubio_url() ) === 0 ) {
545 $tag = str_replace( 'src=', 'defer src=', $tag );
546 }
547
548 return $tag;
549 }
550
551 add_filter( 'script_loader_tag', 'kubio_defer_kubio_scripts', 10, 3 );
552
553 function kubio_defer_kubio_styles( $tag, $handle, $href, $media ) {
554
555 if ( is_admin() ) {
556 return $tag;
557 }
558
559 $deferrable_handles = array( 'kubio-google-fonts', 'kubio-third-party-blocks' );
560
561 if ( in_array( $handle, $deferrable_handles ) ) {
562 $tag = preg_replace( "#rel='(.*?)'#", 'rel="preload" as="style" onload="this.onload=null;this.rel=\'$1\'"', $tag );
563 // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
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