-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
2668 lines (2248 loc) · 64.3 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Configure 8 options configuration plugin
*
* @package Configure 8 Options
* @subpackage Theme Plugins
* @version 1.0.0
* @since 1.0.0
*/
/**
* License & Warranty
*
* This product is free software. It can be redistributed and/or modified
* ad libidum. There is no license distributed with this product.
*
* This product is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @see DISCLAIMER.md
*/
// Stop if accessed directly.
if ( ! defined( 'BLUDIT' ) ) {
die( 'You are not allowed direct access to this file.' );
}
// Access namespaced functions.
use function CFE_Plugin\{
css,
js,
asset_min,
is_rtl,
title_tag,
search_form,
custom_fields,
static_list,
categories_list,
tags_list,
error_search_display,
error_static_display,
error_cats_display,
error_tags_display,
change_theme,
default_theme,
admin_theme
};
use function CFE_Colors\{
define_color_scheme,
default_color_scheme
};
use function CFE_Fonts\{
load_font_files,
current_font_scheme,
admin_font_options
};
use function CFE_Galleries\{
basic_gallery,
page_images
};
/**
* Core plugin class
*
* Extends the Bludit class for plugin functionality,
* options form, and template hooks.
*
* @since 1.0.0
* @version 1.0.0
*/
class configureight extends Plugin {
/**
* Storage root
*
* @since 1.0.0
* @access private
* @var string
*/
private $storage_root = __CLASS__;
/**
* Cache age
*
* @since 1.0.0
* @access private
* @var integer
*/
private $maxCacheAge = 86400;
/**
* Constructor method
*
* @since 1.0.0
* @access public
* @return self
*/
public function __construct() {
// Run parent constructor.
parent :: __construct();
// Include functionality.
if ( $this->installed() ) {
$this->autoload();
$this->get_files();
}
}
/**
* Prepare plugin for installation
*
* @since 1.0.0
* @access public
* @return void
*/
public function prepare() {
$this->autoload();
$this->get_files();
}
/**
* Autoload classes
*
* @since 1.0.0
* @access public
* @return void
*/
public function autoload() {
// Path to class files.
$path = PATH_PLUGINS . __CLASS__ . DS . 'includes/classes' . DS;
// Array of namespaced classes & filenames.
$classes = [
'CFE_Classes\Image_Upload' => $path . 'class-image-upload.php',
'CFE_Classes\Bookmark_Images' => $path . 'class-bookmark-images.php',
'CFE_Classes\Bookmark_Album' => $path . 'class-bookmark-album.php',
'CFE_Classes\Logo_Standard_Images' => $path . 'class-logo-standard-images.php',
'CFE_Classes\Logo_Standard_Album' => $path . 'class-logo-standard-album.php',
'CFE_Classes\Logo_Cover_Images' => $path . 'class-logo-cover-images.php',
'CFE_Classes\Logo_Cover_Album' => $path . 'class-logo-cover-album.php',
'CFE_Classes\Cover_Images' => $path . 'class-cover-images.php',
'CFE_Classes\Cover_Album' => $path . 'class-cover-album.php',
'CFE_Classes\Image_Album' => $path . 'class-image-album.php'
];
spl_autoload_register(
function ( string $class ) use ( $classes ) {
if ( isset( $classes[ $class ] ) ) {
require $classes[ $class ];
}
}
);
}
/**
* Include functionality
*
* @since 1.0.0
* @access public
* @return void
*/
public function get_files() {
// Plugin path.
$path = PATH_PLUGINS . __CLASS__ . DS;
// Get plugin functions.
foreach ( glob( $path . 'includes/functions/*.php' ) as $filename ) {
require_once $filename;
}
}
/**
* Initialize plugin
*
* @since 1.0.0
* @access public
* @global object $L The Language class.
* @return void
*/
public function init() {
// Access global variables.
global $L;
// Plugin options for database.
$this->dbFields = [
'keep_options' => true,
'site_favicon' => [],
'user_toolbar' => 'enabled',
'toolbar_mobile' => false,
'to_top_button' => true,
'show_customize' => true,
'page_loader' => false,
'loader_bg_color' => $this->loader_bg_default(),
'loader_bg_color_dark' => $this->loader_bg_default_dark(),
'loader_text_color' => $this->loader_text_default(),
'loader_text_color_dark' => $this->loader_text_default_dark(),
'loader_text' => $L->get( 'Loading…' ),
'loader_icon' => 'spinner-dots',
'search_icon' => true,
'site_title' => true,
'site_slogan' => true,
'standard_logo' => [],
'cover_logo' => [],
'logo_standard_svg' => '',
'logo_cover_svg' => '',
'logo_thumb_width' => 80,
'logo_thumb_height' => 80,
'logo_large_width' => 320,
'logo_large_height' => 9999,
'logo_width_std' => $this->logo_width_std_default(),
'logo_width_mob' => $this->logo_width_mob_default(),
'logo_location' => 'before',
'header_sticky' => false,
'main_nav_pages' => [ '' ],
'main_nav_labels' => 'slug',
'main_nav_children' => 'secondary',
'main_nav_pos' => 'right',
'main_nav_icon' => 'bars',
'main_nav_loop' => 'none',
'main_nav_loop_label' => '',
'main_nav_home' => false,
'header_search' => false,
'header_social' => false,
'img_upload_quality' => 90,
'thumb_width' => 480,
'thumb_height' => 360,
'modal_bg_color' => $this->modal_bg_default(),
'cover_images' => [],
'cover_thumb_width' => 320,
'cover_thumb_height' => 320,
'cover_thumb_quality' => 90,
'cover_large_width' => 1920,
'cover_large_height' => 1080,
'cover_large_quality' => 90,
'cover_meta_width' => 1280,
'cover_meta_height' => 720,
'cover_meta_quality' => 90,
'gallery_sort' => 'newest', // 'newest', 'oldest', 'a-z'
'cover_in_post' => 'header',
'cover_in_page' => 'header',
'cover_in_profile' => 'profile',
'cover_style' => 'overlay',
'cover_blend' => $this->cover_blend_default(),
'cover_blend_use' => [ '', 'covers', 'slider' ],
'cover_overlay' => $this->cover_overlay_default(),
'cover_text_color' => $this->cover_text_default(),
'cover_text_shadow' => true,
'cover_desaturate' => 0,
'cover_desaturate_use' => [ '', 'none' ],
'cover_icon' => 'angle-down-light',
'loop_title' => '',
'loop_description' => '',
'loop_cover' => 'full_first',
'loop_type' => 'blog',
'loop_style' => 'list',
'cat_style' => 'list',
'tag_style' => 'list',
'loop_paged' => 'numerical',
'loop_byline' => true,
'loop_date' => true,
'loop_word_count' => true,
'loop_read_time' => true,
'loop_icons' => false,
'posts_nav' => true,
'posts_nav_type' => 'buttons',
'posts_nav_icon' => 'arrow',
'posts_slider' => false,
'slider_content' => 'recent',
'slider_number' => 5,
'slider_pages' => [ '' ],
'slider_icon' => 'spinner-dots',
'slider_arrows' => 'none',
'slider_dots' => false,
'slider_animate' => 'fade',
'slider_duration' => '3',
'slider_link_text' => '',
'related_posts' => true,
'max_related' => $this->max_related_default(),
'related_heading' => $L->get( 'Related Posts' ),
'related_heading_el' => 'h3',
'related_style' => 'list',
'cf_menu_label' => true,
'cf_random_cover' => true,
'cf_page_gallery' => true,
'cf_gallery_heading' => true,
'cf_read_more' => true,
'error_widgets' => 'content',
'error_search' => true,
'error_static' => true,
'error_cats' => true,
'error_tags' => true,
'error_search_label' => $L->get( 'Search' ),
'error_static_title' => $L->get( 'Pages' ),
'error_cats_title' => $L->get( 'Categories' ),
'error_tags_title' => $L->get( 'Post Tags' ),
'error_search_heading' => 'h2',
'error_static_heading' => 'h2',
'error_cats_heading' => 'h2',
'error_tags_heading' => 'h2',
'error_search_holder' => $L->get( 'Search' ),
'error_search_btn' => true,
'error_search_btn_text' => $L->get( 'Submit' ),
'error_static_dir' => 'horz',
'error_cats_dir' => 'horz',
'error_tags_dir' => 'horz',
'sidebar_in_page' => 'side',
'sidebar_in_loop' => 'side',
'sidebar_position' => 'right',
'sidebar_social' => false,
'sb_social_heading' => '',
'admin_menu' => true,
'footer_search' => false,
'footer_social' => true,
'ftr_social_heading' => '',
'footer_text' => true,
'copyright' => true,
'copy_date' => true,
'copy_text' => '',
'content_width' => '1280',
'horz_spacing' => '2',
'vert_spacing' => '2',
'color_scheme' => 'default',
'use_dark_scheme' => false,
'custom_scheme_from' => 'default',
'color_body' => '#ffffff',
'color_body_dark' => '#1e1e1e',
'color_text' => '#333333',
'color_text_dark' => '#eeeeee',
'color_one' => '#0044aa',
'color_two' => '#0066cc',
'color_three' => '#333333',
'color_four' => '#555555',
'color_five' => '#888888',
'color_six' => '#cccccc',
'color_one_dark' => '#ffffff',
'color_two_dark' => '#eeeeee',
'color_three_dark' => '#333333',
'color_four_dark' => '#555555',
'color_five_dark' => '#888888',
'color_six_dark' => '#cccccc',
'font_scheme' => 'default',
'wght_text' => '400',
'wght_primary' => '700',
'wght_secondary' => '700',
'wght_display' => '600',
'space_text' => '0',
'space_primary' => '0',
'space_secondary' => '0',
'space_display' => '0',
'admin_theme' => 'css',
'custom_css' => '',
'admin_css' => '',
'title_sep' => '|',
'custom_sep' => '',
'default_ttag' => '',
'loop_ttag' => '',
'post_ttag' => '',
'page_ttag' => '',
'cat_ttag' => '',
'tag_ttag' => '',
'search_ttag' => '',
'error_ttag' => '',
'default_ttag_rtl' => '',
'loop_ttag_rtl' => '',
'post_ttag_rtl' => '',
'page_ttag_rtl' => '',
'cat_ttag_rtl' => '',
'tag_ttag_rtl' => '',
'search_ttag_rtl' => '',
'error_ttag_rtl' => '',
'meta_noindex' => false,
'meta_keywords' => '',
'meta_use_schema' => true,
'meta_use_og' => true,
'meta_use_twitter' => true,
'meta_use_dublin' => false,
'meta_custom' => '',
'footer_scripts' => ''
];
// Array of custom hooks.
$this->customHooks = [
'meta_tags',
'color_scheme_vars',
'url_not_found',
'page_gallery',
'front_page',
'comment_form',
'footer_code',
'site_sidebar_before',
'site_sidebar_after'
];
if ( ! $this->installed() ) {
$Tmp = new dbJSON( $this->filenameDb );
$this->db = $Tmp->db;
$this->prepare();
}
}
/**
* Plugin URL
*
* @since 1.0.0
* @access protected
* @return string
*/
protected function plugin_url() {
$url = HTML_PATH_ADMIN_ROOT . 'configure-plugin/' . __CLASS__;
if ( BLUDIT_VERSION >= 4 ) {
$url = HTML_PATH_ADMIN_ROOT . 'plugin-settings/' . __CLASS__;
}
return $url;
}
/**
* Plugin slug
*
* @since 1.0.0
* @access protected
* @return string
*/
protected function plugin_slug() {
$slug = 'configure-plugin/' . __CLASS__;
if ( BLUDIT_VERSION >= 4 ) {
$slug = 'plugin-settings/' . __CLASS__;
}
return $slug;
}
/**
* Install plugin
*
* @since 1.0.0
* @access public
* @param integer $position
* @return boolean Return true if the installation is successful.
*/
public function install( $position = 1 ) {
/**
* Stop if preserving options and uploads.
*
* The `installed()` method in the parent class simply
* checks for a database corresponding to this plugin.
* If the `keep_options` setting is true then the database
* was not deleted on uninstall. However, this `install()`
* method is still run when the theme/plugin are reactivated
* and will overwrite the saved database if not stopped here.
*
* The check for `keep_options` is not necessary but
* included for completeness.
*/
if ( $this->installed() && $this->keep_options() ) {
return;
}
// Create workspace.
$workspace = $this->workspace();
mkdir( $workspace, DIR_PERMISSIONS, true );
// Create plugin directory for the database
mkdir( PATH_PLUGINS_DATABASES . $this->directoryName, DIR_PERMISSIONS, true );
$this->dbFields['position'] = $position;
// Sanitize default values to store in the file.
foreach ( $this->dbFields as $key => $value ) {
if ( is_array( $value ) ) {
$value = $value;
} else {
$value = Sanitize :: html( $value );
}
settype( $value, gettype( $this->dbFields[$key] ) );
$this->db[$key] = $value;
}
$storage = PATH_CONTENT . $this->storage_root . DS;
if ( ! file_exists( $storage ) ) {
Filesystem :: mkdir( $storage, true );
}
// Create the database.
return $this->save();
}
/**
* Uninstall
*
* If set in the General options tab,
* returns false to prevent database resetting
* when the theme is deactivated and the plugin
* is automatically uninstalled.
*
* @since 1.0.0
* @access public
* @return boolean
*/
public function uninstall() {
// Stop if preserving options and uploads.
if ( $this->keep_options() ) {
return false;
}
// Delete database.
$path = PATH_PLUGINS_DATABASES . $this->directoryName;
Filesystem :: deleteRecursive( $path );
// Delete workspace.
$workspace = $this->workspace();
Filesystem :: deleteRecursive( $workspace );
// Delete image uploads.
$uploads = PATH_CONTENT . $this->directoryName;
Filesystem :: deleteRecursive( $uploads );
return true;
}
/**
* Save options
*
* @since 1.0.0
* @access public
* @return void
*/
public function save() {
$this->edit_settings();
// Switch admin theme on save.
if ( admin_theme() && 'theme' == $this->admin_theme() ) {
change_theme();
} else {
default_theme();
}
// Save options to plugin JSON database.
$tmp = new dbJSON( $this->filenameDb );
$tmp->db = $this->db;
return $tmp->save();
}
/**
* Form post
*
* The form `$_POST` method.
*
* Essentially the same as the parent method
* except that it allows for array field values.
*
* This was implemented to handle multi-checkbox
* and radio button fields. If strings are used
* in an array option then be sure to sanitize
* the string values.
*
* @since 1.0.0
* @access public
* @return void
*/
public function post() {
$args = $_POST;
foreach ( $this->dbFields as $field => $value ) {
if ( isset( $args[$field] ) ) {
// @todo Look into sanitizing array values.
if ( is_array( $args[$field] ) ) {
$final_value = $args[$field];
} else {
$final_value = Sanitize :: html( $args[$field] );
}
if ( $final_value === 'false' ) {
$final_value = false;
} elseif ( $final_value === 'true' ) {
$final_value = true;
}
settype( $final_value, gettype( $value ) );
$this->db[$field] = $final_value;
}
}
return $this->save();
}
/**
* Load login scripts & styles
*
* @since 1.0.0
* @access public
* @global object $site Site class.
* @global object $url Url class.
* @return string
*/
public function loginHead() {
// Access global variables.
global $site, $url;
// Maybe get non-minified assets.
$suffix = '';
if ( ! $this->debug_mode() ) {
$suffix = '.min';
}
$assets = '';
if ( 'css' == $this->admin_theme() && 'configureight' != $site->adminTheme() ) {
$assets .= '<link rel="stylesheet" type="text/css" href="' . $this->domainPath() . "assets/css/login{$suffix}.css?version=" . $this->getMetadata( 'version' ) . '" />' . PHP_EOL;
}
return $assets;
}
/**
* Admin controller
*
* Change the text of the `<title>` tag.
*
* @since 1.0.0
* @access public
* @global object $L The Language class.
* @global array $layout
* @return string Returns the head content.
*/
public function adminController() {
// Access global variables.
global $L, $layout, $site;
// Title separator.
$sep = $this->title_sep();
if ( isset( $_GET['page'] ) && 'database' == $_GET['page'] ) {
$layout['title'] = $L->get( 'Website Options Database' ) . " {$sep} " . $site->title();
} elseif ( isset( $_GET['page'] ) && 'colors' == $_GET['page'] ) {
$layout['title'] = $L->get( 'Color Schemes Reference' ) . " {$sep} " . $site->title();
} elseif ( isset( $_GET['page'] ) && 'fonts' == $_GET['page'] ) {
$layout['title'] = $L->get( 'Font Schemes Reference' ) . " {$sep} " . $site->title();
} else {
$layout['title'] = $L->get( 'Website Options Guide' ) . " {$sep} " . $site->title();
}
}
/**
* Admin style block
*
* Prints custom admin CSS in the admin head.
*
* @since 1.0.0
* @access public
* @return mixed Returns a CSS style block or null.
*/
public function admin_style_block() {
$style = '<style>';
$style .= $this->admin_css();
$style .= '</style>';
return $style;
}
/**
* Load scripts & styles
*
* @since 1.0.0
* @access public
* @global object $site Site class.
* @global object $url Url class.
* @return string
*/
public function adminHead() {
// Access global variables.
global $site, $url;
if ( 'configureight' != $site->theme() ) {
return;
}
// Add class class to 'js' to `<body>`.
echo "<script>jQuery(document).ready( function($) { $('body').addClass('js') });</script>\n";
// Add dark mode class to `<body>`.
if ( $this->use_dark_scheme() ) {
echo "<script>jQuery(document).ready( function($) { $('body').addClass('dark-mode') });</script>\n";
}
// Maybe get non-minified assets.
$suffix = '';
if ( ! $this->debug_mode() ) {
$suffix = '.min';
}
$assets = '';
// Load only for this plugin's settings page.
if ( str_contains( $url->slug(), $this->className() ) ) :
$assets .= '<link rel="stylesheet" type="text/css" href="' . $this->domainPath() . "assets/css/dropzone.min.css?version=" . $this->getMetadata( 'version' ) . '" />' . PHP_EOL;
$assets .= '<link rel="stylesheet" type="text/css" href="' . $this->domainPath() . "assets/css/color-picker{$suffix}.css?version=" . $this->getMetadata( 'version' ) . '" />' . PHP_EOL;
$assets .= '<link rel="stylesheet" type="text/css" href="' . $this->domainPath() . "assets/css/tooltips{$suffix}.css?version=" . $this->getMetadata( 'version' ) . '" />' . PHP_EOL;
$assets .= '<link rel="stylesheet" type="text/css" href="' . $this->domainPath() . "assets/css/lightbox{$suffix}.css?version=" . $this->getMetadata( 'version' ) . '" />' . PHP_EOL;
$assets .= '<script type="text/javascript" src="' . $this->domainPath() . "assets/js/tabs{$suffix}.js?version=" . $this->getMetadata( 'version' ) . '"></script>' . PHP_EOL;
$assets .= '<script type="text/javascript" src="' . $this->domainPath() . "assets/js/dropzone{$suffix}.js?version=" . $this->getMetadata( 'version' ) . '"></script>' . PHP_EOL;
$assets .= '<script type="text/javascript" src="' . $this->domainPath() . "assets/js/color-picker{$suffix}.js?version=" . $this->getMetadata( 'version' ) . '"></script>' . PHP_EOL;
$assets .= '<script type="text/javascript" src="' . $this->domainPath() . "assets/js/tooltips{$suffix}.js?version=" . $this->getMetadata( 'version' ) . '"></script>' . PHP_EOL;
$assets .= '<script type="text/javascript" src="' . $this->domainPath() . "assets/js/lightbox{$suffix}.js?version=" . $this->getMetadata( 'version' ) . '"></script>' . PHP_EOL;
$assets .= '<script type="text/javascript" src="' . $this->domainPath() . "assets/js/fields{$suffix}.js?version=" . $this->getMetadata( 'version' ) . '"></script>' . PHP_EOL;
// End plugin page.
endif;
if ( 'css' == $this->admin_theme() && 'configureight' != $site->adminTheme() ) {
$assets .= '<link rel="stylesheet" type="text/css" href="' . $this->domainPath() . "assets/css/style{$suffix}.css?version=" . $this->getMetadata( 'version' ) . '" />' . PHP_EOL;
} elseif ( 'default' == $this->admin_theme() || 'booty' == $site->adminTheme() || ! $site->adminTheme() ) {
$assets .= '<link rel="stylesheet" type="text/css" href="' . $this->domainPath() . "assets/css/default{$suffix}.css?version=" . $this->getMetadata( 'version' ) . '" />' . PHP_EOL;
}
// Style block for settings screen.
if ( str_contains( $url->slug(), 'settings' ) ) :
$assets .= '<style>';
$assets .= '#seo.tab-pane h2:not( :first-of-type ) { display: none !important; }';
$assets .= '#seo.tab-pane div:not( :first-of-type ) { display: none !important; }';
$assets .= '#nav-images-tab.nav-item { display: none !important; }';
$assets .= '#images.tab-pane { display: none !important; }';
$assets .= '#nav-logo-tab.nav-item { display: none !important; }';
$assets .= '#logo.tab-pane { display: none !important; }';
$assets .= '</style>';
endif;
// Scheme stylesheets.
$assets .= $this->scheme_stylesheet( 'colors', 'admin' );
$assets .= $this->scheme_stylesheet( 'fonts', 'admin' );
$assets .= define_color_scheme();
$assets .= admin_font_options();
// User toolbar is active.
if (
'enabled' == $this->getValue( 'user_toolbar' ) ||
'backend' == $this->getValue( 'user_toolbar' )
) {
$assets .= '<style>body { padding-top: var( --cfe-toolbar--height ); } nav.navbar.d-block { display: none !important; }</style>';
// Is admin menu hidden.
if ( ! $this->getValue( 'admin_menu' ) ) {
$assets .= '<style>.sidebar.d-lg-block { display: none !important; }</style>';
}
}
// Modal background.
$assets .= '<style>';
$assets .= sprintf(
':root { --cfe-modal-overlay--bg-color: %s; }',
$this->modal_bg_color()
);
$assets .= '</style>';
// Custom admin CSS for default the with theme styles.
if ( ! empty( $this->admin_css() ) && 'css' == $this->admin_theme() ) {
$assets .= $this->admin_style_block();
}
return $assets;
}
/**
* Admin body begin
*
* Conditionally prints a modal window notice
* on the Themes admin screen,
*
* @since 1.0.0
* @access public
* @global object $L Language class.
* @global object $page Page class.
* @global object $plugins Plugins class.
* @global object $site Site class.
* @global object $url Url class.
* @return void
*/
public function adminBodyBegin() {
// Access global variables.
global $L, $login, $page, $plugins, $site, $url;
// Stop if Configure 8 is not the active theme.
if ( 'configureight' != $site->theme() ) {
return;
}
$upload_path = HTML_PATH_ADMIN_ROOT . 'configureight';
$current_path = strtok( $_SERVER["REQUEST_URI"], '?' );
if ( $current_path == $upload_path ) {
ob_start();
}
// User toolbar.
if (
'enabled' == $this->getValue( 'user_toolbar' ) ||
'backend' == $this->getValue( 'user_toolbar' )
) {
include( $this->phpPath() . '/views/user-toolbar.php' );
}
// Admin theme notice.
if ( 'themes' == $url->slug() && 'theme' == $this->admin_theme() ) {
include( $this->phpPath() . '/views/notice-admin-theme.php' );
}
}
/**
* Sidebar link
*
* Link to the options screen in the admin sidebar menu.
*
* @since 1.0.0
* @access public
* @global object $L Language class.
* @global object $site Site class.
* @return mixed
*/
public function adminSidebar() {
// Access global variables.
global $L, $site;
// Stop if Configure 8 is not the active theme.
if ( 'configureight' != $site->theme() ) {
return;
}
// Configure 8 admin theme has the options link.
if ( 'configureight' === $site->adminTheme() ) {
return;
}
// Check user role.
if ( ! checkRole( [ 'admin' ], false ) ) {
return;
}
$html = sprintf(
'<a class="nav-link" href="%s"><span class="fa fa-gear theme-options-icon"></span>%s</a>',
$this->plugin_url(),
$L->get( 'Options' )
);
return $html;
}
/**
* Admin body end
*
* Used for adding scripts.
*
* @since 1.0.0
* @access public
* @global object $L Language class.
* @global object $site Site class.
* @global object $url Url class.
* @return string
*/
public function adminBodyEnd() {
// Access global variables.
global $L, $page, $site, $url;
// Stop if Configure 8 is not the active theme.
if ( 'configureight' != $site->theme() ) {
return;
}
// Content ID on page edit screen.
if ( str_contains( $url->slug(), 'edit-content' ) ) {
return sprintf(
'<script>var uuid = $("#jsuuid").val(); $uuid = uuid; if ( $uuid != "" ) { $( "#jsform" ).prepend( "<h2><span class=\'fa fa-pencil page-title-icon\' style=\'font-size: 0.9em;\'></span>%s</h2><p style=\'margin-bottom: 1rem;\'><strong>%s</strong> <code class=\'select\'>" + $uuid + "</code><br /><strong>%s</strong> <a href=\'%s\' target=\'_blank\' rel=\'noopener noreferrer\'>%s</a></p>"); }</script>',
$L->get( 'Edit Content' ),
$L->get( 'Content ID:' ),
$L->get( 'Permalink:' ),
$page->permalink(),
$page->permalink()
);
}
if ( str_contains( $url->slug(), 'new-content' ) ) {
return sprintf(
'<script>$( "#jsform" ).prepend( "<h2 style=\'margin-bottom: 1rem;\'><span class=\'fa fa-pencil page-title-icon\' style=\'font-size: 0.9em;\'></span>%s</h2>");</script>',
$L->get( 'New Content' )
);
}
// Maybe get non-minified assets.
$suffix = '';
if ( ! $this->debug_mode() ) {
$suffix = '.min';
}
$html = '';
// Load only for this plugin's settings page.
if ( str_contains( $url->slug(), $this->className() ) ) :
// AJAX paths for uploads.
$upload_path = HTML_PATH_ADMIN_ROOT . __CLASS__;
$current_path = strtok( $_SERVER['REQUEST_URI'], '?' );
if ( $current_path == $upload_path ) {
// Fetch content.
$content = ob_get_contents();
ob_end_clean();
$bookmark = 'bookmark';
$logo_std = 'logo_std';
$logo_cover = 'logo_cover';
$cover = 'cover';
$domain = $this->domainPath();
// Get helper objects.
require_once( 'includes/classes/class-bookmark-images-helper.php' );
require_once( 'includes/classes/class-logo-standard-images-helper.php' );
require_once( 'includes/classes/class-logo-cover-images-helper.php' );
require_once( 'includes/classes/class-cover-images-helper.php' );
$bookmark_helper = new \CFE_Classes\Bookmark_Images_Helper();
$logo_std_helper = new \CFE_Classes\Logo_Standard_Images_Helper();
$logo_cover_helper = new \CFE_Classes\Logo_Cover_Images_Helper();
$cover_helper = new \CFE_Classes\Cover_Images_Helper();
// Load required JS.
$html .= '<script type="text/javascript" src="' . $this->domainPath() . "assets/js/jquery-confirm{$suffix}.js?version=" . $this->getMetadata( 'version' ) . '"></script>' . PHP_EOL;
$html .= $bookmark_helper->adminJSData( $domain );
$html .= $logo_std_helper->adminJSData( $domain );
$html .= $logo_cover_helper->adminJSData( $domain );
$html .= $cover_helper->adminJSData( $domain );
if ( $bookmark ) {
$html .= $bookmark_helper->dropzoneJSData( $bookmark );
}
if ( $logo_std ) {
$html .= $logo_std_helper->dropzoneJSData( $logo_std );
}
if ( $logo_cover ) {
$html .= $logo_cover_helper->dropzoneJSData( $logo_cover );
}
if ( $cover ) {
$html .= $cover_helper->dropzoneJSData( $cover );
}
// Remove old admin content (error message)
$regexp = "#(\<div class=\"col-lg-10 pt-3 pb-1 h-100\"\>)(.*?)(\<\/div\>)#s";
$content = preg_replace( $regexp, "$1{$html}$3", $content );
echo $content;
return;
}
$bookmark = 'bookmark';
$logo_std = 'logo_std';
$logo_cover = 'logo_cover';
$cover = 'cover';
$domain = $this->domainPath();
// Get helper objects.
require_once( 'includes/classes/class-bookmark-images-helper.php' );
require_once( 'includes/classes/class-logo-standard-images-helper.php' );
require_once( 'includes/classes/class-logo-cover-images-helper.php' );
require_once( 'includes/classes/class-cover-images-helper.php' );
$bookmark_helper = new \CFE_Classes\Bookmark_Images_Helper();
$logo_std_helper = new \CFE_Classes\Logo_Standard_Images_Helper();
$logo_cover_helper = new \CFE_Classes\Logo_Cover_Images_Helper();
$cover_helper = new \CFE_Classes\Cover_Images_Helper();
// Load required JS
$html .= '<script type="text/javascript" src="' . $this->domainPath() . "assets/js/jquery-confirm{$suffix}.js?version=" . $this->getMetadata( 'version' ) . '"></script>' . PHP_EOL;
$html .= $bookmark_helper->adminJSData( $domain );
$html .= $logo_std_helper->adminJSData( $domain );
$html .= $logo_cover_helper->adminJSData( $domain );
$html .= $cover_helper->adminJSData( $domain );
if ( $bookmark ) {
$html .= $bookmark_helper->dropzoneJSData( $bookmark );
}
if ( $logo_std ) {