forked from tgcrypt/Extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules.php
3210 lines (2925 loc) · 107 KB
/
modules.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
// Prevent file from being loaded directly
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
class ET_Builder_Module_Posts extends ET_Builder_Module {
function init() {
$this->template_name = 'module-posts';
$this->name = esc_html__( 'Posts', 'extra' );
$this->slug = 'et_pb_posts';
$this->post_types = array( EXTRA_LAYOUT_POST_TYPE );
$this->main_css_element = '%%order_class%%';
$this->settings_modal_toggles = $this->get_options_toggles();
$this->advanced_fields = array(
'fonts' => array(
'header' => $this->set_frequent_advanced_options( 'header' ),
'subheader' => $this->set_frequent_advanced_options( 'subheader' ),
'main_title' => array(
'label' => esc_html__( 'Main Title', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .main-post .hentry h2 a",
'important' => 'all',
),
'line_height' => array(
'range_settings' => array(
'min' => 0,
'max' => 3,
'step' => 0.1,
),
),
'letter_spacing' => array(
'range_settings' => array(
'min' => 0,
'max' => 30,
'step' => 0.1,
),
),
),
'main_meta' => array(
'label' => esc_html__( 'Main Meta', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .main-post .hentry .post-meta, {$this->main_css_element} .main-post .hentry .post-meta .comment-bubble:before, {$this->main_css_element} .main-post .hentry .post-meta .rating-star:before",
),
),
'main_body' => array(
'label' => esc_html__( 'Main Body', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .main-post .hentry .excerpt",
),
'line_height' => array(
'range_settings' => array(
'min' => 0,
'max' => 3,
'step' => 0.1,
),
),
),
'list_title' => array(
'label' => esc_html__( 'List Title', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .posts-list .hentry h3 a",
'important' => 'all',
),
'line_height' => array(
'range_settings' => array(
'min' => 0,
'max' => 3,
'step' => 0.1,
),
),
),
'list_meta' => array(
'label' => esc_html__( 'List Meta', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .posts-list .hentry .post-meta, {$this->main_css_element} .posts-list .hentry .post-meta .comment-bubble:before, {$this->main_css_element} .posts-list .hentry .post-meta .rating-star:before",
),
),
),
'background' => array(
'css' => array(
'main' => "{$this->main_css_element}, {$this->main_css_element} .module-head",
),
'settings' => array(
'color' => 'alpha',
),
),
'border' => array(
'css' => array(
'main' => "{$this->main_css_element}",
'important' => 'all',
),
),
'custom_margin_padding' => array(),
);
$this->custom_css_fields = array(
'head' => array(
'label' => esc_html__( 'Module Head', 'et_builder' ),
'selector' => '.module-head',
),
'header' => array(
'label' => esc_html__( 'Module Header', 'et_builder' ),
'selector' => '.module-head h1',
),
'subheader' => array(
'label' => esc_html__( 'Module Subheader', 'et_builder' ),
'selector' => '.module-head .module-filter',
),
'main_post' => array(
'label' => esc_html__( 'Main Post Area', 'et_builder' ),
'selector' => '.main-post',
),
'main_post_hentry' => array(
'label' => esc_html__( 'Main Post Entry', 'et_builder' ),
'selector' => '.main-post .hentry',
),
'main_post_title' => array(
'label' => esc_html__( 'Main Post Title', 'et_builder' ),
'selector' => '.main-post .hentry h2 a',
),
'main_post_meta' => array(
'label' => esc_html__( 'Main Post Meta', 'et_builder' ),
'selector' => '.main-post .hentry .post-meta',
),
'main_post_overlay' => array(
'label' => esc_html__( 'Post Overlay', 'et_builder' ),
'selector' => '.main-post .hentry .et_pb_extra_overlay',
),
'main_post_overlay_icon' => array(
'label' => esc_html__( 'Post Overlay Icon', 'et_builder' ),
'selector' => '.main-post .hentry .et_pb_extra_overlay:before',
),
'main_post_meta_icon' => array(
'label' => esc_html__( 'Main Post Meta Icons (Rating & Comment)', 'et_builder' ),
'selector' => '.main-post .hentry .post-meta .post-meta-icon:before',
),
'main_post_excerpt' => array(
'label' => esc_html__( 'Main Post Excerpt', 'et_builder' ),
'selector' => '.main-post .hentry .excerpt',
),
'main_post_overlay' => array(
'label' => esc_html__( 'Main Post Overlay', 'et_builder' ),
'selector' => '.main-post .hentry .et_pb_extra_overlay',
),
'main_post_overlay_icon' => array(
'label' => esc_html__( 'Main Post Overlay Icon', 'et_builder' ),
'selector' => '.main-post .hentry .et_pb_extra_overlay:before',
),
'posts_list' => array(
'label' => esc_html__( 'Posts List Area', 'et_builder' ),
'selector' => '.posts-list',
),
'posts_list_hentry' => array(
'label' => esc_html__( 'Posts List Entry', 'et_builder' ),
'selector' => '.posts-list li',
),
'posts_list_title' => array(
'label' => esc_html__( 'Posts List Title', 'et_builder' ),
'selector' => '.posts-list li h3 a',
),
'posts_list_meta' => array(
'label' => esc_html__( 'Posts List Meta', 'et_builder' ),
'selector' => '.posts-list li .post-meta',
),
'posts_list_meta_icon' => array(
'label' => esc_html__( 'Posts List Meta Icon', 'et_builder' ),
'selector' => '.posts-list li .post-meta .post-meta-icon:before',
),
'posts_list_thumbnail' => array(
'label' => esc_html__( 'Posts List Thumbnail', 'et_builder' ),
'selector' => '.posts-list .post-thumbnail img',
),
);
}
function set_frequent_advanced_options( $key = '', $css = false ) {
$fields = array();
switch ( $key ) {
case 'header':
$fields = array(
'label' => esc_html__( 'Header', 'et_builder' ),
'css' => array(
'main' => "#page-container {$this->main_css_element} .module-head h1",
),
'letter_spacing' => array(
'range_settings' => array(
'min' => 0,
'max' => 30,
'step' => 0.1,
),
),
);
break;
case 'subheader':
$fields = array(
'label' => esc_html__( 'Subheader', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .module-head .module-filter",
),
);
break;
}
// Overwrite css if needed
if ( $css ) {
$fields['css'] = $css;
}
return $fields;
}
function set_fields() {
$this->fields_defaults = wp_parse_args( $this->set_additional_fields(), array(
'heading_style' => array(
'category',
'only_default_setting',
),
'orderby' => array(
'date',
'only_default_setting',
),
'order' => array(
'desc',
'only_default_setting',
),
'date_format' => array(
'M j, Y',
'add_default_setting',
),
) );
parent::set_fields();
}
function get_options_toggles() {
return array(
'general' => array(
'toggles' => array(
'main_content' => esc_html__( 'Posts', 'et_builder' ),
'elements' => esc_html__( 'Elements', 'et_builder' ),
),
),
'advanced' => array(
'toggles' => array(
'layout' => esc_html__( 'Layout', 'et_builder'),
'overlay' => esc_html__( 'Overlay', 'et_builder' ),
'post_icon' => esc_html__( 'Post Format Icon', 'et_builder' ),
'width' => array(
'title' => esc_html__( 'Sizing', 'et_builder' ),
'priority' => 65,
),
),
),
'custom_css' => array(
'toggles' => array(),
),
);
}
/**
* This is meant to be used by sub-class to add additional fields
*/
function set_additional_fields() {
return array();
}
function get_fields() {
$fields = array(
'category_id' => array(
'label' => esc_html__( 'Categories', 'extra' ),
'type' => 'categories',
'description' => esc_html__( 'Choose categories.', 'extra' ),
'renderer_options' => array(
'field_name' => 'et_pb_category_id',
'use_terms' => false,
'custom_items' => array(
array(
'term_id' => '0',
'name' => esc_html__( 'All', 'extra' ),
),
array(
'term_id' => '-1',
'name' => esc_html__( 'Current Category / Tag / Taxonomy', 'extra' ),
),
),
),
'default' => '0',
'priority' => 1,
'option_category' => 'configuration',
'toggle_slug' => 'main_content',
),
'display_featured_posts_only' => array(
'label' => esc_html__( 'Display Featured Posts Only', 'extra' ),
'type' => 'yes_no_button',
'options' => array(
'off' => esc_html__( 'No', 'extra' ),
'on' => esc_html__( 'Yes', 'extra' ),
),
'description' => esc_html__( 'Only display featured posts.', 'extra' ),
'priority' => 5,
'option_category' => 'configuration',
'toggle_slug' => 'main_content',
),
'ignore_displayed_posts' => array(
'label' => esc_html__( 'Ignore Displayed Posts', 'extra' ),
'type' => 'yes_no_button',
'options' => array(
'off' => esc_html__( 'No', 'extra' ),
'on' => esc_html__( 'Yes', 'extra' ),
),
'description' => esc_html__( 'Do not display posts that have been displayed on previous modules.', 'extra' ),
'priority' => 5,
'option_category' => 'configuration',
'toggle_slug' => 'main_content',
),
'heading_style' => array(
'label' => esc_html__( 'Heading Style', 'extra' ),
'type' => 'select',
'options' => array(
'category' => esc_html__( 'Primary Heading: Category Name, Sub Heading: Filter', 'extra' ),
'filter' => esc_html__( 'Primary Heading: Filter, Sub Heading: Category Name', 'extra' ),
'custom' => esc_html__( 'Custom Title', 'extra' ),
),
'description' => esc_html__( 'Choose a heading style.', 'extra' ),
'affects' => array(
'heading_primary',
'heading_sub',
),
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'heading_primary' => array(
'label' => esc_html__( 'Primary Heading', 'extra' ),
'type' => 'text',
'description' => esc_html__( 'The primary heading.', 'extra' ),
'depends_show_if' => 'custom',
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'heading_sub' => array(
'label' => esc_html__( 'Sub Heading', 'extra' ),
'type' => 'text',
'description' => esc_html__( 'The sub heading.', 'extra' ),
'depends_show_if' => 'custom',
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'posts_per_page' => array(
'label' => esc_html__( 'Posts Limit', 'extra' ),
'type' => 'text',
'description' => esc_html__( 'The number of posts shown.', 'extra' ),
'priority' => 3,
'option_category' => 'configuration',
'toggle_slug' => 'main_content',
),
'orderby' => array(
'label' => esc_html__( 'Sort Method', 'extra' ),
'type' => 'select',
'options' => array(
'date' => esc_html__( 'Most Recent', 'extra' ),
'comment_count' => esc_html__( 'Most Popular', 'extra' ),
'rating' => esc_html__( 'Highest Rated', 'extra' ),
),
'description' => esc_html__( 'Choose a sort method.', 'extra' ),
'option_category' => 'configuration',
'toggle_slug' => 'main_content',
),
'order' => array(
'label' => esc_html__( 'Sort Order', 'extra' ),
'type' => 'select',
'options' => array(
'desc' => esc_html__( 'Descending', 'extra' ),
'asc' => esc_html__( 'Ascending', 'extra' ),
),
'description' => esc_html__( 'Choose a sort order.', 'extra' ),
'option_category' => 'configuration',
'toggle_slug' => 'main_content',
),
'show_thumbnails' => array(
'label' => esc_html__( 'Show Featured Image', 'extra' ),
'type' => 'yes_no_button',
'options' => array(
'on' => esc_html__( 'Yes', 'extra' ),
'off' => esc_html__( 'No', 'extra' ),
),
'description' => esc_html__( "Turn the display of each post's featured image on or off.", 'extra' ),
'priority' => 5,
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'show_author' => array(
'label' => esc_html__( 'Show Author', 'extra' ),
'type' => 'yes_no_button',
'options' => array(
'on' => esc_html__( 'Yes', 'extra' ),
'off' => esc_html__( 'No', 'extra' ),
),
'description' => esc_html__( "Turn the display of each post's author on or off.", 'extra' ),
'priority' => 5,
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'show_categories' => array(
'label' => esc_html__( 'Show Categories', 'extra' ),
'type' => 'yes_no_button',
'options' => array(
'on' => esc_html__( 'Yes', 'extra' ),
'off' => esc_html__( 'No', 'extra' ),
),
'description' => esc_html__( "Turn the display of each post's categories on or off.", 'extra' ),
'priority' => 5,
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'show_comments' => array(
'label' => esc_html__( 'Show Comments', 'extra' ),
'type' => 'yes_no_button',
'options' => array(
'on' => esc_html__( 'Yes', 'extra' ),
'off' => esc_html__( 'No', 'extra' ),
),
'description' => esc_html__( "Turn the display of each post's ccomments on or off.", 'extra' ),
'priority' => 5,
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'show_rating' => array(
'label' => esc_html__( 'Show Rating', 'extra' ),
'type' => 'yes_no_button',
'options' => array(
'on' => esc_html__( 'Yes', 'extra' ),
'off' => esc_html__( 'No', 'extra' ),
),
'description' => esc_html__( "Turn the display of each post's rating on or off.", 'extra' ),
'priority' => 5,
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'show_date' => array(
'label' => esc_html__( 'Show Date', 'extra' ),
'type' => 'yes_no_button',
'options' => array(
'on' => esc_html__( 'Yes', 'extra' ),
'off' => esc_html__( 'No', 'extra' ),
),
'affects' => array( 'date_format' ),
'description' => esc_html__( "Turn the dispay of each post's date on or off.", 'extra' ),
'priority' => 5,
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'date_format' => array(
'label' => esc_html__( 'Date Format', 'extra' ),
'type' => 'text',
'depends_show_if_not' => "off",
'description' => esc_html__( 'The format for the date display in PHP date() format', 'extra' ),
'option_category' => 'configuration',
'toggle_slug' => 'elements',
),
'hover_overlay_color' => array(
'label' => esc_html__( 'Hover Overlay Color', 'et_builder' ),
'type' => 'color-alpha',
'custom_color' => true,
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
'priority' => 26,
),
'hover_overlay_icon_color' => array(
'label' => esc_html__( 'Hover Overlay Icon Color', 'et_builder' ),
'type' => 'color-alpha',
'custom_color' => true,
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
'priority' => 26,
),
'hover_overlay_icon' => array(
'label' => esc_html__( 'Hover Overlay Icon Picker', 'et_builder' ),
'type' => 'select_icon',
'option_category' => 'configuration',
'class' => array( 'et-pb-font-icon' ),
'renderer_with_field' => true,
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
'priority' => 26,
),
'admin_label' => array(
'label' => esc_html__( 'Admin Label', 'extra' ),
'type' => 'text',
'description' => esc_html__( 'This will change the label of the module in the builder for easy identification.', 'extra' ),
'toggle_slug' => 'admin_label',
),
'module_id' => array(
'label' => esc_html__( 'CSS ID', 'extra' ),
'type' => 'text',
'description' => esc_html__( 'Enter an optional CSS ID to be used for this module. An ID can be used to create custom CSS styling, or to create links to particular sections of your page.', 'extra' ),
'option_category' => 'configuration',
'tab_slug' => 'custom_css',
'toggle_slug' => 'classes',
),
'module_class' => array(
'label' => esc_html__( 'CSS Class', 'extra' ),
'type' => 'text',
'description' => esc_html__( 'Enter optional CSS classes to be used for this module. A CSS class can be used to create custom CSS styling. You can add multiple classes, separated with a space.', 'extra' ),
'option_category' => 'configuration',
'tab_slug' => 'custom_css',
'toggle_slug' => 'classes',
),
'max_width' => array(
'label' => esc_html__( 'Max Width', 'et_builder' ),
'type' => 'text',
'option_category' => 'layout',
'tab_slug' => 'advanced',
'toggle_slug' => 'width',
'validate_unit' => true,
),
);
$advanced_design_fields = array(
'post_format_icon_bg_color' => array(
'label' => esc_html__( 'Post Format Icon Background Color', 'et_builder' ),
'type' => 'color-alpha',
'custom_color' => true,
'tab_slug' => 'advanced',
'toggle_slug' => 'post_icon',
'priority' => 25,
),
'remove_drop_shadow' => array(
'label' => esc_html__( 'Remove Drop Shadow', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'layout',
'options' => array(
'off' => esc_html__( 'No', 'et_builder' ),
'on' => esc_html__( 'Yes', 'et_builder' ),
),
'tab_slug' => 'advanced',
'toggle_slug' => 'layout',
'priority' => 26,
),
'border_radius' => array(
'label' => esc_html__( 'Border Radius', 'et_builder' ),
'type' => 'range',
'option_category' => 'layout',
'tab_slug' => 'advanced',
'toggle_slug' => 'border',
'priority' => 27,
'range_settings' => array(
'min' => '0',
'max' => '200',
'step' => '1',
),
),
);
return array_merge( $fields, $advanced_design_fields );
}
function process_bool_shortcode_atts() {
foreach ( $this->get_fields() as $field_name => $field ) {
if ( 'yes_no_button' == $field['type'] ) {
$this->props[ $field_name ] = 'on' == $this->props[ $field_name ] ? true : false;
}
}
$this->props['use_tax_query'] = false;
}
function shortcode_atts() {
$this->process_bool_shortcode_atts();
}
function render( $atts, $content = null, $function_name ) {
global $extra_displayed_post_ids;
$args = array(
'post_type' => 'post',
'posts_per_page' => isset( $this->props['posts_per_page'] ) && is_numeric( $this->props['posts_per_page'] ) ? $this->props['posts_per_page'] : 5,
'order' => $this->props['order'],
'orderby' => $this->props['orderby'],
'ignore_displayed_posts' => isset( $this->props['ignore_displayed_posts'] ) ? $this->props['ignore_displayed_posts'] : false,
);
if ( 'rating' == $this->props['orderby'] ) {
$args['orderby'] = 'meta_value_num';
$args['meta_key'] = '_extra_rating_average';
}
if ( ! $extra_displayed_post_ids ) {
$extra_displayed_post_ids = array();
}
if ( $args['ignore_displayed_posts'] ) {
$args['post__not_in'] = $extra_displayed_post_ids;
}
$args = $this->_pre_wp_query( $args );
// need to hook into pre_get_posts to set is_home = true, then unhook afterwards
add_action( 'pre_get_posts', array( $this, 'make_is_home' ) );
$this->props['module_posts'] = new WP_Query( $args );
// unhook afterwards
remove_action( 'pre_get_posts', array( $this, 'make_is_home' ) );
$posts_per_page = $this->props['module_posts']->get( 'posts_per_page' );
// only slice if there is a limit that where trying to enforce respect upon and if it's disrespecting the limit
if ( $posts_per_page > 0 && $this->props['module_posts']->post_count > $posts_per_page ) {
$sticky_posts = get_option( 'sticky_posts' );
if ( is_array( $sticky_posts ) && !empty( $sticky_posts ) ) {
// make wp_query respect posts_per_page even when sticky posts are involved
$module_posts = $this->props['module_posts'];
$module_posts->posts = array_slice( $module_posts->posts, 0, $posts_per_page );
$module_posts->post_count = $posts_per_page;
$this->props['module_posts'] = $module_posts;
}
}
if ( ! empty( $this->props['terms_names'] ) ) {
$category_name = $this->props['terms_names'];
} else if ( ! empty( $this->props['term_name'] ) ) {
$category_name = $this->props['term_name'];
} else {
$category_name = esc_html__( 'All', 'extra' );
}
$this->props['is_all_categories'] = (bool) empty( $this->props['term_name'] );
switch ( $this->props['orderby'] ) {
case 'comment_count':
$filter_title = esc_html__( 'Popular', 'extra' );
break;
case 'rating':
$filter_title = esc_html__( 'Top Rated', 'extra' );
break;
case 'date':
default:
$filter_title = esc_html__( 'Latest', 'extra' );
break;
}
if ( !empty( $this->props['heading_style'] ) ) {
switch ( $this->props['heading_style'] ) {
case 'filter':
$this->props['title'] = $filter_title;
$this->props['sub_title'] = $category_name;
break;
case 'custom':
$this->props['title'] = !empty( $this->props['heading_primary'] ) ? esc_html( $this->props['heading_primary'] ) : '';
$this->props['sub_title'] = !empty( $this->props['heading_sub'] ) ? esc_html( $this->props['heading_sub'] ) : '';
break;
case 'category':
default:
$this->props['title'] = $category_name;
$this->props['sub_title'] = $filter_title;
break;
}
}
if ( !empty( $this->props['term_color'] ) ) {
$this->props['border_top_color'] = $this->props['term_color'];
$this->props['module_title_color'] = $this->props['term_color'];
} else {
$color = et_builder_accent_color();
$module_posts = $this->props['module_posts'];
if ( isset( $module_posts->posts[0] ) ) {
$featured_post = $module_posts->posts[0];
$categories = wp_get_post_categories( $featured_post->ID );
if ( !empty( $categories ) ) {
$first_category_id = $categories[0];
if ( function_exists( 'et_get_childmost_taxonomy_meta' ) ) {
$color = et_get_childmost_taxonomy_meta( $first_category_id, 'color', true, et_builder_accent_color() );
}
}
}
$this->props['term_color'] = $color;
$this->props['border_top_color'] = $color;
$this->props['module_title_color'] = $color;
}
if ( isset( $this->props['module_class'] ) ) {
$this->props['module_class'] = ET_Builder_Element::add_module_order_class( $this->props['module_class'], $this->slug );
}
// Adding styling classes to module
if ( !empty( $this->props['remove_drop_shadow'] ) && 'on' === $this->props['remove_drop_shadow'] ) {
$this->props['module_class'] = $this->props['module_class'] . ' et_pb_no_drop_shadow';
}
// Print styling for general options
if ( isset( $this->props['border_radius'] ) && '' !== $this->props['border_radius'] ) {
ET_Builder_Module::set_style( $this->slug, array(
'selector' => '%%order_class%%.et_pb_extra_module',
'declaration' => sprintf(
'-moz-border-radius: %1$s;
-webkit-border-radius: %1$s;
border-radius: %1$s;',
esc_html( $this->props['border_radius'] )
),
) );
}
if ( isset( $this->props['max_width'] ) && '' !== $this->props['max_width'] ) {
ET_Builder_Module::set_style( $this->slug, array(
'selector' => '%%order_class%%',
'declaration' => sprintf(
'max-width: %1$s;',
esc_html( et_builder_process_range_value( $this->props['max_width'] ) )
),
) );
}
if ( isset( $this->props['post_format_icon_bg_color'] ) && '' !== $this->props['post_format_icon_bg_color'] ) {
ET_Builder_Module::set_style( $this->slug, array(
'selector' => '%%order_class%% .post-thumbnail img',
'declaration' => sprintf(
'background-color: %1$s !important;',
esc_html( $this->props['post_format_icon_bg_color'] )
),
) );
}
if ( isset( $this->props['hover_overlay_color'] ) && '' !== $this->props['hover_overlay_color'] ) {
ET_Builder_Element::set_style( $this->slug, array(
'selector' => '%%order_class%% .et_pb_extra_overlay',
'declaration' => sprintf(
'background-color: %1$s;
border-color: %1$s;',
esc_html( $this->props['hover_overlay_color'] )
),
) );
}
if ( isset( $this->props['hover_overlay_icon_color'] ) && '' !== $this->props['hover_overlay_icon_color'] ) {
ET_Builder_Element::set_style( $this->slug, array(
'selector' => '%%order_class%% .et_pb_extra_overlay:before',
'declaration' => sprintf(
'color: %1$s;',
esc_html( $this->props['hover_overlay_icon_color'] )
),
) );
}
// Overwrite border_color_top attribute if border color is defined by advanced design settings
if ( isset( $this->props['border_color'] ) && isset( $this->props['use_border_color'] ) && 'on' === $this->props['use_border_color'] ) {
$this->props['border_top_color'] = $this->props['border_color'];
}
if ( is_customize_preview() && $this->props['term_color'] === extra_global_accent_color() ) {
$this->props['module_class'] = $this->props['module_class'] . ' no-term-color-module';
}
if ( isset( $this->props['module_posts']->found_posts ) && 0 < $this->props['module_posts']->found_posts ) {
$post_ids = wp_list_pluck( $this->props['module_posts']->posts, 'ID' );
$extra_displayed_post_ids = array_unique( array_merge( $extra_displayed_post_ids, $post_ids ) );
}
}
function make_is_home( $wp_query ) {
$wp_query->is_home = true;
}
function append_tax_query_params( $params ) {
global $wp_query;
if ( isset( $wp_query->tax_query->queries ) ) {
$params['tax_query'] = $wp_query->tax_query->queries;
}
return $params;
}
function _process_shortcode_atts_category_id() {
if ( false !== strpos( $this->props['category_id'], '-1' ) ) {
$this->props['use_tax_query'] = true;
if ( is_category() ) {
$current_categoory = get_queried_object_id();
} else {
$current_categoory = '';
}
if ( '-1' == $this->props['category_id'] ) {
$this->props['category_id'] = $current_categoory;
} else {
$replace = empty( $current_categoory ) ? '-1,' : '-1';
$this->props['category_id'] = str_ireplace( $replace, $current_categoory, $this->props['category_id'] );
}
}
if ( '0' == substr( $this->props['category_id'], 0, 1 ) ) {
$this->props['category_id'] = 0;
}
}
function _pre_wp_query( $args ) {
global $wp_query;
$this->_process_shortcode_atts_category_id();
if ( !empty( $this->props['category_id'] ) ) {
$categories = array_map( 'absint', explode( ',', $this->props['category_id'] ) );
$args['ignore_sticky_posts'] = 1;
$args['tax_query'] = array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $categories,
'operator' => 'IN',
),
);
if ( count( $categories ) > 1 ) {
$terms_names = array();
foreach ( $categories as $category_id ) {
$terms_names[] = get_term( $category_id, 'category' )->name;
}
$terms_names = implode( ', ', $terms_names );
$this->props['terms_names'] = $terms_names;
}
$term = get_term( $categories[0], 'category' );
if ( !empty( $term ) && empty( $term->errors ) ) {
$this->props['term_name'] = $term->name;
$this->props['term_color'] = extra_get_category_color( $term->term_id );
} else {
unset( $args['tax_query'] );
}
}
if ( isset( $wp_query->tax_query->queries ) && $this->props['use_tax_query'] ) {
wp_localize_script( 'extra-scripts', 'EXTRA_TAX_QUERY', $wp_query->tax_query->queries );
$taxonomies = $wp_query->tax_query->queries;
foreach ( $taxonomies as $taxonomy ) {
if ( isset( $taxonomy['taxonomy'] ) && 'category' === $taxonomy['taxonomy'] && ! empty( $this->props['category_id'] ) ) {
continue;
}
$args['tax_query'][] = $taxonomy;
}
if ( isset( $args['tax_query'] ) && 1 < count( $args['tax_query'] ) ) {
$args['tax_query']['relation'] = 'AND';
}
if ( ! is_home() ) {
$args['ignore_sticky_posts'] = 1;
}
}
if ( $this->props['display_featured_posts_only'] ) {
$args['meta_query'] = array(
array(
'key' => '_extra_featured_post',
'value' => '1',
),
);
}
return $args;
}
}
new ET_Builder_Module_Posts;
class ET_Builder_Module_Tabbed_Posts extends ET_Builder_Module {
public static $global_shortcode_atts;
public static $tabs_data = array();
function init() {
$this->template_name = 'module-tabbed-posts';
$this->name = esc_html__( 'Tabbed Posts', 'extra' );
$this->slug = 'et_pb_tabbed_posts';
$this->post_types = array( EXTRA_LAYOUT_POST_TYPE );
$this->child_slug = 'et_pb_tabbed_posts_tab';
$this->main_css_element = '%%order_class%%';
$this->settings_modal_toggles = array(
'general' => array(
'toggles' => array(
'main_content' => esc_html__( 'Posts', 'et_builder' ),
'elements' => esc_html__( 'Elements', 'et_builder' ),
),
),
'advanced' => array(
'toggles' => array(
'layout' => esc_html__( 'Layout', 'et_builder'),
'overlay' => esc_html__( 'Overlay', 'et_builder' ),
'post_icon' => esc_html__( 'Post Format Icon', 'et_builder' ),
'tabs_bg' => esc_html__( 'Tabs Background', 'et_builder' ),
'width' => array(
'title' => esc_html__( 'Sizing', 'et_builder' ),
'priority' => 65,
),
),
),
);
$this->advanced_fields = array(
'fonts' => array(
'tab' => array(
'label' => esc_html__( 'Tab', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .tabs ul li",
),
'letter_spacing' => array(
'range_settings' => array(
'min' => 0,
'max' => 30,
'step' => 0.1,
),
),
),
'main_title' => array(
'label' => esc_html__( 'Main Title', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .main-post .hentry h2 a",
'important' => 'all',
),
'line_height' => array(
'range_settings' => array(
'min' => 0,
'max' => 3,
'step' => 0.1,
),
),
'letter_spacing' => array(
'range_settings' => array(
'min' => 0,
'max' => 30,
'step' => 0.1,
),
),
),
'main_meta' => array(
'label' => esc_html__( 'Main Meta', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .main-post .hentry .post-meta, {$this->main_css_element} .main-post .hentry .post-meta .comment-bubble:before, {$this->main_css_element} .main-post .hentry .post-meta .rating-star:before",
),
),
'main_body' => array(
'label' => esc_html__( 'Main Body', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .main-post .hentry .excerpt",
),
'line_height' => array(
'range_settings' => array(
'min' => 0,
'max' => 3,
'step' => 0.1,
),
),
),
'list_title' => array(
'label' => esc_html__( 'List Title', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .posts-list .hentry h3 a",
'important' => 'all',
),
'line_height' => array(
'range_settings' => array(
'min' => 0,
'max' => 3,
'step' => 0.1,
),
),
),
'list_meta' => array(
'label' => esc_html__( 'List Meta', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .posts-list .hentry .post-meta, {$this->main_css_element} .posts-list .hentry .post-meta .comment-bubble:before, {$this->main_css_element} .posts-list .hentry .post-meta .rating-star:before",
),
),
),
'background' => array(
'css' => array(
'main' => "{$this->main_css_element}.tabbed-post-module",
),
'settings' => array(
'color' => 'alpha',
),