forked from alexkalh/aegis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aegis.php
1467 lines (1209 loc) · 53.2 KB
/
aegis.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
/**
* Plugin Name: Aegis
* Plugin URI: http://colourstheme.com/plugins/aegis-page-builder
* Description: Build responsive page layouts using the widgets you know and love using this simple drag and drop page builder. Your content will accurately adapt to all mobile devices, ensuring your site is mobile-ready.
* Version: 1.4
* Author: Colours Theme
* Author URI: http://colourstheme.com
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* Aegis plugin, Copyright 2014 Colourstheme
* Aegis is distributed under the terms of the GNU GPL.
*
* Requires at least: 4.4
* Tested up to: 4.8
* Text Domain: aegis
* Domain Path: /languages/
*/
/**
* Aegis - Visual page builder
*
* @package Colours
* @subpackage Aegis
*/
define( 'AEGIS_DIR_URL', plugin_dir_url( __FILE__ ) );
define( 'AEGIS_DIR_PATH', plugin_dir_path( __FILE__ ) );
add_action( 'plugins_loaded', array( 'Aegis', 'plugins_loaded' ) );
add_action( 'after_setup_theme', array( 'Aegis', 'get_instance' ) );
if( !class_exists( 'Aegis' ) ) {
if ( version_compare( $wp_version, '4.8', '>=' ) ) {
add_action('widgets_init', function() { require_once AEGIS_DIR_PATH . '/widgets/class-wp-widget-text.php'; } );
}
class Aegis {
protected static $instance = null;
public function __construct() {
if ( is_admin() ) {
global $wp_version;
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
add_action( 'admin_footer', array( $this, 'admin_footer' ) );
add_action( 'wp_ajax_aegis_get_widget_form', array( $this, 'get_widget_form' ) );
add_action( 'wp_ajax_aegis_save_widget', array( $this, 'save_widget' ) );
add_action( 'wp_ajax_aegis_remove_widget', array( $this, 'remove_widget' ) );
add_action( 'wp_ajax_aegis_save_all', array( $this, 'save_all' ) );
add_action( 'wp_ajax_aegis_get_row_customize_form', array( $this, 'get_row_customize_form' ) );
add_action( 'wp_ajax_aegis_save_row_customize_form', array( $this, 'save_row_customize_form' ) );
add_action( 'wp_ajax_aegis_get_col_customize_form', array( $this, 'get_col_customize_form' ) );
add_action( 'wp_ajax_aegis_save_col_customize_form', array( $this, 'save_col_customize_form' ) );
if ( version_compare( $wp_version, '4.8', '>=' ) ) {
add_filter( 'aegis_get_list_of_widgets', array( $this, 'remove_widgets_required_by_backbone' ) );
add_filter( 'aegis_get_widget_form_widget_class_name', array( $this, 'get_widget_form_widget_class_name' ) );
}
}
add_shortcode( 'a_site_url', array( $this, 'get_site_url' ) );
add_shortcode( 'a_media', array( $this, 'get_responsive_media' ) );
}
public function remove_widgets_required_by_backbone($widgets) {
unset($widgets['WP_Widget_Media_Audio']);
unset($widgets['WP_Widget_Media_Video']);
unset($widgets['WP_Widget_Media_Image']);
return $widgets;
}
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
public static function plugins_loaded() {
load_plugin_textdomain( 'aegis', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
}
public static function get_meta_key_widget_customize() {
return apply_filters( 'aegis_get_meta_key_widget_customize', 'aegis_widget_customize' );
}
public static function get_meta_key_page_customize() {
return apply_filters( 'aegis_get_meta_key_page_customize', 'aegis_page_customize' );
}
public static function get_meta_key_page() {
return apply_filters( 'aegis_get_meta_key_page', 'aegis_page' );
}
public static function get_meta_key_col() {
return apply_filters( 'aegis_get_meta_key_col_customize', 'aegis_col' );
}
public static function get_meta_key_row() {
return apply_filters( 'aegis_get_meta_key_row_customize', 'aegis_row' );
}
public static function get_meta_key_widget() {
return apply_filters( 'aegis_get_meta_key_widget', 'aegis_widget' );
}
public static function get_meta_key_is_cache() {
return apply_filters( 'aegis_get_meta_key_is_cache', 'aegis_is_cache' );
}
public static function save_custom_css( $css = '', $post_id = 0 ) {
if ( $css && $post_id ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
global $wp_filesystem;
$upload_dir = wp_upload_dir();
$dir = trailingslashit( $upload_dir['basedir'] ) . 'aegis/';
$file_name = "page_{$post_id}.css";
WP_Filesystem();
$wp_filesystem->mkdir( $dir );
$wp_filesystem->put_contents( $dir . $file_name, $css, 0644 );
update_post_meta( $post_id, self::get_meta_key_is_cache(), 1 );
}
}
public static function extract_shortcode( $content, $is_multi = false, $allow_shortcodes = array() ) {
$media = array();
$regex_matches = '';
$regex_pattern = get_shortcode_regex();
preg_match_all( '/' . $regex_pattern . '/s', $content, $regex_matches );
foreach ( $regex_matches[0] as $shortcode ) {
$regex_matches_new = '';
preg_match( '/' . $regex_pattern . '/s', $shortcode, $regex_matches_new );
if ( in_array( $regex_matches_new[2], $allow_shortcodes, false ) ) :
$media[] = array(
'shortcode' => $regex_matches_new[0],
'type' => $regex_matches_new[2],
'content' => $regex_matches_new[5],
'atts' => shortcode_parse_atts( $regex_matches_new[3] ),
);
if ( false == $is_multi ) {
break;
}
endif;
}
return $media;
}
public static function get_allowed_tags() {
$allowed_tag = wp_kses_allowed_html( 'post' );
$allowed_tag['div']['data-index'] = array();
$allowed_tag['div']['data-tab-id'] = array();
$allowed_tag['span']['data-tab-id'] = array();
$allowed_tag['iframe']['src'] = array();
$allowed_tag['iframe']['height'] = array();
$allowed_tag['iframe']['width'] = array();
$allowed_tag['iframe']['frameborder'] = array();
$allowed_tag['iframe']['allowfullscreen'] = array();
$allowed_tag['input']['class'] = array();
$allowed_tag['input']['id'] = array();
$allowed_tag['input']['name'] = array();
$allowed_tag['input']['value'] = array();
$allowed_tag['input']['type'] = array();
$allowed_tag['input']['checked'] = array();
$allowed_tag['input']['data-default-color'] = array();
$allowed_tag['select']['class'] = array();
$allowed_tag['select']['id'] = array();
$allowed_tag['select']['name'] = array();
$allowed_tag['select']['value'] = array();
$allowed_tag['select']['type'] = array();
$allowed_tag['option']['selected'] = array();
$allowed_tag['style']['type'] = array();
$allowed_tag['code'] = array();
$microdata_tags = array( 'div', 'section', 'article', 'a', 'span', 'img', 'time', 'figure' );
foreach ( $microdata_tags as $tag ) {
$allowed_tag[ $tag ]['itemscope'] = array();
$allowed_tag[ $tag ]['itemtype'] = array();
$allowed_tag[ $tag ]['itemprop'] = array();
}
return apply_filters( 'aegis_get_allowed_tags', $allowed_tag );
}
public function get_widget_form_widget_class_name($widget_class_name) {
if( 'WP_Widget_Text' === $widget_class_name ) {
$widget_class_name = 'Aegis_Widget_Text';
}
return $widget_class_name;
}
public function admin_init() {}
public function admin_enqueue_scripts( $hook ) {
if ( in_array( $hook, array( 'post-new.php', 'post.php' ), false ) ) {
global $post;
$post_types = apply_filters( 'aegis_apply_for_post_types', array( 'page' ) );
if( in_array( $post->post_type, $post_types, false) ){
// Script
wp_enqueue_media();
wp_enqueue_script( 'jquery-form' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-ui-tooltip' );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'jquery-amaran', plugins_url( 'js/jquery.amaran.js', __FILE__ ), array( 'jquery' ), null, true );
wp_enqueue_script( 'aegis', plugins_url( 'js/aegis.js', __FILE__ ), array( 'jquery' ), null, true );
wp_localize_script('aegis', 'aegis_json', array(
'directory_uri' => AEGIS_DIR_URL,
'ajax' => admin_url( 'admin-ajax.php' ),
'i18n' => array(
'layouts' => esc_html__( 'Layouts', 'aegis' ),
'row' => esc_html__( 'Row', 'aegis' ),
'column' => esc_html__( 'Column', 'aegis' ),
'widget' => esc_html__( 'Widget', 'aegis' ),
'elements' => esc_html__( 'Elements', 'aegis' ),
'row_customize' => esc_html__( 'Row customize', 'aegis' ),
'col_customize' => esc_html__( 'Column customize', 'aegis' ),
'media_center' => esc_html__( 'Media center', 'aegis' ),
'use' => esc_html__( 'Use', 'aegis' ),
'drag_row_to_reorder' => esc_html__( 'Drag row to reorder', 'aegis' ),
'split_row_to_multi_columns' => esc_html__( 'Split row to multi columns', 'aegis' ),
'edit_this_row' => esc_html__( 'Edit this row', 'aegis' ),
'delete_this_row' => esc_html__( 'Delete this row', 'aegis' ),
'drag_column_to_reorder' => esc_html__( 'Drag column to reorder', 'aegis' ),
'insert_new_widget_to_this_column' => esc_html__( 'Insert new widget to this column', 'aegis' ),
'edit_this_column' => esc_html__( 'Edit this column', 'aegis' ),
'drag_widget_to_reorder' => esc_html__( 'Drag widget to reorder', 'aegis' ),
'delete_this_widget' => esc_html__( 'Delete this widget', 'aegis' ),
'edit_this_widget' => esc_html__( 'Edit this widget', 'aegis' ),
'save_and_exit' => esc_html__( 'Save and Exit', 'aegis' ),
'save' => esc_html__( 'Save', 'aegis' ),
),
'layouts' => $this->get_grid(),
'key' => array(
'widget' => self::get_meta_key_widget(),
'col' => self::get_meta_key_col(),
'row' => self::get_meta_key_row(),
),
)
);
// Style
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'themify-icons', plugins_url( 'css/themify-icons.css', __FILE__ ), array(), null );
wp_enqueue_style( 'animate', plugins_url( 'css/animate.css', __FILE__ ), array(), null );
wp_enqueue_style( 'jquery-amaran', plugins_url( 'css/jquery.amaran.css', __FILE__ ), array(), null );
wp_enqueue_style( 'aegis', plugins_url( 'css/aegis.css', __FILE__ ), array(), null );
}
}
}
public function admin_footer() {
wp_nonce_field( 'aegis_get_row_customize_form', 'aegis_get_row_customize_form_security', false );
wp_nonce_field( 'aegis_get_col_customize_form', 'aegis_get_col_customize_form_security', false );
wp_nonce_field( 'aegis_get_widget_form', 'aegis_get_widget_form_security', false );
wp_nonce_field( 'aegis_remove_widget', 'aegis_remove_widget_security', false );
wp_nonce_field( 'aegis_save_all', 'aegis_save_all_security', false );
$this->pre_load_modals();
}
public function add_meta_boxes() {
$post_types = apply_filters( 'aegis_apply_for_post_types', array( 'page' ) );
add_meta_box( 'aegis_metabox', esc_html__( 'Aegis', 'aegis' ), array( $this, 'get_metabox_form' ), $post_types, 'advanced', 'high' );
}
public function get_metabox_form( $post ) {
wp_nonce_field( 'aegis_nonce', 'aegis_nonce' );
?>
<div class="a_wrap a_clearfix">
<div class="a_row_wrap a_body a_clearfix">
<?php
$key = self::get_meta_key_page();
$data = get_post_meta( $post->ID, $key, true );
$grid = $this->get_grid();
if ( $data ) :
$rows = isset( $data['rows'] ) && ! empty( $data['rows'] ) ? $data['rows'] : array();
if ( $rows ) :
foreach ( $rows as $row_index => $row ) :
$grid_index = (int) $row['index'];
?>
<div id="<?php echo esc_attr( $row['id'] ); ?>" class="a_grid_item" data-index="<?php echo esc_attr( $grid_index ); ?>">
<div class="a_header a_clearfix">
<span class="a_action a_hanle a_row_hanle a_pull_left a_tooltip" title="<?php esc_attr_e( 'Drag row to reorder', 'aegis' ); ?>"><i class="ti-split-v"></i></span>
<span class="a_action a_row_style a_pull_left a_tooltip" title="<?php esc_attr_e( 'Split row to multi columns', 'aegis' ); ?>"><i class="ti-layout-column3"></i></span>
<?php
$row_customize_fields = apply_filters( 'aegis_get_row_customize_fields', array(), $post->ID );
if ( $row_customize_fields ) :
?>
<span class="a_action a_row_customize a_pull_left a_tooltip" title="<?php esc_attr_e( 'Edit this row', 'aegis' ); ?>"><i class="ti-pencil"></i></span>
<?php endif; ?>
<span class="a_action a_close a_row_close a_pull_right a_tooltip" title="<?php esc_attr_e( 'Delete this row', 'aegis' ); ?>"><i class="ti-trash"></i></span>
</div>
<div class="a_body a_clearfix">
<div class="a_column_wrap a_row a_clearfix">
<?php
$cols = isset( $row['cols'] ) && ! empty( $row['cols'] ) ? $row['cols'] : array();
if ( $cols ) :
foreach ( $cols as $col_index => $col ) :
$col_index = (int) $col['index'];
?>
<div id="<?php echo esc_attr( $col['id'] ); ?>" class="a_column_item_outer <?php echo esc_attr( "a_col_{$col_index}" ); ?>" data-index="<?php echo esc_attr( $col_index ); ?>">
<div class="a_column_item">
<div class="a_header a_clearfix">
<span class="a_action a_hanle a_column_hanle a_pull_left a_tooltip" title="<?php esc_attr_e( 'Drag column to reorder', 'aegis' ); ?>"><i class="ti-split-v"></i></span>
<span class="a_action a_column_add_widget a_pull_left a_tooltip" title="<?php esc_attr_e( 'Insert new widget to this column', 'aegis' ); ?>"><i class="ti-package"></i></span>
<?php
$col_customize_fields = apply_filters( 'aegis_get_col_customize_fields', array(), $post->ID );
if ( $col_customize_fields ) :
?>
<span class="a_action a_col_customize a_pull_left a_tooltip" title="<?php esc_attr_e( 'Edit this column', 'aegis' ); ?>"><i class="ti-pencil"></i></span>
<?php endif; ?>
</div>
<div class="a_block_wrap a_body a_clearfix">
<?php
$widgets = isset( $col['widgets'] ) && ! empty( $col['widgets'] ) ? $col['widgets'] : array();
if ( $widgets ) :
foreach ( $widgets as $widget_index => $widget ) :
$widget_id = isset( $widget['id'] ) && ! empty( $widget['id'] ) ? $widget['id'] : false;
$widget_name = isset( $widget['name'] ) && ! empty( $widget['name'] ) ? $widget['name'] : false;
if ( $widget_id ) :
?>
<div id="<?php echo esc_attr( $widget_id ); ?>" class="a_block a_clearfix">
<div class="a_header a_clearfix">
<span class="a_action a_hanle a_block_hanle a_pull_left a_tooltip" title="<?php esc_attr_e( 'Drag widget to reorder', 'aegis' ); ?>"><i class="ti-split-v"></i></span>
<span class="a_action a_block_edit a_pull_left a_tooltip" title="<?php esc_attr_e( 'Edit this widget', 'aegis' ); ?>"><i class="ti-pencil"></i></span>
<span class="a_action a_close a_block_close a_pull_right a_tooltip" title="<?php esc_attr_e( 'Delete this widget', 'aegis' ); ?>"><i class="ti-trash"></i></span>
</div>
<div class="a_body a_clearfix"><?php echo esc_attr( $widget_name ); ?></div>
</div>
<?php
endif;
endforeach;
endif;
?>
</div>
</div>
</div>
<?php
endforeach;
endif;
?>
</div>
</div>
</div>
<?php
endforeach;
endif;
endif;
?>
</div>
<div class="a_footer a_clearfix">
<span class="a_button a_left a_add_row">
<i class="a_icon ti-plus"></i>
<span class="a_text"><?php esc_html_e( 'Add new row', 'aegis' ); ?></span>
</span>
<span class="a_button a_right a_pull_right a_save_all">
<i class="a_icon ti-save"></i>
<span class="a_text"><?php esc_html_e( 'Save all', 'aegis' ); ?></span>
</span>
</div>
</div>
<?php
}
public function pre_load_modals() {
$screen = get_current_screen();
if ( $screen->base == 'post' ) {
global $post;
$post_types = apply_filters( 'aegis_apply_for_post_types', array( 'page' ) );
if ( in_array( $post->post_type, $post_types ) ) {
global $wp_widget_factory;
?>
<div id="aegis_dialog_overlay"></div>
<div class="hide_all">
<?php
$grid = $this->get_grid();
if ( $grid ) :
?>
<div id="a_modal_grid" class="a_wrap">
<div class="a_row a_clearfix">
<?php
$index = 0;
foreach ( $grid as $grid_index => $cols ) :
?>
<div class="a_col_4">
<div class="a_row_mockup" data-index="<?php echo esc_attr( $grid_index ); ?>">
<div class="a_row a_clearfix">
<?php foreach ( $cols as $col ) : ?>
<div class="a_col <?php echo esc_attr( "a_col_{$col}" ); ?>">
<div class="a_col_mockup">
<?php echo esc_attr( $col ); ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<?php
$index++;
if ( 0 == $index % 3 && $index < count( $grid ) ) {
echo '</div>';
echo '<div class="a_row a_clearfix">';
}
endforeach;
?>
</div>
</div>
<?php endif; ?>
<div id="a_modal_widgets" class="a_wrap a_clearfix">
<?php
$widgets = $wp_widget_factory->widgets;
$widgets = apply_filters( 'aegis_get_list_of_widgets', $widgets, $post );
$blocks = array();
foreach ( $widgets as $class_name => $widget_info ) {
if ( isset( $widget_info->aegis_tab ) && ! empty( $widget_info->aegis_tab ) ) {
$tab_slug = $widget_info->aegis_tab;
} else {
if ( strpos( strtolower( $widget_info->name ), 'bbpress' ) ) {
$tab_slug = 'bbpress';
} else if ( strpos( strtolower( $widget_info->name ), 'commerce' ) ) {
$tab_slug = 'product';
} else {
$tab_slug = 'widgets';
}
}
if ( ! isset( $blocks[ $tab_slug ] ) ) {
$blocks[ $tab_slug ]['title'] = $this->str_beautify( $tab_slug );
}
$blocks[ $tab_slug ]['items'][ $class_name ] = $widget_info;
}
ksort( $blocks );
?>
<div class="a_tabs">
<nav class="a_nav">
<ul class="a_clearfix">
<?php
$is_first = true;
foreach ( $blocks as $tab_slug => $tab ) :
$tab_id = "#aegis_tab_block_{$tab_slug}";
$tab_class = $is_first ? 'a_tab_item a_first a_active' : 'a_tab_item';
?>
<li class="<?php echo esc_attr( $tab_class ); ?>">
<span data-tab-id="<?php echo esc_attr( $tab_id ); ?>"><?php echo esc_attr( $tab['title'] ); ?></span>
</li>
<?php
$is_first = false;
endforeach;
?>
</ul>
</nav>
<?php
$is_first = true;
foreach ( $blocks as $tab_slug => $tab ) :
$index = 0;
$tab_id = "aegis_tab_block_{$tab_slug}";
$tab_class = $is_first ? 'a_tab_content a_first a_active' : 'a_tab_content a_hide';
?>
<div id="<?php echo esc_attr( $tab_id ); ?>" class="<?php echo esc_attr( $tab_class ); ?>">
<div class="a_row a_clearfix">
<?php
$widgets = $tab['items'];
foreach ( $widgets as $class_name => $widget_info ) :
?>
<div class="a_col_3">
<div class="a_item">
<?php
$icon = 'ti-wordpress';
if ( isset( $widget_info->icon ) && ! empty( $widget_info->icon ) ) {
$icon = $widget_info->icon;
}
?>
<input type="hidden" name="a_widget_class_name" value="<?php echo esc_attr( $class_name ); ?>" autocomplete="off">
<input type="hidden" name="a_widget_title" value="<?php echo esc_attr( $widget_info->name ); ?>" autocomplete="off">
<p class="a_icon">
<i class="<?php echo esc_attr( $icon ); ?>"></i>
</p>
<p class="a_title"><?php echo esc_attr( $widget_info->name ); ?></p>
<div class="a_desc"><?php echo esc_attr( $widget_info->widget_options['description'] ); ?></div>
</div>
</div>
<?php
$index++;
if ( 0 == $index % 4 ) {
echo '</div>';
echo '<div class="a_row a_clearfix">';
}
endforeach;
?>
</div>
</div>
<?php
$is_first = false;
endforeach;
?>
</div>
</div>
<?php $form_action = wp_nonce_url( admin_url( 'admin-ajax.php' ), 'aegis_save_widget', 'security' ); ?>
<form id="a_modal_single_widget" class="a_wrap a_clearfix" name="a_form_single_widget" method="POST" autocomplete="off" onsubmit="AegisAjax.saveWidget(event, jQuery(this));" action="<?php echo esc_url( $form_action ); ?>">
<input type="hidden" name="action" value="aegis_save_widget" autocomplete="off">
<input type="hidden" name="a_widget_class_name" value="" autocomplete="off">
<input type="hidden" name="a_widget_title" value="" autocomplete="off">
<input type="hidden" name="a_widget_id" value="" autocomplete="off">
<input type="hidden" name="a_post_id" value="<?php echo esc_attr( (int) $post->ID ); ?>" autocomplete="off">
<div class="a_widget_form a_tabs"></div>
</form>
<?php $form_action = wp_nonce_url( admin_url( 'admin-ajax.php' ), 'aegis_save_row_customize_form', 'security' ); ?>
<form id="a_modal_row_customize" class="a_wrap a_clearfix" name="a_form_single_row" method="POST" autocomplete="off" onsubmit="AegisAjax.saveRowCustomize(event, jQuery(this));" action="<?php echo esc_url( $form_action ); ?>">
<input type="hidden" name="action" value="aegis_save_row_customize_form" autocomplete="off">
<input type="hidden" name="a_row_id" value="" autocomplete="off">
<input type="hidden" name="a_post_id" value="<?php echo esc_attr( (int) $post->ID ); ?>" autocomplete="off">
<div class="a_row_customize_form a_tabs"></div>
</form>
<?php $form_action = wp_nonce_url( admin_url( 'admin-ajax.php' ), 'aegis_save_col_customize_form', 'security' ); ?>
<form id="a_modal_col_customize" class="a_wrap a_clearfix" name="a_form_single_col" method="POST" autocomplete="off" onsubmit="AegisAjax.saveColCustomize(event, jQuery(this));" action="<?php echo esc_url( $form_action ); ?>">
<input type="hidden" name="action" value="aegis_save_col_customize_form" autocomplete="off">
<input type="hidden" name="a_col_id" value="" autocomplete="off">
<input type="hidden" name="a_post_id" value="<?php echo esc_attr( (int) $post->ID ); ?>" autocomplete="off">
<div class="a_col_customize_form a_tabs"></div>
</form>
</div>
<?php
}
}
}
public function get_grid() {
$grid = array(
array( 12 ),
array( 10, 2 ),
array( 8, 4 ),
array( 7, 5 ),
array( 7, 2, 3 ),
array( 6, 6 ),
array( 5, 4, 3 ),
array( 4, 4, 4 ),
array( 4, 6, 2 ),
array( 3, 9 ),
array( 3, 6, 3 ),
array( 3, 3, 3, 3 ),
array( 2, 8, 2 ),
array( 2, 2, 2, 6 ),
array( 2, 2, 2, 2, 2, 2 ),
);
return apply_filters( 'aegis_get_grid', $grid );
}
public function save_all() {
check_ajax_referer( 'aegis_save_all', 'security' );
$data = isset( $_POST['data'] ) ? $_POST['data'] : false;
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : false;
$return = '';
if ( $post_id ) {
$meta_key = self::get_meta_key_page();
if ( $data ) {
update_post_meta( $post_id, $meta_key, $data );
do_action( 'aegis_save_all_success', $post_id, $data );
$return = esc_html__( 'All data has been saved !', 'aegis' );
} else {
delete_post_meta( $post_id, $meta_key );
$widget_key = self::get_meta_key_widget();
$row_key = self::get_meta_key_row();
global $wpdb;
$wpdb->query( $wpdb->prepare( "delete from $wpdb->postmeta where post_id = %d and meta_key like %s", $post_id, "{$widget_key}_%" ) );
$wpdb->query( $wpdb->prepare( "delete from $wpdb->postmeta where post_id = %d and meta_key like %s", $post_id, "{$row_key}_%" ) );
$return = esc_html__( 'All data has been cleaned.', 'aegis' );
wp_reset_query();
}
update_post_meta( $post_id, self::get_meta_key_is_cache(), 0 );
}
echo esc_attr( $return );
exit();
}
public function get_row_customize_form() {
check_ajax_referer( 'aegis_get_row_customize_form', 'security' );
$row_id = isset( $_POST['row_id'] ) ? $_POST['row_id'] : false;
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : false;
$customize_key = self::get_meta_key_row();
$customize_fields = apply_filters( 'aegis_get_row_customize_fields', array(), $post_id );
if ( $customize_fields ) :
$customize_data = array();
if ( $row_id ) {
$customize_data = get_post_meta( $post_id, $row_id, true );
}
?>
<nav class="a_nav">
<ul class="a_clearfix">
<?php
$is_first = true;
foreach ( $customize_fields as $tab_slug => $tab ) :
$tab_id = "#aegis_tab_row_{$tab_slug}";
$tab_class = $is_first ? 'a_tab_item a_first a_active' : 'a_tab_item';
?>
<li class="<?php echo esc_attr( $tab_class ); ?>">
<span data-tab-id="<?php echo esc_attr( $tab_id ); ?>"><?php echo esc_attr( $tab['title'] ); ?></span>
</li>
<?php
$is_first = false;
endforeach;
?>
</ul>
</nav>
<?php
$is_first = true;
foreach ( $customize_fields as $tab_slug => $tab ) :
$tab_id = "aegis_tab_row_{$tab_slug}";
$tab_class = $is_first ? 'a_tab_content a_first a_active' : 'a_tab_content a_hide';
?>
<div id="<?php echo esc_attr( $tab_id ); ?>" class="<?php echo esc_attr( $tab_class ); ?>">
<?php
foreach ( $tab['params'] as $param_key => $param_args ) :
$param_args['name'] = sprintf( '%s[%s][%s]', $customize_key, $tab_slug, $param_key );
$param_args['value'] = isset( $customize_data[ $tab_slug ][ $param_key ] ) ? $customize_data[ $tab_slug ][ $param_key ] : (isset( $param_args['default'] ) ? $param_args['default'] : null);
$param_args['attributes'] = $this->get_custom_attributes_for_field( $param_args );
$this->get_control( $param_args );
endforeach;
?>
</div>
<?php
$is_first = false;
endforeach;
endif;
exit();
}
public function save_row_customize_form() {
check_ajax_referer( 'aegis_save_row_customize_form', 'security' );
$return = '';
if ( ! empty( $_POST ) ) {
$customize_key = self::get_meta_key_row();
$row_id = isset( $_POST['a_row_id'] ) ? $_POST['a_row_id'] : false;
$post_id = isset( $_POST['a_post_id'] ) ? (int) $_POST['a_post_id'] : false;
$customize_fields = apply_filters( 'aegis_get_row_customize_fields', array(), $post_id );
if ( $customize_key ) {
$data = isset( $_POST[ $customize_key ] ) ? $_POST[ $customize_key ] : array();
if ( $data ) {
foreach ( $customize_fields as $tab_slug => $tab ) {
foreach ( $tab['params'] as $param_key => $param_args ) {
$new_value = isset( $data[ $tab_slug ][ $param_key ] ) ? $data[ $tab_slug ][ $param_key ] : null;
$data[ $tab_slug ][ $param_key ] = $this->esc_data( $param_args, $new_value );
}
}
update_post_meta( $post_id, $row_id, $data );
}
$return = esc_html__( 'All data has been saved !', 'aegis' );
update_post_meta( $post_id, self::get_meta_key_is_cache(), 0 );
}
}
echo esc_attr( $return );
exit();
}
public function get_col_customize_form() {
check_ajax_referer( 'aegis_get_col_customize_form', 'security' );
$col_id = isset( $_POST['col_id'] ) ? $_POST['col_id'] : false;
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : false;
$customize_key = self::get_meta_key_col();
$customize_fields = apply_filters( 'aegis_get_col_customize_fields', array(), $post_id );
if ( $customize_fields ) :
$customize_data = array();
if ( $col_id ) {
$customize_data = get_post_meta( $post_id, $col_id, true );
}
?>
<nav class="a_nav">
<ul class="a_clearfix">
<?php
$is_first = true;
foreach ( $customize_fields as $tab_slug => $tab ) :
$tab_id = "#aegis_tab_col_{$tab_slug}";
$tab_class = $is_first ? 'a_tab_item a_first a_active' : 'a_tab_item';
?>
<li class="<?php echo esc_attr( $tab_class ); ?>">
<span data-tab-id="<?php echo esc_attr( $tab_id ); ?>"><?php echo esc_html( $tab['title'] ); ?></span>
</li>
<?php
$is_first = false;
endforeach;
?>
</ul>
</nav>
<?php
$is_first = true;
foreach ( $customize_fields as $tab_slug => $tab ) :
$tab_id = "aegis_tab_col_{$tab_slug}";
$tab_class = $is_first ? 'a_tab_content a_first a_active' : 'a_tab_content a_hide';
?>
<div id="<?php echo esc_attr( $tab_id ); ?>" class="<?php echo esc_attr( $tab_class ); ?>">
<?php
foreach ( $tab['params'] as $param_key => $param_args ) :
$param_args['name'] = sprintf( '%s[%s][%s]', $customize_key, $tab_slug, $param_key );
$param_args['value'] = isset( $customize_data[ $tab_slug ][ $param_key ] ) ? $customize_data[ $tab_slug ][ $param_key ] : (isset( $param_args['default'] ) ? $param_args['default'] : null);
$param_args['attributes'] = $this->get_custom_attributes_for_field( $param_args );
$this->get_control( $param_args );
endforeach;
?>
</div>
<?php
$is_first = false;
endforeach;
endif;
exit();
}
public function save_col_customize_form() {
check_ajax_referer( 'aegis_save_col_customize_form', 'security' );
$return = '';
if ( ! empty( $_POST ) ) {
$col_id = isset( $_POST['a_col_id'] ) ? $_POST['a_col_id'] : false;
$post_id = isset( $_POST['a_post_id'] ) ? (int) $_POST['a_post_id'] : false;
$customize_key = self::get_meta_key_col();
$customize_fields = apply_filters( 'aegis_get_col_customize_fields', array(), $post_id );
if ( $customize_key ) {
$data = isset( $_POST[ $customize_key ] ) ? $_POST[ $customize_key ] : array();
if ( $data ) {
foreach ( $customize_fields as $tab_slug => $tab ) {
foreach ( $tab['params'] as $param_key => $param_args ) {
$new_value = isset( $data[ $tab_slug ][ $param_key ] ) ? $data[ $tab_slug ][ $param_key ] : null;
$data[ $tab_slug ][ $param_key ] = $this->esc_data( $param_args, $new_value );
}
}
update_post_meta( $post_id, $col_id, $data );
}
$return = esc_html__( 'All data has been saved !', 'aegis' );
update_post_meta( $post_id, self::get_meta_key_is_cache(), 0 );
}
}
echo esc_attr( $return );
exit();
}
public function get_widget_form() {
check_ajax_referer( 'aegis_get_widget_form', 'security' );
$widget_class_name = isset( $_POST['widget_class_name'] ) ? $_POST['widget_class_name'] : false;
$widget_id = isset( $_POST['widget_id'] ) ? $_POST['widget_id'] : false;
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : false;
if ( $post_id ) :
$instance = array();
$customize_data = array();
if ( $widget_id ) {
$widget_saved_data = get_post_meta( $post_id, $widget_id, true );
$instance = isset( $widget_saved_data['instance'] ) ? (array) $widget_saved_data['instance'] : array();
$customize_data = isset( $widget_saved_data['customize'] ) ? $widget_saved_data['customize'] : array();
}
if ( ! empty( $widget_saved_data ) && empty( $widget_class_name ) ) {
$widget_class_name = isset( $widget_saved_data['class_name'] ) ? $widget_saved_data['class_name'] : false;
}
if ( $widget_class_name ) :
$widget_class_name = apply_filters( 'aegis_get_widget_form_widget_class_name', $widget_class_name );
$widget = new $widget_class_name;
$widget->id_base = rand( 0, 9999 );
$widget->number = rand( 0, 9999 );
$customize_key = self::get_meta_key_widget_customize();
$customize_fields = apply_filters( 'aegis_get_widget_customize_fields', array() );
?>
<nav class="a_nav">
<ul class="a_clearfix">
<li class="a_tab_item a_first a_active">
<span data-tab-id="#aegis_tab_widget"><?php esc_html_e( 'Widget', 'aegis' ); ?></span>
</li>
<?php
if ( $customize_fields ) :
foreach ( $customize_fields as $tab_slug => $tab ) :
$tab_id = "#aegis_tab_widget_{$tab_slug}";
?>
<li class="a_tab_item">
<span data-tab-id="<?php echo esc_attr( $tab_id ); ?>"><?php echo esc_attr( $tab['title'] ); ?></span>
</li>
<?php
endforeach;
endif;
?>
</ul>
</nav>
<div id="aegis_tab_widget" class="a_tab_content a_active">
<?php $widget->form( $instance ); ?>
</div>
<?php
if ( $customize_fields ) :
foreach ( $customize_fields as $tab_slug => $tab ) :
$tab_id = "aegis_tab_widget_{$tab_slug}";
?>
<div id="<?php echo esc_attr( $tab_id ); ?>" class="a_tab_content a_hide">
<?php
foreach ( $tab['params'] as $param_key => $param_args ) :
$param_args['name'] = sprintf( '%s[%s][%s]', $customize_key, $tab_slug, $param_key );
$param_args['value'] = isset( $customize_data[ $tab_slug ][ $param_key ] ) ? $customize_data[ $tab_slug ][ $param_key ] : (isset( $param_args['default'] ) ? $param_args['default'] : null);
$param_args['attributes'] = $this->get_custom_attributes_for_field( $param_args );
$this->get_control( $param_args );
endforeach;
?>
</div>
<?php
endforeach;
endif;
endif;
endif;
exit();
}
public function save_widget() {
check_ajax_referer( 'aegis_save_widget', 'security' );
if ( ! empty( $_POST ) ) :
$form_data = $_POST;
$post_id = false;
$widget_id = false;
$data = array();
$data['widget'] = array();
$data['class_name'] = array();
$customize_key = self::get_meta_key_widget_customize();
$response = array( 'is_first' => 1, 'html' => '' );
foreach ( $form_data as $key => $value ) {
if ( 'a_post_id' == $key ) {
$post_id = (int) $value;
} else if ( 'widget' == substr( $key, 0, 6 ) ) {
$data['instance'] = reset( $value );
} else if ( 'a_widget_class_name' == $key ) {
$data['class_name'] = $value;
} else if ( 'a_widget_id' == $key ) {
$widget_id = $value;
} else if ( 'a_widget_title' == $key ) {
$data['name'] = $value;
} else if ( $customize_key == $key ) {
$data['customize'] = $value;
if ( $data ) {
$customize_fields = apply_filters( 'aegis_get_widget_customize_fields', array() );
foreach ( $customize_fields as $tab_slug => $tab ) {
foreach ( $tab['params'] as $param_key => $param_args ) {
$new_value = isset( $data['customize'][ $tab_slug ][ $param_key ] ) ? $data['customize'][ $tab_slug ][ $param_key ] : null;
$data['customize'][ $tab_slug ][ $param_key ] = $this->esc_data( $param_args, $new_value );
}
}
}
}
}
$old_data = get_post_meta( $post_id, $widget_id, true );
$old_instance = array();
if ( $old_data ) {
$response['is_first'] = 0;
$old_instance = isset( $old_data['instance'] ) ? $old_data['instance'] : array();
$data['class_name'] = isset( $old_data['class_name'] ) ? $old_data['class_name'] : false;
}
if ( $data['class_name'] ) :
$obj = new $data['class_name'];
$data['instance'] = $obj->update( $data['instance'], $old_instance );
$caption = '';
update_post_meta( $post_id, $widget_id, $data );
if ( isset( $data['instance']['title'] ) && ! empty( $data['instance']['title'] ) ) {
$caption = sprintf( '%s : %s', $obj->name, $data['instance']['title'] );
} else {
$caption = sprintf( '%s', $obj->name );
}
if ( 1 == $response['is_first'] ) :
ob_start();
?>
<div id="<?php echo esc_attr( $widget_id ); ?>" class="a_block a_clearfix">