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