PluginProbe
JCH Optimize / trunk
JCH Optimize vtrunk
6.0.2 6.0.1 trunk 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.10.0 2.2.0 2.2.1 All 58 releases
jch-optimize / src / Admin / Settings / FieldCallbacks.php

FieldCallbacks.php in JCH Optimize trunk, at src/Admin/Settings/FieldCallbacks.php

1,117 lines 29.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * JCH Optimize - Performs several front-end optimizations for fast downloads
5 *
6 * @package jchoptimize/wordpress-platform
7 * @author Samuel Marshall <samuel@jch-optimize.net>
8 * @copyright Copyright (c) 2020 Samuel Marshall / JCH Optimize
9 * @license GNU/GPLv3, or later. See LICENSE file
10 *
11 * If LICENSE file missing, see <http://www.gnu.org/licenses/>.
12 */
13
14 namespace JchOptimize\WordPress\Admin\Settings;
15
16 use JchOptimize\Core\FeatureHelpers\ResponsiveImages;
17
18 use function __;
19 use function array_keys;
20
21 abstract class FieldCallbacks
22 {
23 ## General Tab
24
25 /*
26 General Section
27 */
28
29 public static function pro_downloadid(): void
30 {
31 ControlRenderer::render('text.pro', __FUNCTION__, '');
32 }
33
34 public static function debug(): void
35 {
36 ControlRenderer::render('switch', __FUNCTION__, '0');
37 }
38
39 public static function order_plugin(): void
40 {
41 ControlRenderer::render('switch', __FUNCTION__, '1');
42 }
43
44 public static function disable_logged_in_users(): void
45 {
46 ControlRenderer::render('switch', __FUNCTION__, '1');
47 }
48
49 /*
50 Elements Above Fold
51 */
52
53 public static function elements_above_fold_home(): void
54 {
55 ControlRenderer::render('text', __FUNCTION__, '300');
56 }
57
58 public static function elements_above_fold(): void
59 {
60 ControlRenderer::render('text', __FUNCTION__, '300');
61 }
62
63 public static function elements_above_fold_per_page(): void
64 {
65 $subfields = [
66 [
67 'name' => 'elements',
68 'type' => 'text',
69 /*'header' => 'Number of elements',*/
70 'defaultValue' => '300',
71 'class' => 'small-text bg-white'
72 ]
73 ];
74
75 ControlRenderer::render('multiselectjs', __FUNCTION__, [], 'url', 'file', 'url', $subfields);
76 }
77
78 public static function elements_above_fold_marker(): void
79 {
80 ControlRenderer::render('switch', __FUNCTION__, '0');
81 }
82
83 /*
84 Exclude Menu Urls Section
85 */
86 public static function menuexcludedurl(): void
87 {
88 ControlRenderer::render('multiselect', __FUNCTION__, [], 'url', 'file');
89 }
90
91 /*
92 Cache Storage Section
93 */
94 public static function pro_cache_storage_adapter(): void
95 {
96 $options = [
97 'filesystem' => __('Filesystem', 'jch-optimize'),
98 'apcu' => __('APCu', 'jch-optimize'),
99 'memcached' => __('Memcached', 'jch-optimize'),
100 'redis' => __('Redis', 'jch-optimize')
101 ];
102
103 $class = CacheStorageSupport::class;
104
105 $conditions = [
106 'apcu' => [$class, 'isApcuSupported'],
107 'memcached' => [$class, 'isMemcachedSupported'],
108 'redis' => [$class, 'isRedisSupported']
109 ];
110
111 ControlRenderer::render('select.pro', __FUNCTION__, 'filesystem', $options, '', $conditions);
112 }
113
114 public static function cache_lifetime(): void
115 {
116 $aOptions = [
117 '1800' => __('30 min', 'jch-optimize'),
118 '3600' => __('1 hour', 'jch-optimize'),
119 '10800' => __('3 hours', 'jch-optimize'),
120 '21600' => __('6 hours', 'jch-optimize'),
121 '43200' => __('12 hours', 'jch-optimize'),
122 '86400' => __('1 day', 'jch-optimize'),
123 '172800' => __('2 days', 'jch-optimize'),
124 '604800' => __('7 days', 'jch-optimize'),
125 '1209600' => __('2 weeks', 'jch-optimize')
126 ];
127
128 ControlRenderer::render('select', __FUNCTION__, '1800', $aOptions);
129 }
130
131 public static function memcached_server_host(): void
132 {
133 ControlRenderer::render('text.pro', __FUNCTION__, '127.0.0.1');
134 }
135
136 public static function memcached_server_port(): void
137 {
138 ControlRenderer::render('text.pro', __FUNCTION__, '11211');
139 }
140
141 public static function redis_server_host(): void
142 {
143 ControlRenderer::render('text.pro', __FUNCTION__, '127.0.0.1');
144 }
145
146 public static function redis_server_port(): void
147 {
148 ControlRenderer::render('text.pro', __FUNCTION__, '6379');
149 }
150
151 public static function redis_server_password(): void
152 {
153 ControlRenderer::render('input.pro', __FUNCTION__, '', 'password');
154 }
155
156 public static function redis_server_database(): void
157 {
158 ControlRenderer::render('text.pro', __FUNCTION__, '0');
159 }
160
161 public static function delete_expiry(): void
162 {
163 ControlRenderer::render('switch', __FUNCTION__, '1');
164 }
165
166 /*
167 Recache Section
168 */
169
170 public static function recache_base_url(): void
171 {
172 ControlRenderer::render('text.pro', __FUNCTION__, '');
173 }
174
175 public static function recache_crawl_limit(): void
176 {
177 ControlRenderer::render('text.pro', __FUNCTION__, '100');
178 }
179
180 public static function recache_concurrency(): void
181 {
182 ControlRenderer::render('text.pro', __FUNCTION__, '10');
183 }
184
185 public static function recache_max_depth(): void
186 {
187 ControlRenderer::render('text.pro', __FUNCTION__, '3');
188 }
189
190 public static function recache_delete_cache(): void
191 {
192 ControlRenderer::render('switch.pro', __FUNCTION__, '1');
193 }
194
195 public static function recache_frequency(): void
196 {
197 $options = [
198 '0' => __('Disabled', 'jch-optimize'),
199 '1' => __('On save only', 'jch-optimize'),
200 'hourly' => __('Hourly', 'jch-optimize'),
201 'twicedaily' => __('Twice Daily', 'jch-optimize'),
202 'daily' => __('Daily', 'jch-optimize'),
203 ];
204
205 ControlRenderer::render('select.pro', __FUNCTION__, '1', $options);
206 }
207
208 ## Combine Files tab
209
210 /*
211 Combine CSS/Js Section
212 */
213
214 public static function combine_files_enable(): void
215 {
216 ControlRenderer::render('switch', __FUNCTION__, '1');
217 }
218
219 public static function combine_files(): void
220 {
221 ControlRenderer::render('switch', __FUNCTION__, '0');
222 }
223
224 public static function smart_combine(): void
225 {
226 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
227 }
228
229 public static function try_catch(): void
230 {
231 ControlRenderer::render('switch', __FUNCTION__, '1');
232 }
233
234 public static function html_minify_level(): void
235 {
236 $aOptions = [
237 '0' => __('Basic', 'jch-optimize'),
238 '1' => __('Advanced', 'jch-optimize'),
239 '2' => __('Ultra', 'jch-optimize')
240 ];
241
242 ControlRenderer::render('select', __FUNCTION__, '0', $aOptions);
243 }
244
245 public static function htaccess(): void
246 {
247 $aOptions = [
248 '2' => __('Static css and js files', 'jch-optimize'),
249 '0' => __('PHP file with query', 'jch-optimize'),
250 '1' => __('PHP using url re-write', 'jch-optimize'),
251 '3' => __('PHP using url re-write (Without Options +FollowSymLinks)', 'jch-optimize'),
252 ];
253
254 ControlRenderer::render('select', __FUNCTION__, '2', $aOptions);
255 }
256
257 /*
258 Combine Files Automatic Section
259 */
260
261 public static function gzip(): void
262 {
263 ControlRenderer::render('switch', __FUNCTION__, '0');
264 }
265
266 public static function html_minify(): void
267 {
268 ControlRenderer::render('switch', __FUNCTION__, '0');
269 }
270
271 public static function includeAllExtensions(): void
272 {
273 ControlRenderer::render('switch', __FUNCTION__, '0');
274 }
275
276 public static function phpAndExternal(): void
277 {
278 ControlRenderer::render('switch', __FUNCTION__, '0');
279 }
280
281 ## CSS Tab
282
283 /*
284 CSS Automatic Settings Section
285 */
286
287 public static function css(): void
288 {
289 ControlRenderer::render('switch', __FUNCTION__, '1');
290 }
291
292 public static function css_minify(): void
293 {
294 ControlRenderer::render('switch', __FUNCTION__, '0');
295 }
296
297 public static function replaceImports(): void
298 {
299 ControlRenderer::render('switch', __FUNCTION__, '0');
300 }
301
302 public static function inlineStyle(): void
303 {
304 ControlRenderer::render('switch', __FUNCTION__, '0');
305 }
306
307 /*
308 Exclude CSS Files section
309 */
310
311 public static function excludeCss(): void
312 {
313 ControlRenderer::render('multiselect', __FUNCTION__, [], 'css', 'file');
314 }
315
316 public static function excludeCssComponents(): void
317 {
318 ControlRenderer::render('multiselect', __FUNCTION__, [], 'css', 'extension');
319 }
320
321 public static function excludeStyles(): void
322 {
323 ControlRenderer::render('multiselect', __FUNCTION__, [], 'css', 'style');
324 }
325
326 public static function excludeAllStyles(): void
327 {
328 ControlRenderer::render('switch', __FUNCTION__, '0');
329 }
330
331 /*
332 Remove CSS Files section
333 */
334
335 public static function remove_css(): void
336 {
337 ControlRenderer::render('multiselect', __FUNCTION__, [], 'css', 'file');
338 }
339
340 /*
341 Custom CSS section
342 */
343 public static function custom_css_enable(): void
344 {
345 ControlRenderer::render('switch', __FUNCTION__, '0');
346 }
347
348 public static function custom_css(): void
349 {
350 ControlRenderer::render('textarea', __FUNCTION__, '');
351 }
352
353 public static function mobile_css(): void
354 {
355 ControlRenderer::render('textarea', __FUNCTION__, '');
356 }
357
358 public static function desktop_css(): void
359 {
360 ControlRenderer::render('textarea', __FUNCTION__, '');
361 }
362
363 /*
364 Optimize CSS Delivery Section
365 */
366
367 public static function optimizeCssDelivery_enable(): void
368 {
369 ControlRenderer::render('switch', __FUNCTION__, '0');
370 }
371
372 public static function pro_reduce_unused_css(): void
373 {
374 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
375 }
376
377 public static function pro_dynamic_selectors(): void
378 {
379 ControlRenderer::render('multiselect', __FUNCTION__, [], 'selectors', 'style');
380 }
381
382 public static function dynamic_css_selectors(): void
383 {
384 ControlRenderer::render('multiselect', __FUNCTION__, [], 'selectors', 'style');
385 }
386
387 public static function critical_css_configure_helper(): void
388 {
389 ControlRenderer::render('switch', __FUNCTION__, '0');
390 }
391 ## JavaScript Tab
392
393 /*
394 JavaScript Automatic Settings Section
395 */
396
397 public static function javascript(): void
398 {
399 ControlRenderer::render('switch', __FUNCTION__, '1');
400 }
401
402 public static function js_minify(): void
403 {
404 ControlRenderer::render('switch', __FUNCTION__, '0');
405 }
406
407 public static function inlineScripts(): void
408 {
409 ControlRenderer::render('switch', __FUNCTION__, '0');
410 }
411
412 public static function bottom_js(): void
413 {
414 ControlRenderer::render('switch', __FUNCTION__, '0');
415 }
416
417 public static function loadAsynchronous(): void
418 {
419 ControlRenderer::render('switch', __FUNCTION__, '0');
420 }
421
422 /*
423 Exclude JavaScript Files
424 */
425
426 public static function excludeJs_peo(): void
427 {
428 $subfields = [
429 ['name' => 'ieo', 'type' => 'checkbox', 'header' => 'Ignore execution order',],
430 ['name' => 'dontmove', 'type' => 'checkbox', 'header' => 'Don\'t move to bottom',]
431 ];
432
433 ControlRenderer::render('multiselectjs', __FUNCTION__, [], 'js', 'file', 'url', $subfields);
434 }
435
436 public static function excludeJsComponents_peo(): void
437 {
438 $subfields = [
439 ['name' => 'ieo', 'type' => 'checkbox', 'header' => 'Ignore execution order',],
440 ['name' => 'dontmove', 'type' => 'checkbox', 'header' => 'Don\'t move to bottom',]
441 ];
442
443 ControlRenderer::render('multiselectjs', __FUNCTION__, [], 'js', 'extension', 'url', $subfields);
444 }
445
446 public static function excludeScripts_peo(): void
447 {
448 $subfields = [
449 ['name' => 'ieo', 'type' => 'checkbox', 'header' => 'Ignore execution order',],
450 ['name' => 'dontmove', 'type' => 'checkbox', 'header' => 'Don\'t move to bottom',]
451 ];
452
453 ControlRenderer::render('multiselectjs', __FUNCTION__, [], 'js', 'script', 'script', $subfields);
454 }
455
456 public static function excludeAllScripts(): void
457 {
458 ControlRenderer::render('switch', __FUNCTION__, '0');
459 }
460
461 /*
462 Remove JavaScript Files Section
463 */
464 public static function remove_js(): void
465 {
466 ControlRenderer::render('multiselect', __FUNCTION__, [], 'js', 'file');
467 }
468
469 /*
470 Reduce Unused JavaScript Section
471 */
472
473 public static function pro_reduce_unused_js_enable(): void
474 {
475 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
476 }
477
478 public static function pro_criticalJs(): void
479 {
480 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'criticaljs', 'file');
481 }
482
483 public static function pro_criticalScripts(): void
484 {
485 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'js', 'script');
486 }
487
488 public static function pro_criticalModules(): void
489 {
490 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'modules', 'file');
491 }
492
493 public static function pro_criticalModulesScripts(): void
494 {
495 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'modulesScripts', 'script');
496 }
497
498 public static function critical_js_configure_helper(): void
499 {
500 ControlRenderer::render('criticaljsmodalbutton.pro', __FUNCTION__, '');
501 }
502
503 ## Page Cache Tab
504
505 /*
506 Page Cache Section
507 */
508
509 public static function cache_enable(): void
510 {
511 ControlRenderer::render('switch', __FUNCTION__, '0');
512 }
513
514 public static function pro_cache_platform(): void
515 {
516 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
517 }
518
519 public static function page_cache_exclude_form_users(): void
520 {
521 ControlRenderer::render('switch', __FUNCTION__, '1');
522 }
523
524 public static function page_cache_browser_caching(): void
525 {
526 ControlRenderer::render('switch', __FUNCTION__, '0');
527 }
528
529 public static function page_cache_lifetime(): void
530 {
531 $aOptions = [
532 '900' => __('15 min', 'jch-optimize'),
533 '1800' => __('30 min', 'jch-optimize'),
534 '3600' => __('1 hour', 'jch-optimize'),
535 '10800' => __('3 hours', 'jch-optimize'),
536 '21600' => __('6 hours', 'jch-optimize'),
537 '43200' => __('12 hours', 'jch-optimize'),
538 '86400' => __('1 day', 'jch-optimize'),
539 '172800' => __('2 days', 'jch-optimize'),
540 '604800' => __('1 week', 'jch-optimize')
541 ];
542
543 ControlRenderer::render('select', __FUNCTION__, '900', $aOptions);
544 }
545
546 public static function cache_exclude(): void
547 {
548 //We're using class as the last argument to be able to include '?' in the multiselect box
549 ControlRenderer::render('multiselect', __FUNCTION__, [], 'url', 'class');
550 }
551
552 public static function page_cache_ignore_query_values(): void
553 {
554 ControlRenderer::render('multiselect', __FUNCTION__, [], 'url', 'class');
555 }
556
557 public static function pro_capture_cache_enable(): void
558 {
559 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
560 }
561
562 /*
563 Cloudflare Cache Purge Section
564 */
565
566 public static function cf_enable(): void
567 {
568 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
569 }
570
571 public static function cf_api_token(): void
572 {
573 ControlRenderer::render('verifycftoken.pro', __FUNCTION__, '');
574 }
575
576 public static function cf_zone_id(): void
577 {
578 ControlRenderer::render('text.pro', __FUNCTION__, '');
579 }
580
581 public static function cf_mode_switcher_integration(): void
582 {
583 ControlRenderer::render('switch.pro', __FUNCTION__, '1');
584 }
585
586 ## Media Tab
587
588 /*
589 Add Image Attributes Section
590 */
591
592 public static function img_attributes_enable(): void
593 {
594 ControlRenderer::render('switch', __FUNCTION__, '0');
595 }
596
597 /*
598 Sprite Generator Section
599 */
600
601 public static function csg_enable(): void
602 {
603 ControlRenderer::render('switch', __FUNCTION__, '0');
604 }
605
606 public static function csg_direction(): void
607 {
608 $aOptions = [
609 'vertical' => __('vertical', 'jch-optimize'),
610 'horizontal' => __('horizontal', 'jch-optimize')
611 ];
612
613 ControlRenderer::render('select', __FUNCTION__, 'vertical', $aOptions);
614 }
615
616 public static function csg_wrap_images(): void
617 {
618 ControlRenderer::render('switch', __FUNCTION__, '0');
619 }
620
621 public static function csg_exclude_images(): void
622 {
623 ControlRenderer::render('multiselect', __FUNCTION__, [], 'images', 'file');
624 }
625
626 public static function csg_include_images(): void
627 {
628 ControlRenderer::render('multiselect', __FUNCTION__, [], 'images', 'file');
629 }
630
631 /*
632 Lazy Load Images Section
633 */
634
635 public static function lazyload_enable(): void
636 {
637 ControlRenderer::render('switch', __FUNCTION__, '0');
638 }
639
640 public static function pro_lazyload_iframe(): void
641 {
642 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
643 }
644
645 public static function pro_lazyload_audiovideo(): void
646 {
647 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
648 }
649
650 public static function pro_lazyload_bgimages(): void
651 {
652 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
653 }
654
655 public static function excludeLazyLoad(): void
656 {
657 ControlRenderer::render('multiselect', __FUNCTION__, [], 'lazyload', 'file');
658 }
659
660 public static function pro_excludeLazyLoadFolders(): void
661 {
662 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'lazyload', 'folder');
663 }
664
665 public static function pro_excludeLazyLoadClass(): void
666 {
667 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'lazyload', 'class');
668 }
669
670 public static function includeLazyLoad(): void
671 {
672 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'lazyload', 'file');
673 }
674
675 public static function includeLazyLoadFolders(): void
676 {
677 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'lazyload', 'folder');
678 }
679
680 public static function includeLazyLoadClass(): void
681 {
682 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'lazyload', 'class');
683 }
684
685 ## Preloads Tab
686
687 /*
688 HTTP/2 Preload
689 */
690
691 public static function http2_push_enable(): void
692 {
693 ControlRenderer::render('switch', __FUNCTION__, '0');
694 }
695
696 public static function pro_http2_preload_modules(): void
697 {
698 ControlRenderer::render('switch.pro', __FUNCTION__, '1');
699 }
700
701 public static function pro_http2_file_types(): void
702 {
703 $aOptions = [
704 'style' => 'style',
705 'script' => 'script',
706 'font' => 'font',
707 'image' => 'image'
708 ];
709
710 ControlRenderer::render('checkboxes', __FUNCTION__, array_keys($aOptions), $aOptions);
711 }
712
713 public static function pro_http2_include(): void
714 {
715 $subfields = [
716 [
717 'name' => 'crossorigin',
718 'type' => 'select',
719 'header' => 'Crossorigin',
720 'options' => [
721 ['value' => '', 'text' => '- None -'],
722 ['value' => 'anonymous', 'text' => 'anonymous'],
723 ['value' => 'use-credentials', 'text' => 'use-credentials'],
724 ],
725 'legacy' => ['anonymous', 'use-credentials'],
726 'class' => 'bg-white'
727 ]
728 /* ['name' => 'anonymous', 'type' => 'checkbox', 'header' => 'Crossorigin: \'anonymous\''],
729 ['name' => 'use-credentials', 'type' => 'checkbox', 'header' => '\'use-credentials\''] */
730 ];
731
732 ControlRenderer::render(
733 'multiselectjs.pro',
734 __FUNCTION__,
735 [],
736 'http2',
737 'file',
738 'url',
739 $subfields,
740 'only-one'
741 );
742 }
743
744 public static function pro_http2_exclude(): void
745 {
746 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'http2', 'file');
747 }
748
749 /*
750 Largest Contentful Paint Images
751 */
752
753 public static function pro_lcp_images_enable(): void
754 {
755 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
756 }
757
758 public static function pro_lcp_images(): void
759 {
760 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'lazyload', 'file');
761 }
762
763 public static function pro_lcp_identifiers(): void
764 {
765 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'lazyload', 'file');
766 }
767
768 public static function lcp_images_mobile(): void
769 {
770 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'lazyload', 'file');
771 }
772
773 public static function lcp_images_desktop(): void
774 {
775 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'lazyload', 'file');
776 }
777
778 /*
779 Optimize Fonts Section
780 */
781
782 public static function pro_optimizeFonts_enable(): void
783 {
784 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
785 }
786
787 public static function pro_force_swap_policy(): void
788 {
789 ControlRenderer::render('switch.pro', __FUNCTION__, '1');
790 }
791
792 public static function pro_optimize_font_files(): void
793 {
794 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'css', 'file');
795 }
796
797 /*
798 Preconnect Third-party
799 */
800
801 public static function pro_preconnect_domains_enable(): void
802 {
803 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
804 }
805
806 public static function pro_preconnect_domains(): void
807 {
808 $subfields = [
809 [
810 'name' => 'crossorigin',
811 'type' => 'select',
812 'header' => 'Crossorigin',
813 'options' => [
814 ['value' => '', 'text' => '- None -'],
815 ['value' => 'anonymous', 'text' => 'anonymous'],
816 ['value' => 'use-credentials', 'text' => 'use-credentials'],
817 ],
818 'legacy' => ['anonymous', 'use-credentials'],
819 'class' => 'bg-white'
820 ],
821 /* ['name' => 'anonymous', 'type' => 'checkbox', 'header' => 'Crossorigin: \'anonymous\''],
822 ['name' => 'use-credentials', 'type' => 'checkbox', 'header' => '\'use-credentials\'']*/
823 ];
824
825 ControlRenderer::render(
826 'multiselectjs.pro',
827 __FUNCTION__,
828 [],
829 'origin',
830 'origin',
831 'url',
832 $subfields,
833 'only-one'
834 );
835 }
836
837 public static function dns_prefetch_domains(): void
838 {
839 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'origin', 'origin');
840 }
841
842 ## CDN Tab
843
844 /*
845 CDN Section
846 */
847
848 public static function cookielessdomain_enable(): void
849 {
850 ControlRenderer::render('switch', __FUNCTION__, '0');
851 }
852
853 public static function cdn_scheme(): void
854 {
855 $aOptions = [
856 '0' => __('scheme relative', 'jch-optimize'),
857 '1' => __('http', 'jch-optimize'),
858 '2' => __('https', 'jch-optimize')
859 ];
860
861 ControlRenderer::render('select', __FUNCTION__, '0', $aOptions);
862 }
863
864 public static function cookielessdomain(): void
865 {
866 ControlRenderer::render('text', __FUNCTION__, '');
867 }
868
869 public static function staticfiles(): void
870 {
871 ControlRenderer::render('checkboxes', __FUNCTION__, array_keys(self::staticFilesArray()), self::staticFilesArray());
872 }
873
874 /**
875 * @return array<string, string>
876 */
877 private static function staticFilesArray(): array
878 {
879 return [
880 'css' => 'css',
881 'png' => 'png',
882 'gif' => 'gif',
883 'ico' => 'ico',
884 'pdf' => 'pdf',
885 'js' => 'js',
886 'jpe?g' => 'jp(e)g',
887 'bmp' => 'bmp',
888 'webp' => 'webp',
889 'svg' => 'svg'
890 ];
891 }
892
893 public static function pro_customcdnextensions(): void
894 {
895 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'url', 'file');
896 }
897
898 public static function pro_cookielessdomain_2(): void
899 {
900 ControlRenderer::render('text.pro', __FUNCTION__, '');
901 }
902
903 public static function pro_staticfiles_2(): void
904 {
905 ControlRenderer::render('checkboxes.pro', __FUNCTION__, array_keys(self::staticFilesArray()), self::staticFilesArray());
906 }
907
908 public static function pro_cookielessdomain_3(): void
909 {
910 ControlRenderer::render('text.pro', __FUNCTION__, '');
911 }
912
913 public static function pro_staticfiles_3(): void
914 {
915 ControlRenderer::render('checkboxes.pro', __FUNCTION__, array_keys(self::staticFilesArray()), self::staticFilesArray());
916 }
917
918 ## Optimize Images Tab
919
920 /*
921 Global Options Section
922 */
923
924 public static function ignore_optimized(): void
925 {
926 ControlRenderer::render('switch', __FUNCTION__, '1');
927 }
928
929 /*
930 Next Generation Images Section
931 */
932
933 public static function pro_next_gen_images(): void
934 {
935 ControlRenderer::render('switch.pro', __FUNCTION__, '1');
936 }
937
938 public static function gen_avif_images(): void
939 {
940 ControlRenderer::render('switch.pro', __FUNCTION__, '1');
941 }
942
943 public static function load_avif_webp_images(): void
944 {
945 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
946 }
947
948 public static function pro_web_old_browsers(): void
949 {
950 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
951 }
952
953 public static function pro_load_webp_images(): void
954 {
955 ControlRenderer::render('switch.pro', __FUNCTION__, '1');
956 }
957
958 public static function load_avif_images(): void
959 {
960 ControlRenderer::render('switch.pro', __FUNCTION__, '1');
961 }
962
963 /*
964 Responsive Image Section
965 */
966 public static function pro_gen_responsive_images(): void
967 {
968 ControlRenderer::render('switch.pro', __FUNCTION__, '1');
969 }
970
971 public static function pro_load_responsive_images(): void
972 {
973 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
974 }
975
976 public static function cropgravity(): void
977 {
978 if (JCH_PRO) {
979 $subfields = [
980 [
981 'name' => 'gravity',
982 'type' => 'select',
983 'header' => 'Position',
984 'options' => [
985 ['value' => 'West', 'text' => 'Left', 'selected' => false],
986 ['value' => 'Center', 'text' => 'Center', 'selected' => true],
987 ['value' => 'East', 'text' => 'Right', 'selected' => false],
988 ],
989 'class' => 'bg-white'
990 ],
991 [
992 'name' => 'cropwidth',
993 'type' => 'text',
994 'header' => 'Width (px)',
995 'defaultValue' => ResponsiveImages::$breakpoints[0],
996 'class' => 'small-text bg-white'
997 ]
998 ];
999 } else {
1000 $subfields = [];
1001 }
1002
1003 ControlRenderer::render(
1004 'multiselectjs.pro',
1005 __FUNCTION__,
1006 [],
1007 'lazyload',
1008 'file',
1009 'url',
1010 $subfields
1011 );
1012 }
1013
1014 /*
1015 Optimization Configuration Section
1016 */
1017 public static function lossy(): void
1018 {
1019 ControlRenderer::render('switch', __FUNCTION__, '1');
1020 }
1021
1022 public static function save_metadata(): void
1023 {
1024 ControlRenderer::render('switch', __FUNCTION__, '0');
1025 }
1026
1027 /*
1028 Upload Setting Section
1029 */
1030 public static function pro_api_concurrency(): void
1031 {
1032 ControlRenderer::render('text.pro', __FUNCTION__, '2');
1033 }
1034
1035 public static function pro_api_num_files(): void
1036 {
1037 ControlRenderer::render('text.pro', __FUNCTION__, '');
1038 }
1039
1040 public static function pro_api_max_size(): void
1041 {
1042 ControlRenderer::render('text.pro', __FUNCTION__, '2M');
1043 }
1044
1045 public static function api_connection_timeout(): void
1046 {
1047 ControlRenderer::render('text.pro', __FUNCTION__, '30');
1048 }
1049
1050 /*
1051 Optimize Images By URLs Section
1052 */
1053
1054 public static function pro_api_resize_mode(): void
1055 {
1056 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
1057 }
1058
1059 /*
1060 Optimize Images By Folders Section
1061 */
1062
1063 public static function recursive(): void
1064 {
1065 ControlRenderer::render('switch', __FUNCTION__, '1');
1066 }
1067
1068 ## Miscellaneous Tab
1069
1070 /*
1071 Reduce DOM Section
1072 */
1073
1074 public static function pro_reduce_dom(): void
1075 {
1076 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
1077 }
1078
1079 public static function pro_html_sections(): void
1080 {
1081 $options = [
1082 'header' => 'header',
1083 'nav' => 'nav',
1084 'main' => 'main',
1085 'article' => 'article',
1086 'section' => 'section',
1087 'aside' => 'aside',
1088 'footer' => 'footer',
1089 ];
1090
1091 ControlRenderer::render('checkboxes.pro', __FUNCTION__, array_keys($options), $options);
1092 }
1093
1094 public static function reduce_dom_identifiers(): void
1095 {
1096 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'reducedom', 'class');
1097 }
1098
1099 public static function reduce_dom_exclude_identifiers(): void
1100 {
1101 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'reducedom', 'class');
1102 }
1103
1104 public static function reduce_dom_above_fold_identifiers(): void
1105 {
1106 ControlRenderer::render('multiselect.pro', __FUNCTION__, [], 'reducedom', 'class');
1107 }
1108
1109 /*
1110 Mode Switcher Menu Section
1111 */
1112 public static function pro_disableModeSwitcher(): void
1113 {
1114 ControlRenderer::render('switch.pro', __FUNCTION__, '0');
1115 }
1116 }
1117