-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctionsWidget.php
More file actions
1473 lines (1210 loc) · 48.2 KB
/
Copy pathfunctionsWidget.php
File metadata and controls
1473 lines (1210 loc) · 48.2 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
function WGR_widget_arr_default_home_hot($new_arr = array())
{
// Giá trị mặc định
$arr = array(
'title' => 'EchBay Widget for product',
'hide_widget_title' => 0,
'custom_cat_link' => '',
'dynamic_tag' => 'div',
'dynamic_post_tag' => '',
'description' => '',
'get_full_content' => 0,
'content_only' => 0,
'off_img_max_width' => 0,
'js_ptags' => 0,
'show_content_excerpt' => 0,
'sortby' => 'menu_order ID',
'num_line' => '',
'html_template' => 'home_hot.html',
'html_node' => '',
'max_width' => '',
'post_number' => 5,
'cat_ids' => 0,
'cat_type' => 'category',
'get_childs' => 0,
'post_cloumn' => '',
'hide_title' => 0,
'hide_description' => 0,
'show_post_content' => 0,
'hide_info' => 0,
// khi thuộc tính này kích hoạt -> ảnh sẽ được đặt làm slider
'run_slider' => 0,
'post_type' => 'post',
// dành cho mục quảng cáo -> mở dưới dạng video youtube
'open_youtube' => 0,
// lấy các bài viết cùng nhóm
'same_cat' => 0,
// tự động lấy post type mới khi chức năng same_cat được kích hoạt
'get_post_type' => 0,
// Quan hệ liên kết (XFN) -> rel="nofollow"
'rel_xfn' => '',
// Mở liên kết trong 1 thẻ mới
'open_target' => 0,
'ads_eb_status' => 0,
'post_eb_status' => 0,
'custom_style' => '',
'custom_id' => '',
'custom_size' => '',
// bỏ qua chế độ lọc trùng sản phẩm nếu được kích hoạt
'post__not_in' => '',
'page_id' => 0
);
// thay thế các giá trị mặc định
foreach ($new_arr as $k => $v) {
$arr[$k] = $v;
}
// Trả về kết quả
return $arr;
}
function WGR_widget_home_hot($instance)
{
// global $func;
global $echbay_widget_i_set_home_product_bg;
//
// $title = apply_filters ( 'widget_title', $instance ['title'] );
$title = isset($instance['title']) ? $instance['title'] : '';
$dynamic_tag = isset($instance['dynamic_tag']) ? $instance['dynamic_tag'] : 'div';
$dynamic_post_tag = isset($instance['dynamic_post_tag']) ? $instance['dynamic_post_tag'] : '';
$description = isset($instance['description']) ? $instance['description'] : '';
$post_number = isset($instance['post_number']) ? $instance['post_number'] : 0;
if ($post_number == 0) $post_number = 5;
$sortby = isset($instance['sortby']) ? $instance['sortby'] : '';
$num_line = isset($instance['num_line']) ? $instance['num_line'] : '';
$cat_ids = isset($instance['cat_ids']) ? $instance['cat_ids'] : 0;
$cat_type = isset($instance['cat_type']) ? $instance['cat_type'] : 'category';
$post_eb_status = isset($instance['post_eb_status']) ? $instance['post_eb_status'] : 0;
$html_template = isset($instance['html_template']) ? $instance['html_template'] : '';
$max_width = isset($instance['max_width']) ? $instance['max_width'] : '';
$post_cloumn = isset($instance['post_cloumn']) ? $instance['post_cloumn'] : '';
$post_type = isset($instance['post_type']) ? $instance['post_type'] : '';
// $html_node = isset( $instance ['html_node'] ) ? $instance ['html_node'] : '';
// $html_node = str_replace( '.html', '', $html_node );
$custom_style = isset($instance['custom_style']) ? $instance['custom_style'] : '';
$custom_size = isset($instance['custom_size']) ? $instance['custom_size'] : '';
// ẩn các thuộc tính theo option
$custom_style .= WGR_add_option_class_for_post_widget($instance);
//
$___order = 'DESC';
if ($sortby == '' || $sortby == 'rand') {
$___order = '';
}
//
$args = array(
'orderby' => $sortby,
'order' => $___order,
);
//
$str_home_hot = '';
$home_hot_lnk = '';
$home_hot_more = '';
// echo $cat_ids . '<br>';
// echo 'aaaaaaaaaaaaaaaaa<br>';
// nếu có phân nhóm -> lấy theo phân nhóm
if ($cat_ids > 0) {
$cat_type = WGR_get_taxonomy_name($cat_ids, $cat_type);
// echo $cat_type . '<br>';
// các sản phẩm trong nhóm con
/*
$arr_in = array();
$sub_cat = get_categories( array(
'parent' => $cat_ids
) );
// print_r( $sub_cat );
if ( ! empty( $sub_cat ) ) {
foreach ( $sub_cat as $k => $v ) {
$arr_in[] = $v->term_id;
}
}
if ( ! empty( $arr_in ) ) {
$arr_in[] = $cat_ids;
$args['category__in'] = $arr_in;
}
else {
*/
if ($cat_type == 'category') {
$args['cat'] = $cat_ids;
} else {
$args['tax_query'] = array(
array(
'taxonomy' => $cat_type,
'field' => 'term_id',
'operator' => 'IN',
'terms' => array($cat_ids)
// 'terms' => $terms_categories,
)
);
}
// }
//
$home_hot_lnk = _eb_c_link($cat_ids, $cat_type);
// lấy thông tin phân nhóm luôn
if ($title == '') {
$categories = get_term_by('id', $cat_ids, $cat_type);
$title = $categories->name;
}
//
$title = '<a href="' . $home_hot_lnk . '">' . $title . '</a>';
// $home_hot_more = '<' . $dynamic_tag . ' class="home-hot-more"><a href="' . $home_hot_lnk . '">Xem thêm <span>»</span></a></' . $dynamic_tag . '>';
$home_hot_more = '<div class="home-hot-more"><a href="' . $home_hot_lnk . '">Xem thêm <span>»</span></a></div>';
} else if ($title == '') {
$title = EBE_get_lang('home_hot');
} else {
global $___eb_lang;
//
if (isset($___eb_lang[eb_key_for_site_lang . $title])) {
$title = $___eb_lang[eb_key_for_site_lang . $title];
}
}
// tìm theo trạng thái
if ($post_eb_status > 0) {
$args['meta_key'] = '_eb_product_status';
$args['meta_value'] = $post_eb_status;
$args['compare'] = '=';
$args['type'] = 'NUMERIC';
}
$args['ignore_sticky_posts'] = 1;
//
$html_content = __eb_thread_template;
// nếu có size riêng -> sử dụng size này
if ($custom_size != '') {
$html_content = str_replace('{tmp.cf_product_size}', $custom_size, $html_content);
}
if ($dynamic_post_tag != '') {
$html_content = EBE_dynamic_title_tag($html_content, $dynamic_post_tag);
}
$str_home_hot = _eb_load_post($post_number, $args, $html_content);
//
if ($str_home_hot == '') {
echo '<!-- ';
print_r($args);
echo ' -->';
$str_home_hot = '<li class="text-center"><em>post not found</em></li>';
}
//
$html_template = _eb_widget_create_html_template($html_template, 'home_hot');
//
echo '<div class="' . $custom_style . '">';
$arr_for_template = array(
'tmp.dynamic_widget_tag' => $dynamic_tag,
'tmp.max_width' => $max_width,
'tmp.num_post_line' => $num_line,
'tmp.home_hot_title' => $title,
'tmp.home_hot_more' => $home_hot_more,
'tmp.description' => $description,
'tmp.home_hot' => $str_home_hot,
// ) );
);
/*
if ( $max_width != '' ) {
$arr_for_template['custom_blog_css'] = $max_width;
}
*/
// print_r($arr_for_template);
// echo EBE_html_template( EBE_get_page_template( $html_template ), array(
$show_content = WGR_show_home_hot($arr_for_template, $html_template);
/*
if ( $dynamic_post_tag != '' ) {
$show_content = EBE_dynamic_title_tag( $show_content, $dynamic_post_tag );
}
*/
echo $show_content;
echo '</div>';
}
// hiển thị phần home hot theo chuẩn nhất định
function WGR_show_home_hot($arr, $tmp = 'home_hot')
{
// global $__cf_row;
//
// print_r($arr);
// nạp html được truyền vào
$html = EBE_html_template(EBE_get_page_template($tmp), $arr);
//
if (!isset($arr['tmp.dynamic_widget_tag'])) {
$arr['tmp.dynamic_widget_tag'] = 'div';
}
// tạo thẻ đóng
$html = str_replace('dynamic_widget_tag>', $arr['tmp.dynamic_widget_tag'] . '>', $html);
// tạo thẻ mở
$html = str_replace('<dynamic_widget_tag', '<' . $arr['tmp.dynamic_widget_tag'], $html);
// các đoạn HTML mặc định cho về trống nếu chưa có
$html = EBE_html_template($html, array(
'tmp.max_width' => '',
'tmp.num_post_line' => '',
'tmp.home_hot_title' => '',
'tmp.home_hot_more' => '',
'tmp.description' => '',
'tmp.home_hot' => ''
));
//
/*
if ( $__cf_row['cf_replace_content'] != '' ) {
$html = WGR_replace_for_all_content( $__cf_row['cf_replace_content'], $html );
}
*/
//
return $html;
}
// hiển thị phần home node theo chuẩn nhất định
function WGR_show_home_node($arr, $custom_tag = '', $tmp = 'home_node')
{
// kiểm tra xem có custom tag không -> do bản cũ với mới khác nhau nên phải có đoạn này
$custom_end_tag = '';
if ($custom_tag != '') {
$custom_end_tag = '</' . $custom_tag . '>';
$custom_tag = '<' . $custom_tag . '>';
}
// nạp html được truyền vào
$html = EBE_html_template(EBE_get_page_template($tmp), $arr);
// các đoạn HTML mặc định cho về trống nếu chưa có
return EBE_html_template($html, array(
// thẻ H2, H3... cho phần tên danh mục
'tmp.custom_tag' => $custom_tag,
'tmp.custom_end_tag' => $custom_end_tag,
// các thông số khác
'tmp.num_post_line' => '',
));
}
// lấy danh sách nhóm con
function WGR_get_home_node_sub_cat($cat_ids, $custom_tag = '')
{
// danh sách nhóm cấp 2
$arr_sub_cat = array(
'parent' => $cat_ids,
);
$sub_cat = get_categories($arr_sub_cat);
// print_r( $sub_cat );
// kiểm tra xem có custom tag không -> do bản cũ với mới khác nhau nên phải có đoạn này
$custom_end_tag = '';
if ($custom_tag != '') {
$custom_end_tag = '</' . $custom_tag . '>';
$custom_tag = '<' . $custom_tag . '>';
}
//
$str_sub_cat = '';
foreach ($sub_cat as $sub_v) {
$str_sub_cat .= $custom_tag . '<a href="' . _eb_c_link($sub_v->term_id) . '">' . $sub_v->name . ' <span class="home-count-subcat">(' . $sub_v->count . ')</span></a>' . $custom_end_tag;
}
return $str_sub_cat;
}
// lấy danh sách các quảng cáo đi kèm cho từng nhóm
function WGR_get_home_node_ads($cat_ids, $tmp = 'ads_node')
{
return _eb_load_ads(9, _eb_number_only(EBE_get_lang('homelist_num')), EBE_get_lang('homelist_size'), array(
'cat' => $cat_ids,
), 0, EBE_get_page_template($tmp));
// ), 0, str_replace( 'ti-le-global', '', EBE_get_page_template( 'ads_node' ) ) );
}
//
function WGR_add_option_class_for_post_widget($a)
{
$s = '';
//
if (isset($a['hide_widget_title']) && $a['hide_widget_title'] == 'on') {
$s .= ' hide-widget-title';
}
if (isset($a['hide_title']) && $a['hide_title'] == 'on') {
$s .= ' hide-blogs-title';
}
if (isset($a['hide_description']) && $a['hide_description'] == 'on') {
$s .= ' hide-blogs-description';
}
if (isset($a['hide_info']) && $a['hide_info'] == 'on') {
$s .= ' hide-blogs-info';
}
if (isset($a['run_slider']) && $a['run_slider'] == 'on') {
$s .= ' ebwidget-run-slider';
}
if (isset($a['open_youtube']) && $a['open_youtube'] == 'on') {
$s .= ' youtube-quick-view';
}
//
return $s;
}
function WGR_show_widget_blog($args, $instance, $options = array())
{
// global $__cf_row;
// print_r( $instance );
extract($args);
//
$page_id = isset($instance['page_id']) ? $instance['page_id'] : 0;
if ($page_id > 0) {
global $post;
// print_r( $post );
// nếu không phải là page -> thông báo lỗi luôn -> thông báo ẩn thôi, để các page khác không thấy là được
// if ( ! is_page() || ! isset( $post->post_type ) || $post->post_type != 'page' || $page_id != $post->ID ) {
if (!isset($post->post_type) || $post->post_type != 'page' || $page_id != $post->ID) {
echo '<!-- WARNING!</strong>: widget show only page id: <strong>' . $page_id . '. Current post type: ' . $post->post_type . ', current post ID: ' . $post->ID . ' -->';
return false;
}
}
// $title = apply_filters ( 'widget_title', $instance ['title'] );
$title = isset($instance['title']) ? $instance['title'] : '';
$custom_cat_link = isset($instance['custom_cat_link']) ? $instance['custom_cat_link'] : '';
if (trim($custom_cat_link) == '#') {
$custom_cat_link = 'javascript:;';
}
$dynamic_tag = isset($instance['dynamic_tag']) ? $instance['dynamic_tag'] : '';
$dynamic_post_tag = isset($instance['dynamic_post_tag']) ? $instance['dynamic_post_tag'] : '';
$description = isset($instance['description']) ? $instance['description'] : '';
$post_number = isset($instance['post_number']) ? $instance['post_number'] : 0;
$sortby = isset($instance['sortby']) ? $instance['sortby'] : '';
$cat_ids = isset($instance['cat_ids']) ? $instance['cat_ids'] : 0;
$cat_type = isset($instance['cat_type']) ? $instance['cat_type'] : EB_BLOG_POST_LINK;
$get_childs = isset($instance['get_childs']) ? $instance['get_childs'] : 'off';
$get_full_content = isset($instance['get_full_content']) ? $instance['get_full_content'] : 'off';
// echo $get_full_content . '<br>' . "\n";
$content_only = isset($instance['content_only']) ? $instance['content_only'] : 'off';
$off_img_max_width = isset($instance['off_img_max_width']) ? $instance['off_img_max_width'] : 'off';
$js_ptags = isset($instance['js_ptags']) ? $instance['js_ptags'] : 'off';
//echo 'js_ptags: ' . $js_ptags . '<br>' . "\n";
$show_content_excerpt = isset($instance['show_content_excerpt']) ? $instance['show_content_excerpt'] : 'off';
$num_line = isset($instance['num_line']) ? $instance['num_line'] : '';
$max_width = isset($instance['max_width']) ? $instance['max_width'] : '';
$post_cloumn = isset($instance['post_cloumn']) ? $instance['post_cloumn'] : '';
$html_template = isset($instance['html_template']) ? $instance['html_template'] : '';
$post_type = isset($instance['post_type']) ? $instance['post_type'] : '';
$same_cat = isset($instance['same_cat']) ? $instance['same_cat'] : 'off';
$get_post_type = isset($instance['get_post_type']) ? $instance['get_post_type'] : 'off';
// xác định lại post type cho trường hợp đặc biệt
if ($post_type == 'for_other_post_type') {
$get_post_type = 'on';
}
//echo $post_type . '<br>' . "\n";
//echo $get_post_type . '<br>' . "\n";
$html_node = isset($instance['html_node']) ? $instance['html_node'] : '';
$html_node = _eb_widget_create_html_template($html_node, 'blogs_node');
//echo $html_node . '<br>' . "\n";
$ads_eb_status = isset($instance['ads_eb_status']) ? $instance['ads_eb_status'] : 0;
$post_eb_status = isset($instance['post_eb_status']) ? $instance['post_eb_status'] : 0;
$custom_style = isset($instance['custom_style']) ? $instance['custom_style'] : '';
$custom_id = isset($instance['custom_id']) ? $instance['custom_id'] : '';
if ($custom_id != '') {
$custom_id = ' id="' . $custom_id . '"';
}
$custom_size = isset($instance['custom_size']) ? $instance['custom_size'] : '';
$rel_xfn = isset($instance['rel_xfn']) ? $instance['rel_xfn'] : '';
$open_target = isset($instance['open_target']) ? $instance['open_target'] : 'off';
$open_youtube = isset($instance['open_youtube']) ? $instance['open_youtube'] : 'off';
// ẩn các thuộc tính theo option
$custom_style .= WGR_add_option_class_for_post_widget($instance);
// nếu chỉ có một bài -> thêm class đánh dấu chỉ một bài viết
// echo $post_number;
if ($post_number == 0) {
$post_number = 5;
}
/*
else if ( $post_number == 1 ) {
$custom_style .= ' echbay-blog-onerow';
}
*/
// echo $post_number . '<br>';
$custom_style .= ' echbay-blog-number' . $post_number;
// echo $custom_style . '<br>';
//
// $cat_link = '';
$cat_link = $custom_cat_link;
//
// _eb_echo_widget_title( $title, 'echbay-widget-blogs-title', $before_title );
//
$terms_categories = array();
// lấy lại nhóm của bài viết
$re_post_categories = array();
$cat_name = '';
$more_link = '';
$str_sub_cat = '';
// chỉ lấy các bài viết cùng nhóm (tự động)
if ($same_cat == 'on') {
global $cid;
global $parent_cid;
global $pid;
// xử lý thêm khi trong trang chi tiết
if ($pid > 0) {
// xác định lại post type
if ($get_post_type == 'on') {
global $__post;
// print_r( $__post );
if (isset($__post->post_type)) {
$post_type = $__post->post_type;
} else {
$post_type = WGR_get_post_type_name($pid);
}
// nếu post type là page -> hủy luôn
if ($post_type == 'page') {
echo '<!-- STOP! auto get same cat not runing in page post type -->';
return false;
}
}
// lấy toàn bộ danh sách nhóm của bài viết này
if ($post_type == EB_BLOG_POST_TYPE) {
$re_post_categories = get_the_terms($pid, EB_BLOG_POST_LINK);
} else {
$re_post_categories = get_the_terms($pid, 'category');
}
}
/*
else if ( $cat_type != EB_BLOG_POST_LINK ) {
$post_type = 'post';
}
echo $cat_type . '<br>' . "\n";
*/
//
/*
if ( $parent_cid > 0 ) {
$cat_ids = $parent_cid;
}
else if ( $cid > 0 ) {
$cat_ids = $cid;
}
*/
if ($cid > 0) {
$cat_ids = $cid;
} else if ($parent_cid > 0) {
$cat_ids = $parent_cid;
}
//
echo '<!-- auto get same cat -->';
}
// echo 'aaaaaaaaaaaaa<br>';
//
_eb_echo_widget_name($options['this_name'], $before_widget);
// lấy theo nhóm tin đã được chỉ định
//echo $cat_ids . '<br>' . "\n";
if ($cat_ids > 0) {
//echo $cat_type . '<br>' . "\n";
//echo $pid . '<br>' . "\n";
// lấy lại taxonomy dựa theo ID cho nó chuẩn xác
$cat_type = WGR_get_taxonomy_name($cat_ids, $cat_type);
//echo $cat_type . '<br>' . "\n";
if ($cat_type == '') {
echo '<!-- taxonomy for #' . $cat_ids . ' not found! -->';
}
//
else {
//
// echo $cat_type . '<br>' . "\n";
// xác định lại post type nếu đang là lấy tin tự động, và nghi ngờ post type với taxonomy không hợp lệ
if ($get_post_type == 'on' && $same_cat == 'on' && $cat_type != EB_BLOG_POST_LINK && $post_type == EB_BLOG_POST_TYPE) {
$post_type = 'post';
}
//
//print_r( $re_post_categories );
if (!empty($re_post_categories)) {
foreach ($re_post_categories as $v) {
$terms_categories[] = $v->term_id;
}
} else {
$terms_categories[] = $cat_ids;
}
//
if ($post_type == 'for_other_post_type' && $get_post_type == 'on') {
//echo 'for_other_post_type aaaaaaa';
$arr_select_data = array();
$arr_select_data['tax_query'] = array(
array(
'taxonomy' => $cat_type,
'field' => 'term_id',
// 'terms' => array( $cat_ids ),
'terms' => $terms_categories,
'operator' => 'IN'
)
);
//print_r( $arr_select_data );
$sql = _eb_load_post_obj(1, $arr_select_data);
//print_r( $sql );
}
//echo $post_type . '<br>' . "\n";
//
if ($cat_link == '') {
$cat_link = _eb_c_link($cat_ids, $cat_type);
}
$more_link = '<div class="widget-blog-more"><a href="' . $cat_link . '">Xem thêm <span>»</span></a></div>';
if ($title == '') {
// echo $cat_ids;
// $categories = get_term_by('id', $cat_ids, $cat_type);
$categories = get_term($cat_ids, $cat_type);
// print_r($categories);
if (!empty($categories)) {
$title = $categories->name;
}
// print_r($categories);
}
// danh sách nhóm cấp 2
$arr_sub_cat = array(
'parent' => $cat_ids,
'taxonomy' => $cat_type,
);
$sub_cat = get_categories($arr_sub_cat);
// print_r( $sub_cat );
if (!empty($sub_cat)) {
// lấy các các bài viết trong nhóm con (nếu có)
foreach ($sub_cat as $sub_v) {
$terms_categories[] = $sub_v->term_id;
}
//
if ($post_type != 'ads' && $get_childs == 'on') {
foreach ($sub_cat as $sub_v) {
$str_sub_cat .= ' <a href="' . _eb_c_link($sub_v->term_id, $cat_type) . '">' . $sub_v->name . ' <span class="blog-count-subcat">(' . $sub_v->count . ')</span></a>';
}
$str_sub_cat = '<div class="widget-blog-subcat">' . $str_sub_cat . '</div>';
}
}
}
}
// lấy tất cả
else {
// tự xác định lại taxonomy
if ($post_type == EB_BLOG_POST_TYPE) {
$cat_type = EB_BLOG_POST_LINK;
} else {
$cat_type = 'category';
}
//
$args = array(
'taxonomy' => $cat_type,
);
$categories = get_categories($args);
// print_r( $categories );
//
if (!empty($categories)) {
foreach ($categories as $v) {
$terms_categories[] = $v->term_id;
}
}
}
// print_r( $terms_categories );
//echo $post_type . '<br>' . "\n";
// https://codex.wordpress.org/Template_Tags/get_posts#Random_posts
$___order = 'DESC';
if ($sortby == '' || $sortby == 'rand') {
$sortby = 'rand';
$___order = '';
}
// https://codex.wordpress.org/Template_Tags/get_posts
$arr_select_data = array(
'orderby' => $sortby,
'order' => $___order,
'post_type' => $post_type,
);
// đối với ads
if ($post_type == 'ads') {
// lấy theo trạng thái
if ($ads_eb_status > 0) {
// v2
/*
$arr_select_data['tax_query'] = array(
array(
'key' => '_eb_ads_status',
'value' => $ads_eb_status,
'operator' => '=',
'type' => 'NUMERIC'
)
);
*/
// v1
$arr_select_data['meta_key'] = '_eb_ads_status';
$arr_select_data['meta_value'] = $ads_eb_status;
$arr_select_data['compare'] = '=';
$arr_select_data['type'] = 'NUMERIC';
// hiển thị trạng thái ads ra để check cho dễ
global $arr_eb_ads_status;
echo '<!-- ADS status: ' . $ads_eb_status . ' - ' . $arr_eb_ads_status[$ads_eb_status] . ' -->';
}
// lấy theo taxonomy
if ($cat_ids > 0) {
// if ( ! empty( $terms_categories ) ) {
$arr_select_data['tax_query'] = array(
array(
'taxonomy' => $cat_type,
'field' => 'term_id',
// 'terms' => array( $cat_ids ),
'terms' => $terms_categories,
'operator' => 'IN'
)
);
}
}
// các post type khác
else {
//
/*
global $cid;
// chỉ lấy các bài viết cùng nhóm
if ( $cat_ids == 0 && $cid > 0 && $same_cat == 'on' ) {
$arr_select_data['tax_query'] = array(
array(
'taxonomy' => $cat_type,
'field' => 'term_id',
'terms' => array( $cid ),
'operator' => 'IN'
)
);
if ( $title == '' ) {
$categories = get_term( $cid, $cat_type );
// print_r($categories);
if ( ! empty( $categories ) ) {
$title = $categories->name;
}
}
}
else {
*/
// post -> có thêm phần trạng thái
if ($post_type == 'post' && $post_eb_status > 0) {
$arr_select_data['meta_key'] = '_eb_product_status';
$arr_select_data['meta_value'] = $post_eb_status;
$arr_select_data['compare'] = '=';
$arr_select_data['type'] = 'NUMERIC';
}
// với blog, lấy đặc biệt hơn chút
// else if ( count( $terms_categories ) > 0 ) {
// -> lấy theo danh mục hoặc post option -> dùng để phân loại widget
// if ( count( $terms_categories ) > 0 ) {
if (!empty($terms_categories)) {
$arr_select_data['tax_query'] = array(
array(
'taxonomy' => $cat_type,
'field' => 'term_id',
'terms' => $terms_categories,
'operator' => 'IN'
)
);
}
// }
}
//
// print_r( $arr_select_data );
$auto_del_line = 'yes';
// nếu là node của sản phẩm -> dùng bản mặc định luôn
if ($html_node == 'thread_node') {
$html_node = __eb_thread_template;
$html_template = 'widget_echbay_thread';
} else {
// cố định file HTML để tối ưu với SEO
if ($post_cloumn == 'chi_anh') {
$html_node = 'blogs_node_chi_anh';
} else if ($post_cloumn == 'chi_chu') {
$html_node = 'blogs_node_chi_chu';
} else if ($post_cloumn == 'text_only') {
$html_node = 'blogs_node_text_only';
} else if (
isset($instance['hide_description']) && $instance['hide_description'] == 'on' &&
isset($instance['hide_info']) && $instance['hide_info'] == 'on'
) {
$html_node = 'blogs_node_avt_title';
}
//
$html_node = EBE_get_page_template($html_node);
$html_node = WGR_add_li_to_thread_node($html_node);
// chỉnh lại kích thước nếu có
if ($custom_size != '') {
$html_node = str_replace('{tmp.cf_blog_size}', $custom_size, $html_node);
$html_node = str_replace('{tmp.cf_product_size}', $custom_size, $html_node);
}
// xóa bỏ các HTML thừa theo option
if (isset($instance['hide_description']) && $instance['hide_description'] == 'on') {
$html_node = str_replace('{tmp.trv_gioithieu}', '', $html_node);
}
if (isset($instance['hide_info']) && $instance['hide_info'] == 'on') {
$html_node = str_replace('{tmp.ngaycapnhat}', '', $html_node);
$html_node = str_replace('{tmp.ant_ten}', '', $html_node);
}
if (isset($instance['show_post_content']) && $instance['show_post_content'] == 'on') {
//echo 'js_ptags: ' . $js_ptags . '<br>' . "\n";
//print_r( $instance ); echo 'aaaaaaaaaaa';
//
$fix_ptags = '';
if ($js_ptags == 'on') {
$fix_ptags = ' each-to-fix-ptags';
//echo 'fix_ptags: ' . $fix_ptags . '<br>' . "\n";
$auto_del_line = 'no';
}
//
$html_node = str_replace('{tmp.trv_gioithieu}', '<div class="echbay-blog-excerpt">{tmp.trv_gioithieu}</div><div class="echbay-blog-content' . $fix_ptags . '">{tmp.post_content}</div>', $html_node);
}
}
//
if ($dynamic_post_tag != '') {
$html_node = EBE_dynamic_title_tag($html_node, $dynamic_post_tag);
}
//
if ($post_cloumn != '') {
$post_cloumn = 'blogs_node_' . $post_cloumn;
}
// echo $cat_link;
//
$html_template = _eb_widget_create_html_template($html_template, 'widget_echbay_blog');
echo '<!-- HTML widget file: ' . $html_template . ' - Widget title: ' . $title . ' -->';
//
$widget_title = '';
if (!isset($instance['hide_widget_title']) || $instance['hide_widget_title'] == 'off') {
$widget_title = _eb_get_echo_widget_title(
$cat_link == '' ? $title : '<a href="' . $cat_link . '">' . $title . '</a>',
'echbay-widget-blogs-title',
// $before_title,
'',
$dynamic_tag
);
if ($description != '') {
$widget_title .= '<div class="echbay-widget-blogs-desc">' . WGR_widget_title_with_bbcode($description) . '</div>';
}
// echo $description;
}
//
echo '<div' . $custom_id . ' class="' . trim($custom_style) . '">';
// chỉ lấy nội dung bài viết
if ($content_only == 'on') {
//
// print_r( $arr_select_data );
// bắt buộc là sắp xếp theo menu_order DESC
$arr_select_data['orderby'] = 'menu_order ID';
$arr_select_data['order'] = 'DESC';
// print_r( $arr_select_data ); exit();
// chỉ lấy 1 bài duy nhất
$sql = _eb_load_post_obj(1, $arr_select_data);
if (isset($sql->post)) {
$cl = '';
// nếu có lệnh bỏ img maxwidth
if ($off_img_max_width != 'on') {
$cl .= ' img-max-width';
}
// thêm lệnh tự tạo ptag
if ($js_ptags == 'on' && $show_content_excerpt == 'on') {
$cl .= ' each-to-fix-ptags';
}
// lấy và in ra nội dung tìm được
echo '<div class="echbay-blog-content_only' . $cl . '">';
echo '<div data-id="' . $sql->post->ID . '" data-type="' . $sql->post->post_type . '" class="quick-edit-content_only"></div>';
// in thẳng
if (isset($sql->post) && isset($sql->post->post_content)) {
echo '<!-- ' . _eb_p_link($sql->post->ID) . ' -->';
if ($sql->post->post_content == '') {
echo $sql->post->post_excerpt;
}
// hiển thị trực tiếp phần content
else if ($show_content_excerpt == 'on') {
echo $sql->post->post_content;
}
// sử dụng hàm the_content để định hình
else {
$content = apply_filters('the_content', $sql->post->post_content);
echo str_replace(']]>', ']]>', $content);
}
}
// sử dụng hàm content của wp -> nặng hơn -> đầy đủ chức năng hơn
/*
while ( $sql->have_posts() ) {
$sql->the_post();
the_content();
}
*/
echo '</div>';
} else {
echo '<!-- ';
print_r($sql);
echo ' -->';
}
}
// mặc định
else {
$arr_select_data['ignore_sticky_posts'] = 1;
// load riêng 1 kiểu đối với ads
/*
if ( $post_type == 'ads' ) {
$content = _eb_load_post( $post_number, $arr_select_data,
$html_node );
}
// mặc định thì load theo post
else {
*/
/*
if ( $get_full_content == 0 ) {
$get_full_content = 'off';
}
echo $get_full_content . '<br>' . "\n";
*/
/*
print_r( array(
'pot_tai' => $cat_type,
'get_full_content' => ( $get_full_content === 'on' ) ? 1 : 0
) );
*/
$content = _eb_load_post(
$post_number,