-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.php
More file actions
3062 lines (2721 loc) · 161 KB
/
plugin.php
File metadata and controls
3062 lines (2721 loc) · 161 KB
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
/*
Plugin Name: AGCA - Custom Dashboard & Login Page
Plugin URI: https://cusmin.com/agca
Description: CHANGE: admin menu, login page, admin bar, dashboard widgets, custom colors, custom CSS & JS, logo & images
Author: Cusmin
Version: 7.2.5
Text Domain: ag-custom-admin
Domain Path: /languages
Author URI: https://cusmin.com/
Copyright 2024. Cusmin (email : info@cusmin.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$agca = new AGCA();
class AGCA{
private $agca_version = "7.2.5";
private $colorizer = "";
private $agca_debug = false;
private $admin_capabilities;
private $context = "";
private $saveAfterImport = false;
const PLACEHOLDER_BLOG = '%BLOG%';
const PLACEHOLDER_PAGE = '%PAGE%';
public function __construct()
{
add_action( 'plugins_loaded', array(&$this,'my_load_plugin_textdomain') );
add_action('init', array(&$this,'init'));
}
function init(){
$this->reloadScript();
$this->checkGET();
if(function_exists("add_filter")){
add_filter('admin_title', array(&$this,'change_title'), 10, 2);
add_filter('plugin_row_meta', array(&$this,'jk_filter_plugin_links'), 10, 2);
}
add_action('admin_init', array(&$this,'admin_init'));
add_action('login_init', array(&$this,'login_init'));
add_action('admin_head', array(&$this,'print_admin_css'));
add_action('login_head', array(&$this,'print_login_head'));
add_action('admin_menu', array(&$this,'agca_create_menu'));
add_action('wp_head', array(&$this,'print_page'));
register_deactivation_hook(__FILE__, array(&$this,'agca_deactivate'));
add_action( 'customize_controls_enqueue_scripts', array(&$this,'agca_customizer_php') );
add_action( 'admin_bar_menu', array(&$this, 'wp_admin_bar_my_custom_account_menu'), 11 );
add_action( 'updated_option', array(&$this, 'after_update_option'), 10, 3);
/*Initialize properties*/
$this->colorizer = $this->jsonMenuArray(get_option('ag_colorizer_json'),'colorizer');
if(!get_option('agca_check_js_notice') && get_option('agca_custom_js')) {
add_action( 'admin_notices', array(&$this, 'agca_check_js_notice') );
}
//admin bar on front end
if(!is_admin() && is_admin_bar_showing()){
add_action('wp_head', array(&$this, 'hide_admin_bar_css'));
$this->agca_enqueue_js();
}
}
function hide_admin_bar_css(){
if(is_user_logged_in() &&
current_user_can($this->admin_capability()) &&
get_option('agca_role_allbutadmin')){
return;
}
?>
<style type="text/css">
#wpadminbar{
display: none;
}
</style>
<?php
}
function agca_check_js_notice(){
echo '<div class="notice error">
<p><h2>IMPORTANT MESSAGE FROM AGCA PLUGIN! (aka Custom Dashboard & Login Page plugin)</h2></p>
<p>We are enforcing security in AGCA plugin and custom JavaScript code is currently disabled and requires your review. Please go to AGCA plugin settings (Tools > AGCA > Advanced) page and make sure that your JavaScript does not contain any unwanted code. If you are sure that the script looks good to you, please save the settings in AGCA plugin again, to dismiss this notice and re-enable the script again.</p>
<p><a href="'. get_site_url() .'/wp-admin/tools.php?page=ag-custom-admin%2Fplugin.php#ag-advanced">Click here to revisit and save AGCA settings again</a></p>
</div>';
}
function isAGCASettingsPage() {
if(!is_admin()) {
return false;
}
if(isset($_GET['page']) && $_GET['page'] == 'ag-custom-admin/plugin.php'){
return true;
}
return false;
}
function my_load_plugin_textdomain() {
load_plugin_textdomain( 'ag-custom-admin');
}
// Add donate and support information
function jk_filter_plugin_links($links, $file)
{
if ( $file == plugin_basename(__FILE__) )
{
if(!is_network_admin()){
$links[] = '<a href="tools.php?page=ag-custom-admin/plugin.php#general-settings">' . __('Settings', 'ag-custom-admin') . '</a>';
}
$links[] = '<a target="_blank" href="https://wordpress.org/support/plugin/ag-custom-admin">' . __('Support', 'ag-custom-admin') . '</a>';
$links[] = '<a target="_blank" href="https://cusmin.com/upgrade-to-cusmin/?ref=agca-plugins-page">' . __('Upgrade', 'ag-custom-admin') . '</a>';
$links[] = '<a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=agca@cusmin.com&amount=10&item_name=Support+for+AGCA+Development">' . __('Donate', 'ag-custom-admin') . '</a>';
}
return $links;
}
function filePath($url){
$absPath = ABSPATH;
$absPath = rtrim($absPath, '/');
$url = ltrim($url, '/');
return $absPath.'/'.$url;
}
function change_admin_color(){
return 'default';
}
//Prevent non-admin users to update sensitive options
//Revert option value to previous
function after_update_option( $option, $old_value, $new_value ){
if((
!current_user_can('administrator') ||
!current_user_can('unfiltered_html')
) &&
in_array($option, [
'agca_dashboard_text_paragraph',
'agca_dashboard_text',
'agca_custom_css',
'agca_footer_left',
'agca_footer_right',
'agca_custom_js',
'agca_check_js_notice',
])) {
remove_action( 'updated_option', array(&$this,'after_update_option'));
update_option($option, $old_value);
add_action( 'updated_option', array(&$this,'after_update_option'), 10, 3);
}
}
function is_wp_admin(){
return current_user_can('administrator');
}
function can_save_unfiltered_html(){
return current_user_can('unfiltered_html');
}
function agca_customizer_php(){
$this->agca_get_includes();
}
function admin_init(){
$this->agca_register_settings();
$isAdminUser = current_user_can($this->admin_capability());
if(!$isAdminUser || ($isAdminUser && !get_option('agca_role_allbutadmin'))){
if(get_option('agca_profile_color_scheme')){
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
}
}
$this->enqueue_scripts();
}
function login_init(){
$this->agca_enqueue_scripts();
}
function enqueue_scripts() {
$wpversion = $this->get_wp_version();
if($this->isAGCASettingsPage()) {
wp_register_script ( 'agca-farbtastic-script', $this->pluginUrl() . 'script/agca_farbtastic.js', array('farbtastic'), $wpversion );
wp_register_style('agca-farbtastic-style', $this->pluginUrl() . 'style/agca_farbtastic.css', array('farbtastic'), $wpversion);
wp_enqueue_script ( 'farbtastic' );
wp_enqueue_style( 'farbtastic' );
wp_enqueue_script ( 'agca-farbtastic-script', array('farbtastic') );
wp_enqueue_style ( 'agca-farbtastic-style', array('farbtastic') );
}
if(is_admin()) {
$agcaStyleFileName = get_option('agca_no_style') == true ? 'ag_style_simple' : 'ag_style';
wp_register_style('agca-style', $this->pluginUrl() . 'style/' . $agcaStyleFileName . '.css', array('farbtastic'), $this->agca_version);
wp_enqueue_style( 'agca-style' );
$this->agca_enqueue_js();
}
}
function agca_enqueue_js(){
wp_register_script ( 'agca-script', $this->pluginUrl() . 'script/ag_script.js', array('jquery'), $this->agca_version );
add_action('wp_print_scripts', function () {
wp_enqueue_script ( 'agca-script' );
}, 2);
}
function checkGET(){
if(isset($_GET['agca_debug'])){
if($_GET['agca_debug'] =="true"){
$this->agca_debug = true;
}else{
$this->agca_debug = false;
}
}
}
function getFieldSecurityProtected(){
if($this->is_wp_admin() && $this->can_save_unfiltered_html()){
return '';
}
return "<p class=\"agca-field-secured-notice\">( For security reasons, this field is available for editing only to WordPress <b>Administrators</b> with the allowed capability to save unfiltered HTML )</p>";
}
function verifyPostRequest(){
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!is_admin()) {
_e('Not allowed. This action is allowed exclusively in admin panel', 'ag-custom-admin');
exit;
}
//In case of problems with saving AGCA settings on MS disable verification temporary
if(get_option('agca_disable_postver')){
return;
}
if (is_multisite()) {
$blog_id = get_current_blog_id();
$user_id = get_current_user_id();
$msError = __('Please try temporary disabling POST verification. Go to Absolutely Glamorous Custom Admin -> Advanced -> Temporary disable POST verification. Do not forget to un-check this option once you are done with customizations.', 'ag-custom-admin');
if (is_user_member_of_blog($user_id, $blog_id)) {
if (!current_user_can('manage_options')) {
_e('Multi-site: Current user is not recognized as administrator.', 'ag-custom-admin');
echo ' '. $this->sanitize_html($msError);
exit;
}
} else {
printf(
/*translators: 1: User Id 2: Blog Id*/
__('Multi-site: User (%1$s) does not have access to this blog (%2$s).', 'ag-custom-admin'),
$user_id,
$blog_id
);
echo ' '. $this->sanitize_html($msError);
exit;
}
} else {
include_once($this->filePath('wp-includes/pluggable.php'));
if (!is_user_logged_in() || !current_user_can('manage_options')) {
echo !is_user_logged_in() ? __('User is not logged in.', 'ag-custom-admin').' ' : '';
echo !current_user_can('manage_options') ? __('User can not manage options.', 'ag-custom-admin').' ' : '';
exit;
}
}
if (!wp_verify_nonce($_POST['_agca_token'], 'agca_form')) {
echo __('Nonce verification failed.', 'ag-custom-admin');
exit;
}
}
}
function isGuest(){
global $user_login;
if($user_login) {
return false;
}else{
return true;
}
}
function change_title($admin_title, $title){
//return get_bloginfo('name').' - '.$title;
if(get_option('agca_custom_title')!=""){
$blog = get_bloginfo('name');
$page = $title;
$customTitle = get_option('agca_custom_title');
$customTitle = str_replace(self::PLACEHOLDER_BLOG,$blog,$customTitle);
$customTitle = str_replace(self::PLACEHOLDER_PAGE,$page,$customTitle);
return htmlentities(strip_tags($customTitle));
}
return strip_tags($admin_title);
}
function agca_get_includes() {
if(!((get_option('agca_role_allbutadmin')==true) and (current_user_can($this->admin_capability())))){
?>
<style type="text/css">
<?php echo wp_kses_post(get_option('agca_custom_css')); ?>
</style>
<?php if(get_option('agca_check_js_notice')) { ?>
<script type="text/javascript">
try{
<?php echo wp_kses_post(get_option('agca_custom_js')); ?>
}catch(e){
alert('AGCA: <?php _e('There is an error in your custom JS script. Please fix it:', 'ag-custom-admin'); ?> \n\n' + e + '\n\n (<?php _e('AGCA -> Advanced -> Custom JavaScript', 'ag-custom-admin'); ?>)');
console.log(e);
}
</script>
<?php } ?>
<?php
}
}
function agca_enqueue_scripts() {
wp_enqueue_script('jquery');
}
function WPSPluginIsLoginPage(){
$WPSPluginName = 'wps-hide-login/wps-hide-login.php';
if(is_multisite()){
if ( ! function_exists( 'is_plugin_active_for_network' ) ){
$pluginPhpFilePath = $this->filePath('wp-admin/includes/plugins.php');
if(!file_exists($pluginPhpFilePath)){
return '';
}
require_once($pluginPhpFilePath);
}
if(!$this->isPluginActiveForNetwork($WPSPluginName)){
return '';
}
}else{
if(!$this->isPluginActive($WPSPluginName)){
return '';
}
}
if ( $slug = get_option( 'whl_page' ) ) {
return $slug;
} else if ( ( is_multisite() && $this->isPluginActiveForNetwork($WPSPluginName) && ( $slug = get_site_option( 'whl_page', 'login' ) ) ) ) {
return $slug;
} else if ( $slug = 'login' ) {
return $slug;
}
$requestURI = $_SERVER['REQUEST_URI'];
return $this->startsWith('/'.$slug.'/', $requestURI);
}
function reloadScript(){
$isAdmin = false;
if(defined('WP_ADMIN') && WP_ADMIN == 1){
$isAdmin = true;
}
if($isAdmin || $this->WPSPluginIsLoginPage()){
$this->agca_enqueue_scripts();
}
}
function agca_register_settings() {
register_setting( 'agca-options-group', 'agca_role_allbutadmin' );
register_setting( 'agca-options-group', 'agca_no_style' );
register_setting( 'agca-options-group', 'agca_screen_options_menu' );
register_setting( 'agca-options-group', 'agca_help_menu' );
register_setting( 'agca-options-group', 'agca_logout' );
register_setting( 'agca-options-group', 'agca_remove_your_profile' );
register_setting( 'agca-options-group', 'agca_logout_only' );
register_setting( 'agca-options-group', 'agca_custom_title' );
register_setting( 'agca-options-group', 'agca_howdy' );
register_setting( 'agca-options-group', 'agca_header' );
register_setting( 'agca-options-group', 'agca_header_show_logout' );
register_setting( 'agca-options-group', 'agca_footer' );
register_setting( 'agca-options-group', 'agca_privacy_options' );
register_setting( 'agca-options-group', 'agca_header_logo' );
register_setting( 'agca-options-group', 'agca_header_logo_custom' );
register_setting( 'agca-options-group', 'agca_wp_logo_custom' );
register_setting( 'agca-options-group', 'agca_remove_site_link' );
register_setting( 'agca-options-group', 'agca_wp_logo_custom_link' );
register_setting( 'agca-options-group', 'agca_profile_color_scheme' );
register_setting( 'agca-options-group', 'agca_site_heading' );
register_setting( 'agca-options-group', 'agca_custom_site_heading' );
register_setting( 'agca-options-group', 'agca_update_bar' );
register_setting( 'agca-options-group', 'agca_footer_left' );
register_setting( 'agca-options-group', 'agca_footer_left_hide' );
register_setting( 'agca-options-group', 'agca_footer_right' );
register_setting( 'agca-options-group', 'agca_footer_right_hide' );
register_setting( 'agca-options-group', 'agca_check_js_notice' );
register_setting( 'agca-options-group', 'agca_login_banner' );
register_setting( 'agca-options-group', 'agca_login_banner_text' );
register_setting( 'agca-options-group', 'agca_login_photo_remove' );
register_setting( 'agca-options-group', 'agca_login_photo_url' );
register_setting( 'agca-options-group', 'agca_login_photo_href' );
register_setting( 'agca-options-group', 'agca_login_round_box' );
register_setting( 'agca-options-group', 'agca_login_round_box_size' );
register_setting( 'agca-options-group', 'agca_login_round_box_skip_logo' );
register_setting( 'agca-options-group', 'agca_dashboard_icon' );
register_setting( 'agca-options-group', 'agca_dashboard_text' );
register_setting( 'agca-options-group', 'agca_dashboard_text_paragraph' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_welcome' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_health_status' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_activity' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_il' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_plugins' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_qp' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_rn' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_rd' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_primary' );
register_setting( 'agca-options-group', 'agca_dashboard_widget_secondary' );
//WP3.3
register_setting( 'agca-options-group', 'agca_admin_bar_comments' );
register_setting( 'agca-options-group', 'agca_admin_bar_new_content' );
register_setting( 'agca-options-group', 'agca_admin_bar_new_content_post' );
register_setting( 'agca-options-group', 'agca_admin_bar_new_content_link' );
register_setting( 'agca-options-group', 'agca_admin_bar_new_content_page' );
register_setting( 'agca-options-group', 'agca_admin_bar_new_content_user' );
register_setting( 'agca-options-group', 'agca_admin_bar_new_content_media' );
register_setting( 'agca-options-group', 'agca_admin_bar_update_notifications' );
register_setting( 'agca-options-group', 'agca_remove_top_bar_dropdowns' );
register_setting( 'agca-options-group', 'agca_admin_bar_frontend' );
register_setting( 'agca-options-group', 'agca_admin_bar_frontend_hide' );
register_setting( 'agca-options-group', 'agca_login_register_remove' );
register_setting( 'agca-options-group', 'agca_login_register_href' );
register_setting( 'agca-options-group', 'agca_login_lostpassword_remove' );
register_setting( 'agca-options-group', 'agca_admin_capability' );
register_setting( 'agca-options-group', 'agca_disablewarning' );
/*Admin menu*/
register_setting( 'agca-options-group', 'agca_admin_menu_turnonoff' );
register_setting( 'agca-options-group', 'agca_admin_menu_agca_button_only' );
register_setting( 'agca-options-group', 'agca_admin_menu_separators' );
register_setting( 'agca-options-group', 'agca_admin_menu_icons' );
register_setting( 'agca-options-group', 'agca_admin_menu_collapse_button' );
register_setting( 'agca-options-group', 'agca_admin_menu_arrow' );
register_setting( 'agca-options-group', 'agca_admin_menu_submenu_round' );
register_setting( 'agca-options-group', 'agca_admin_menu_submenu_round_size' );
register_setting( 'agca-options-group', 'agca_admin_menu_brand' );
register_setting( 'agca-options-group', 'agca_admin_menu_brand_link' );
register_setting( 'agca-options-group', 'agca_admin_menu_autofold' );
register_setting( 'agca-options-group', 'ag_edit_adminmenu_json' );
register_setting( 'agca-options-group', 'ag_edit_adminmenu_json_new' );
register_setting( 'agca-options-group', 'ag_add_adminmenu_json' );
register_setting( 'agca-options-group', 'ag_colorizer_json' );
register_setting( 'agca-options-group', 'agca_colorizer_turnonoff' );
register_setting( 'agca-options-group', 'agca_custom_js' );
register_setting( 'agca-options-group', 'agca_custom_css' );
register_setting( 'agca-options-group', 'agca_disable_postver' );
register_setting( 'agca-options-group', 'agca_menu_remove_client_profile' );
register_setting( 'agca-options-group', 'agca_menu_remove_customize_button' );
if(!empty($_POST)){
if(isset($_POST['_agca_import_settings']) && $_POST['_agca_import_settings']=="true"){
$this->verifyPostRequest();
if(isset($_FILES) && isset($_FILES['settings_import_file']) ){
if($_FILES["settings_import_file"]["error"] > 0){
}else{
$file = $_FILES['settings_import_file'];
if($this->startsWith($file['name'],'AGCA_Settings')){
if (file_exists($file['tmp_name'])) {
$fh = fopen($file['tmp_name'], 'r');
$theData = "";
if(filesize($file['tmp_name']) > 0){
$theData = fread($fh,filesize($file['tmp_name']));
}
fclose($fh);
$this->importSettings($theData);
}
}
}
}
}else if(isset($_POST['_agca_export_settings']) && $_POST['_agca_export_settings']=="true"){
$this->verifyPostRequest();
$this->exportSettings();
}
}
if(isset($_GET['agca_action'])){
if($_GET['agca_action'] == "disablewarning"){
update_option('agca_disablewarning', true);
}
}
}
function agca_deactivate() {
}
function getOptions(){
return Array(
'agca_role_allbutadmin',
'agca_no_style',
'agca_admin_bar_frontend',
'agca_admin_bar_frontend_hide',
'agca_login_register_remove',
'agca_login_register_href',
'agca_login_lostpassword_remove',
'agca_admin_capability',
'agca_screen_options_menu',
'agca_help_menu',
'agca_logout',
'agca_remove_your_profile',
'agca_logout_only',
'agca_custom_title',
'agca_howdy',
'agca_header',
'agca_header_show_logout',
'agca_footer',
'agca_privacy_options',
'agca_header_logo',
'agca_header_logo_custom',
'agca_remove_site_link',
'agca_wp_logo_custom',
'agca_wp_logo_custom_link',
'agca_profile_color_scheme',
'agca_site_heading',
'agca_custom_site_heading',
'agca_update_bar',
'agca_footer_left',
'agca_footer_left_hide',
'agca_footer_right',
'agca_footer_right_hide',
'agca_check_js_notice',
'agca_login_banner',
'agca_login_banner_text',
'agca_login_photo_remove',
'agca_login_photo_url',
'agca_login_photo_href',
'agca_login_round_box',
'agca_login_round_box_size',
'agca_login_round_box_skip_logo',
'agca_dashboard_icon',
'agca_dashboard_text',
'agca_dashboard_text_paragraph',
'agca_dashboard_widget_welcome',
'agca_dashboard_widget_health_status',
'agca_dashboard_widget_activity',
'agca_dashboard_widget_il',
'agca_dashboard_widget_plugins',
'agca_dashboard_widget_qp',
'agca_dashboard_widget_rn',
'agca_dashboard_widget_rd',
'agca_dashboard_widget_primary',
'agca_dashboard_widget_secondary',
'agca_admin_bar_comments',
'agca_admin_bar_new_content',
'agca_admin_bar_new_content_post',
'agca_admin_bar_new_content_link',
'agca_admin_bar_new_content_page',
'agca_admin_bar_new_content_user',
'agca_admin_bar_new_content_media',
'agca_admin_bar_update_notifications',
'agca_remove_top_bar_dropdowns',
'agca_admin_menu_turnonoff',
'agca_admin_menu_agca_button_only',
'agca_admin_menu_separators',
'agca_admin_menu_icons',
'agca_admin_menu_arrow',
'agca_admin_menu_submenu_round',
'agca_admin_menu_submenu_round_size',
'agca_admin_menu_brand',
'agca_admin_menu_brand_link',
'agca_admin_menu_autofold',
'agca_admin_menu_collapse_button',
'ag_edit_adminmenu_json',
'ag_edit_adminmenu_json_new',
'ag_add_adminmenu_json',
'ag_colorizer_json',
'agca_colorizer_turnonof',
'agca_custom_js',
'agca_custom_css',
'agca_colorizer_turnonoff',
'agca_disablewarning',
'agca_disable_postver',
'agca_menu_remove_client_profile',
'agca_menu_remove_customize_button',
);
}
function getTextEditor($name){
$settings = array(
'textarea_name' => $name,
'media_buttons' => true,
'tinymce' => array(
'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
'bullist,blockquote,|,justifyleft,justifycenter' .
',justifyright,justifyfull,|,link,unlink,|' .
',spellchecker,wp_fullscreen,wp_adv'
)
);
wp_editor( get_option($name), $name, $settings );
}
function importSettings($settings){
$exploaded = explode("|^|^|", $settings);
// $str = "EEE: ";
$str = '';
$savedOptions = array();
foreach ($exploaded as $setting){
$key = current(explode(':', $setting));
$value = substr($setting, strlen($key)+1);
$cleanedValue = str_replace('|^|^|','',$value);
$savedOptions[$key] = $cleanedValue;
}
// print_r($savedOptions);
$optionNames = $this->getOptions();
foreach ($optionNames as $optionName){
$optionValue = $savedOptions[$optionName];
if($optionName == "ag_edit_adminmenu_json" || "ag_edit_adminmenu_json_new"|| $optionName == "ag_add_adminmenu_json" ||$optionName == "ag_colorizer_json"){
$optionValue = str_replace("\\\"", "\"", $optionValue);
$optionValue = str_replace("\\\'", "\'", $optionValue);
}else if($optionName == "agca_custom_js" || $optionName == "agca_custom_css"){
$optionValue = htmlspecialchars_decode($optionValue);
$optionValue = str_replace("\'", '"', $optionValue);
$optionValue = str_replace('\"', "'", $optionValue);
}
update_option($optionName, $optionValue);
$str.="/".$optionName."/".$optionValue."\n";
}
//Migration from 1.2.6. to 1.2.5.1 - remove in later versions
//agca_script_css
//
// fb($savedOptions);
if($savedOptions['agca_script_css'] != null){
$optionValue = "";
$optionValue = str_replace("\'", '"', $savedOptions['agca_script_css']);
$optionValue = str_replace('\"', "'", $optionValue);
update_option('agca_custom_css', $optionValue);
}
if($savedOptions['agca_script_js'] != null){
$optionValue = "";
$optionValue = str_replace("\'", '"', $savedOptions['agca_script_js']);
$optionValue = str_replace('\"', "'", $optionValue);
update_option('agca_custom_js', $optionValue);
}
//echo $str;
//save imported settings
$this->saveAfterImport = true;
}
function exportSettings(){
$str = "";
$include_menu_settings = false;
if(isset($_POST['export_settings_include_admin_menu'])){
if($_POST['export_settings_include_admin_menu'] == 'on'){
$include_menu_settings = true;
}
}
foreach ($_POST as $key => $value) {
if ($this->startsWith($key,'ag')||$this->startsWith($key,'color')) {
if($this->startsWith($key,'ag_edit_adminmenu')){
if($include_menu_settings) $str .=$key. ":".$value."|^|^|";
}else{
$str .=$key. ":".$value."|^|^|";
}
}
}
$filename = __('AGCA_Settings', 'ag-custom-admin').'_'.date("Y-M-d_H-i-s").'.agca';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: text/plain; ");
header("Content-Transfer-Encoding: binary");
echo wp_kses_post($str);
die();
}
function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function agca_create_menu() {
add_management_page('AGCA', 'AGCA', 'administrator', __FILE__, array(&$this,'agca_admin_page') );
}
function filter_url($url = ''){
if (filter_var($url, FILTER_VALIDATE_URL)) {
return $url;
}
return $url;
}
function filter_target($target = '_self'){
return $target === '_blank' ? '_blank' : '_self';
}
function agca_create_admin_button($name,$arr) {
$href = $this->filter_url($arr["value"]);
$target = $this->filter_target($arr["target"]);
$button ="<li class=\"wp-not-current-submenu menu-top aaa menu-top-last\" id=\"menu-" . $this->sanitize_html($name) . "\"><a href=\"".$this->sanitize_html($href)."\" target=\"".$this->sanitize_html($target)."\" class=\"wp-not-current-submenu menu-top\"><div class=\"wp-menu-arrow\"><div></div></div><div class=\"wp-menu-image dashicons-before dashicons-admin-".$this->sanitize_html($name)."\" style=\"width:15px\"><br></div><div class=\"wp-menu-name\">".$this->sanitize_html($name)."</div></a></li>";
return $button;
}
function agca_decode($code){
$code = str_replace("{","",$code);
$code = str_replace("}","",$code);
$code = str_replace("\", \"","\"|||\"",$code);
$elements = explode("|||",$code);
return $elements;
}
function jsonMenuArray($json,$type){
$arr = explode("|",$json);
$elements = "";
$array ="";
$first = true;
//print_r($json);
if($type == "colorizer"){
$elements = json_decode($arr[0],true);
if($elements !=""){
return $elements;
}
}else if($type == "buttons"){
$elements = json_decode($arr[0],true);
if($elements !=""){
foreach($elements as $k => $v){
$array.=$this->agca_create_admin_button($k,$v);
}
}
}else if($type == "buttonsJq"){
$elements = json_decode($arr[0],true);
if($elements !=""){
foreach($elements as $k => $v){
$array.='<tr><td colspan="2"><button target="'.$this->sanitize_html($v['target']).'" title="'.$this->sanitize_html($v['value']).'" class="button-secondary" type="button">'.$this->sanitize_html($k).'</button> <a style="cursor:pointer;" title="Edit" class="button_edit"><span class="dashicons dashicons-edit"></span></a> <a style="cursor:pointer" title="Delete" class="button_remove"><span class="dashicons dashicons-no"></span></a></td><td></td></tr>';
}
}
}else{
if(isset($arr[$type])){
$elements = $this->agca_decode($arr[$type]);
}
if($elements !=""){
foreach($elements as $element){
if(!$first){
$array .=",";
}
$parts = explode(" : ",$element);
if(isset($parts[0]) && isset($parts[1])){
$array.="[".$parts[0].", ".$parts[1]."]";
}
$first=false;
}
}
}
return $array;
}
function remove_dashboard_widget($widget,$side)
{
//side can be 'normal' or 'side'
remove_meta_box($widget, 'dashboard', $side);
}
function get_wp_version(){
global $wp_version;
$array = explode('-', $wp_version);
$version = $array[0];
return $version;
}
function print_page()
{
if($this->isGuest() && get_option('agca_admin_bar_frontend_hide') or $this->isCusminActive()){
return false;
}
if(!$this->isGuest()){
?><style type="text/css">
<?php
echo $this->sanitize_html(get_option('agca_custom_css'));
if(get_option('agca_menu_remove_customize_button')){
echo '#wp-admin-bar-customize{display:none;}';
}
?>
</style><?php
}
if(get_option('agca_admin_bar_frontend_hide')==true){
if(!((get_option('agca_role_allbutadmin')==true) and (current_user_can($this->admin_capability())))) {
add_filter( 'show_admin_bar', '__return_false' );
?>
<style type="text/css">
#wpadminbar{
display: none;
}
</style>
<script type="text/javascript">
window.setTimeout(function(){document.getElementsByTagName('html')[0].setAttribute('style',"margin-top:0px !important");},50);
</script>
<?php
}
}
if(get_option('agca_admin_bar_frontend')!=true && is_user_logged_in()){
$this->context = "page";
//$wpversion = $this->get_wp_version();
?>
<script type="text/javascript">
var agca_version = "<?php echo $this->sanitize_html($this->agca_version); ?>";
var agca_debug = <?php echo ($this->agca_debug)?"true":"false"; ?>;
var jQueryScriptOutputted = false;
var agca_context = "page";
var agca_orig_admin_menu = [];
function initJQuery() {
//if the jQuery object isn't available
if (typeof(jQuery) == 'undefined') {
if (! jQueryScriptOutputted) {
console.log('AGCA: jQuery not found!!!');
}
} else {
jQuery(function() {
try
{
<?php if(get_option('agca_header')!=true){ ?>
jQuery('#wpadminbar').show();
<?php } ?>
<?php $this->print_admin_bar_scripts(); ?>
}catch(ex){}
});
}
}
initJQuery();
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
<?php if(get_option('agca_colorizer_turnonoff') == 'on' && (get_option('agca_admin_bar_frontend_hide')!=true)){
foreach($this->colorizer as $k => $v){
if(($k !="") and ($v !="")){
if(
$k == "color_header" ||
$k == "color_font_header"
){
?> updateTargetColor("<?php echo $this->sanitize_html($k);?>","<?php echo $this->sanitize_html($v);?>"); <?php
}
}
}
?>
<?php
}
?>
});
</script>
<?php
}
}
function is_safe_remote_image($url){
$imgCheck = wp_safe_remote_get($this->sanitize_html($url));
if(!is_wp_error($imgCheck)) {
$cid = $imgCheck['headers'];
if (strpos($cid->offsetGet('content-type'), 'image/') === 0) {
return true;
}
}
return false;
}
function print_admin_bar_scripts(){
?>
<?php if(get_option('agca_remove_top_bar_dropdowns')==true){ ?>
jQuery("#wpadminbar #wp-admin-bar-root-default > #wp-admin-bar-wp-logo .ab-sub-wrapper").hide();
jQuery("#wpadminbar #wp-admin-bar-root-default > #wp-admin-bar-site-name .ab-sub-wrapper").hide();
jQuery("#wpadminbar #wp-admin-bar-root-default > #wp-admin-bar-wp-logo .ab-item").attr('title','');
<?php if(get_option('agca_admin_bar_new_content')!=""){ ?>
jQuery(".new_content_header_submenu").hide();
<?php } ?>
<?php } ?>
<?php if(get_option('agca_admin_bar_comments')!=""){ ?>
jQuery("ul#wp-admin-bar-root-default li#wp-admin-bar-comments").css("display","none");
<?php } ?>
<?php if(get_option('agca_admin_bar_new_content')!=""){ ?>
jQuery("ul#wp-admin-bar-root-default li#wp-admin-bar-new-content").css("display","none");
<?php } ?>
<?php if(get_option('agca_admin_bar_new_content_post')!=""){ ?>
jQuery("ul#wp-admin-bar-root-default li#wp-admin-bar-new-content li#wp-admin-bar-new-post").css("display","none");
<?php } ?>
<?php if(get_option('agca_admin_bar_new_content_link')!=""){ ?>
jQuery("ul#wp-admin-bar-root-default li#wp-admin-bar-new-content li#wp-admin-bar-new-link").css("display","none");
<?php } ?>
<?php if(get_option('agca_admin_bar_new_content_page')!=""){ ?>
jQuery("ul#wp-admin-bar-root-default li#wp-admin-bar-new-content li#wp-admin-bar-new-page").css("display","none");
<?php } ?>
<?php if(get_option('agca_admin_bar_new_content_user')!=""){ ?>
jQuery("ul#wp-admin-bar-root-default li#wp-admin-bar-new-content li#wp-admin-bar-new-user").css("display","none");
<?php } ?>
<?php if(get_option('agca_admin_bar_new_content_media')!=""){ ?>
jQuery("ul#wp-admin-bar-root-default li#wp-admin-bar-new-content li#wp-admin-bar-new-media").css("display","none");
<?php } ?>
<?php if(get_option('agca_admin_bar_update_notifications')!=""){ ?>
jQuery("ul#wp-admin-bar-root-default li#wp-admin-bar-updates").css("display","none");
<?php } ?>
<?php if(get_option('agca_header_logo')==true){ ?>
jQuery("#wphead #header-logo").css("display","none");
jQuery("ul#wp-admin-bar-root-default li#wp-admin-bar-wp-logo").css("display","none");
<?php } ?>
<?php if(get_option('agca_header_logo_custom')!="" && $this->is_safe_remote_image(get_option('agca_header_logo_custom'))){ ?>
var img_url = '<?php echo $this->sanitize_html($this->sanitize_html(get_option('agca_header_logo_custom'))); ?>';
advanced_url = img_url;
image = jQuery("<img id=\"admin-top-branding-logo\" style='max-width:98%;position:relative;'/>").attr("src",advanced_url);
jQuery(image).on('load', function() {
jQuery("#wpbody-content").prepend(image);
});
<?php } ?>
<?php if(get_option('agca_wp_logo_custom')!="" && $this->is_safe_remote_image(get_option('agca_wp_logo_custom'))){ ?>
jQuery("li#wp-admin-bar-wp-logo a.ab-item span.ab-icon")
.html("<img alt=\"Logo\" style=\"height:32px;margin-top:0\" src=\"<?php echo $this->sanitize_html(get_option('agca_wp_logo_custom')); ?>\" />")
.css('background-image','none')
.css('width','auto');
jQuery("li#wp-admin-bar-wp-logo > a.ab-item")
.attr('href',"<?php echo $this->sanitize_html(get_bloginfo('wpurl')); ?>")
.css('padding', 0);
jQuery("#wpadminbar #wp-admin-bar-root-default > #wp-admin-bar-wp-logo .ab-item:before").attr('title','');
jQuery('body #wpadminbar #wp-admin-bar-wp-logo > .ab-item .ab-icon').attr('class','ab-icon2');
jQuery("#wp-admin-bar-wp-logo").show();
<?php }?>
<?php if(get_option('agca_remove_site_link')==true){ ?>
jQuery("#wp-admin-bar-site-name").css("display","none");
<?php } ?>
<?php if(get_option('agca_wp_logo_custom_link')!=""){ ?>
<?php
$href = get_option('agca_wp_logo_custom_link');
$href = str_replace(self::PLACEHOLDER_BLOG, get_bloginfo('wpurl'), $href);
?>
var href = "<?php echo esc_url($href); ?>";
if(href == "%SWITCH%"){
href = "<?php echo $this->sanitize_html(get_bloginfo('wpurl')); ?>";
<?php if($this->context == "page"){
?>href+="/wp-admin";<?php
}
?>
}
jQuery("li#wp-admin-bar-wp-logo a.ab-item").attr('href',href);
<?php }?>
<?php if(get_option('agca_site_heading')==true){ ?>
jQuery("#wphead #site-heading").css("display","none");
<?php } ?>
<?php if(get_option('agca_custom_site_heading')!=""){ ?>
jQuery("#wp-admin-bar-site-name a:first").html("<?php echo (htmlentities(get_option('agca_custom_site_heading'))); ?>");
<?php } ?>
<?php if(get_option('agca_header')==true && $this->context =='admin'){