PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.2.3
Kubio AI Page Builder v1.2.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
admin-pages 4 years ago api 4 years ago blog 4 years ago filters 4 years ago full-site-editing 4 years ago importer 4 years ago integrations 4 years ago menu 4 years ago polyfills 4 years ago preview 4 years ago shapes 4 years ago shortcodes 4 years ago src 4 years ago add-edit-in-kubio.php 4 years ago editor-assets.php 4 years ago env.php 4 years ago filters.php 4 years ago frontend.php 4 years ago global-data.php 4 years ago init.php 4 years ago kubio-block-library.php 4 years ago kubio-editor.php 4 years ago load.php 4 years ago
editor-assets.php
442 lines
1 <?php
2
3 use IlluminateAgnostic\Arr\Support\Arr;
4 use Kubio\Core\Utils;
5
6 function kubio_override_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
7 $script = $scripts->query( $handle, 'registered' );
8 if ( $script ) {
9
10 $script->src = $src;
11 $script->deps = $deps;
12 $script->ver = $ver;
13 $script->args = $in_footer;
14
15 unset( $script->extra['group'] );
16 if ( $in_footer ) {
17 $script->add_data( 'group', 1 );
18 }
19 } else {
20 $scripts->add( $handle, $src, $deps, $ver, $in_footer );
21 }
22
23 if ( in_array( 'wp-i18n', $deps, true ) ) {
24 $scripts->set_translations( $handle, 'kubio' );
25 }
26 }
27
28 function kubio_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
29 $style = $styles->query( $handle, 'registered' );
30 if ( $style ) {
31 $styles->remove( $handle );
32 }
33 $styles->add( $handle, $src, $deps, $ver, $media );
34 }
35
36 function kubio_register_kubio_scripts_scripts_dependencies( $version ) {
37 $scripts = array(
38 array(
39 'handle' => 'typed',
40 'deps' => array( 'jquery' ),
41 'src' => 'typed.js',
42 ),
43 array(
44 'handle' => 'fancybox',
45 'deps' => array( 'jquery' ),
46 'src' => 'fancybox/jquery.fancybox.min.js',
47 ),
48 array(
49 'handle' => 'swiper',
50 'deps' => array( 'jquery' ),
51 'src' => 'swiper/js/swiper.js',
52 ),
53 );
54
55 $script_handles = array();
56
57 foreach ( $scripts as $script ) {
58 $handle = "kubio-scripts-dep-{$script['handle']}";
59 $script_handles[ $handle ] = array(
60 $handle,
61 kubio_url( "/static/{$script['src']}" ),
62 $script['deps'],
63 $version,
64 true,
65 );
66 }
67
68 return $script_handles;
69 }
70
71 function kubio_register_packages_scripts() {
72
73 $registered = array();
74
75 $paths = glob( KUBIO_ROOT_DIR . 'build/*/index.js' );
76 foreach ( $paths as $path ) {
77 $handle = 'kubio-' . basename( dirname( $path ) );
78 $asset_file = substr( $path, 0, - 3 ) . '.asset.php';
79 $asset = file_exists( $asset_file )
80 ? require( $asset_file )
81 : null;
82 $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
83
84 if ( Utils::isDebug() ) {
85 $version = uniqid( time() . '-' );
86 } else {
87 $version = isset( $asset['version'] ) ? $asset['version'] : filemtime( $path );
88 }
89
90 switch ( $handle ) {
91 case 'kubio-editor':
92 array_push( $dependencies, 'wp-dom-ready', 'editor' );
93 break;
94
95 case 'kubio-format-library':
96 array_push( $dependencies, 'wp-format-library' );
97 break;
98
99 case 'kubio-scripts':
100 $extra_scripts = kubio_register_kubio_scripts_scripts_dependencies( $version );
101 $registered = array_merge( $registered, $extra_scripts );
102 $extra_deps = array_keys( $extra_scripts );
103 $dependencies = array_merge( $dependencies, $extra_deps, array( 'jquery', 'jquery-masonry' ) );
104 $dependencies = array_diff( $dependencies, array( 'wp-polyfill' ) );
105 break;
106
107 case 'kubio-frontend':
108 $dependencies = array( 'kubio-scripts' );
109 break;
110
111 case 'kubio-block-library':
112 array_push( $dependencies, 'kubio-format-library' );
113 break;
114
115 case 'kubio-block-editor':
116 array_push( $dependencies, 'wp-block-editor', 'wp-block-directory' );
117 break;
118
119 }
120
121 $kubio_path = substr( $path, strlen( KUBIO_ROOT_DIR ) );
122
123 $registered[] = array(
124 $handle,
125 kubio_url( $kubio_path ),
126 $dependencies,
127 $version,
128 true,
129 );
130 }
131
132 foreach ( $registered as $script ) {
133
134 if ( is_array( $script ) && count( $script ) >= 2 ) {
135 $handle = $script[0];
136 $deps = $script[2];
137 if ( in_array( 'wp-i18n', $deps, true ) ) {
138 wp_set_script_translations( $handle, 'kubio' );
139 }
140
141 call_user_func_array( 'wp_register_script', $script );
142 do_action( 'kubio_registered_script', $script[0], $script[3] );
143 }
144 }
145
146 do_action( 'kubio_scripts_registered', $registered );
147 }
148
149
150 function kubio_replace_default_scripts( $scripts ) {
151
152 if ( ! kubio_is_kubio_editor_page() ) {
153 return;
154 }
155
156 $to_replace = array(
157 'wp-block-editor' => 'block-editor',
158 );
159
160 foreach ( $to_replace as $old => $new ) {
161 $script_path = KUBIO_ROOT_DIR . "/build/{$new}/index.js";
162 $asset_file = KUBIO_ROOT_DIR . "/build/{$new}/index.asset.php";
163
164 $asset = file_exists( $asset_file )
165 ? require( $asset_file )
166 : null;
167 $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
168 $version = isset( $asset['version'] ) ? $asset['version'] : filemtime( $script_path );
169
170 kubio_override_script(
171 $scripts,
172 $old,
173 kubio_url( "/build/{$new}/index.js" ),
174 $dependencies,
175 $version,
176 true
177 );
178 }
179
180 }
181
182
183 function kubio_register_kubio_block_library__style_dependencies( $version ) {
184 $styles = array(
185 array(
186 'handle' => 'fancybox',
187 'src' => 'fancybox/jquery.fancybox.min.css',
188 ),
189 array(
190 'handle' => 'swiper',
191 'src' => 'swiper/css/swiper.min.css',
192 ),
193 );
194
195 $handles = array();
196
197 foreach ( $styles as $style ) {
198 $handle = "kubio-block-library-dep-{$style['handle']}";
199 $handles[ $handle ] = array(
200 $handle,
201 kubio_url( "/static/{$style['src']}" ),
202 isset( $style['deps'] ) ? $style['deps'] : array(),
203 $version,
204 );
205 }
206
207 return $handles;
208 }
209
210
211 function kubio_register_packages_styles() {
212
213 $registered = array();
214
215 foreach ( glob( KUBIO_ROOT_DIR . 'build/*/style.css' ) as $path ) {
216 $handle = 'kubio-' . basename( dirname( $path ) );
217 $kubio_path = substr( $path, strlen( KUBIO_ROOT_DIR ) );
218 $version = filemtime( $path );
219 $dependencies = array();
220
221 switch ( $handle ) {
222 case 'kubio-editor':
223 $dependencies = array( 'wp-edit-blocks' );
224 break;
225
226 case 'kubio-format-library':
227 array_push( $dependencies, 'wp-format-library' );
228 break;
229
230 case 'kubio-admin-panel':
231 array_push( $dependencies, 'kubio-utils' );
232 break;
233
234 case 'kubio-block-library':
235 $extra_styles = kubio_register_kubio_block_library__style_dependencies( $version );
236 $registered = array_merge( $registered, $extra_styles );
237 $extra_deps = array_keys( $extra_styles );
238 $dependencies = array_merge( $dependencies, $extra_deps, array( 'wp-block-library' ) );
239 break;
240 }
241
242 $registered[] = array(
243 $handle,
244 kubio_url( $kubio_path ),
245 $dependencies,
246 $version,
247 );
248 }
249
250 foreach ( glob( KUBIO_ROOT_DIR . 'build/*/editor.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-block-library':
262 $dependencies = array( /* 'wp-block-library' */ );
263 break;
264 }
265
266 $registered[] = array(
267 "{$handle}-editor",
268 kubio_url( $kubio_path ),
269 $dependencies,
270 $version,
271 );
272 }
273
274 foreach ( $registered as $style ) {
275
276 if ( is_array( $style ) && count( $style ) >= 2 ) {
277
278 call_user_func_array( 'wp_register_style', $style );
279
280 }
281 }
282 }
283
284
285 function kubio_replace_default_styles( $styles ) {
286
287 if ( ! kubio_is_kubio_editor_page() ) {
288 return;
289 }
290
291 // Editor Styles .
292 kubio_override_style(
293 $styles,
294 'wp-block-editor',
295 kubio_url( 'build/block-editor/style.css' ),
296 array( 'wp-components', 'wp-editor-font' ),
297 filemtime( KUBIO_ROOT_DIR . 'build/editor/style.css' )
298 );
299 $styles->add_data( 'wp-block-editor', 'rtl', 'replace' );
300
301 }
302
303 add_action( 'init', 'kubio_register_packages_scripts' );
304 add_action( 'init', 'kubio_register_packages_styles' );
305
306 add_action( 'wp_default_styles', 'kubio_replace_default_styles' );
307 add_action( 'wp_default_scripts', 'kubio_replace_default_scripts' );
308
309
310 add_action(
311 'kubio_registered_script',
312 function ( $handle, $version ) {
313 if ( $handle === 'kubio-utils' || $handle === 'kubio-admin-panel' ) {
314 $data = 'window.kubioUtilsData=' . wp_json_encode(
315 array_merge(
316 kubio_get_site_urls(),
317 array(
318
319 'defaultAssetsUrl' => kubio_url( 'static/default-assets' ),
320 'patternsAssetsUrl' => kubio_url( 'static/patterns' ),
321 'kubioRemoteContentFile' => 'https://static-assets.kubiobuilder.com/content-2022-03-14.json',
322 'kubioLocalContentFile' => kubio_url( 'static/patterns/content-converted.json' ),
323 'kubioEditorURL' => add_query_arg( 'page', 'kubio', admin_url( 'admin.php' ) ),
324 'patternsOnTheFly' =>
325 ( defined( 'KUBIO_PATTERNS_ON_THE_FLY' ) && KUBIO_PATTERNS_ON_THE_FLY )
326 ? KUBIO_PATTERNS_ON_THE_FLY
327 : '',
328 'base_url' => site_url(),
329 'admin_url' => admin_url(),
330 'admin_plugins_url' => admin_url( 'plugins.php' ),
331 )
332 )
333 );
334
335 wp_add_inline_script( $handle, $data, 'before' );
336 }
337
338 if ( $handle === 'kubio-style-manager' ) {
339
340 $url = add_query_arg(
341 array(
342 'action' => 'kubio_style_manager_web_worker',
343 'v' => $version,
344 ),
345 admin_url( 'admin-ajax.php' )
346 );
347
348 wp_add_inline_script(
349 $handle,
350 'var _kubioStyleManagerWorkerURL=' . wp_json_encode( $url ),
351 'before'
352 );
353 }
354 },
355 10,
356 2
357 );
358
359 function kubio_print_style_manager_web_worker() {
360 header( 'content-type: application/javascript' );
361
362 $script = '';
363 $done = wp_scripts()->done;
364 ob_start();
365 wp_scripts()->done = array();
366 wp_scripts()->do_items( 'kubio-style-manager' );
367 wp_scripts()->done = $done;
368 $script = ob_get_clean();
369
370 $script = preg_replace_callback(
371 '#<script(.*?)>(.*?)</script>#s',
372 function( $matches ) {
373 $script_attrs = Arr::get( $matches, 1, '' );
374 preg_match( "#src='(.*?)'#", $script_attrs, $attrs_match );
375 $url = Arr::get( $attrs_match, 1, '' );
376 $content = trim( Arr::get( $matches, 2, '' ) );
377
378 $result = array();
379
380 if ( ! empty( $url ) ) {
381 $result[] = sprintf( "importScripts('%s');", $url );
382 }
383
384 if ( ! empty( $content ) ) {
385 $result[] = $content;
386 }
387
388 return trim( implode( "\n", $result ) ) . "\n\n";
389 },
390 $script
391 );
392
393 $content = file_get_contents( KUBIO_ROOT_DIR . '/defaults/style-manager-web-worker-template.js' );
394 $content = str_replace( '// {{{importScriptsPlaceholder}}}', $script, $content );
395
396 if ( ! Utils::isDebug() ) {
397 header( 'Cache-control: public' );
398 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', time() ) . ' GMT' );
399 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + YEAR_IN_SECONDS ) . ' GMT' );
400 header( 'Etag: ' . md5( $content ) );
401 }
402
403 die( $content );
404 }
405
406 add_action( 'wp_ajax_kubio_style_manager_web_worker', 'kubio_print_style_manager_web_worker' );
407
408 // quick test for safari
409 add_action(
410 'admin_init',
411 function () {
412 ob_start();
413 ?>
414 <script>
415 window.requestIdleCallback =
416 window.requestIdleCallback ||
417 function (cb) {
418 var start = Date.now();
419 return setTimeout(function () {
420 cb({
421 didTimeout: false,
422 timeRemaining: function () {
423 return Math.max(0, 50 - (Date.now() - start));
424 },
425 });
426 }, 1);
427 };
428
429 window.cancelIdleCallback =
430 window.cancelIdleCallback ||
431 function (id) {
432 clearTimeout(id);
433 };
434 </script>
435 <?php
436
437 $content = strip_tags( ob_get_clean() );
438
439 wp_add_inline_script( 'wp-polyfill', $content, 'after' );
440 }
441 );
442