-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
1193 lines (873 loc) · 29.8 KB
/
Copy pathindex.php
File metadata and controls
1193 lines (873 loc) · 29.8 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
/*
* This is private plugin
* Not active
* Các function và giao diện dùng chung cho theme của EchBay sẽ được viết vào plugin này, trường hợp theme sử dụng giao diện riêng thì file html sẽ được viết trong theme -> code kiểm tra có file riêng sẽ sử dụng nó thay vì file chung
*/
//
//$all_sizes = get_intermediate_image_sizes();
//print_r( $all_sizes );
/*
* Các function hay được sử dụng nhất
// -> lấy url phân nhóm
get_category_link( $id ) -> dùng function riêng cũng được -> _eb_c_link( $id )
*/
//
//echo $wpdb->postmeta . '<br>';
define( 'wp_postmeta', $wpdb->postmeta );
//echo wp_postmeta;
define( 'wp_termmeta', $wpdb->termmeta );
//echo $wpdb->posts . '<br>';
define( 'wp_posts', $wpdb->posts );
//
if ( defined('EB_CHILD_THEME_URL') ) {
define( 'using_child_wgr_theme', 1 );
}
else {
define( 'using_child_wgr_theme', 0 );
}
// danh sách toàn bộ các theme được hỗ trợ
$eb_all_themes_support = array();
//
$arr_posts_structure = NULL;
// mảng dùng để truyền css tương ứng vào theme
/*
* Các file CSS nằm trong plugin tổng sẽ được add trước
* Sau đó là các css của theme -> nó sẽ replace các css được viết trước đó
*/
//$arr_for_add_js = array();
$arr_for_add_css = array();
//$arr_for_add_theme_css = array();
// Load các CSS ưu tiên mặc định
// loại css add thẳng vào html chỉ dành cho trang đầu tiên
$arr_for_add_css[ EB_THEME_PLUGIN_INDEX . 'css/d.css' ] = 0;
// các css kém quan trọng hơn thì cho vào đây
$arr_for_add_css[ EB_THEME_PLUGIN_INDEX . 'css/d2.css' ] = 1;
$arr_for_add_css[ EB_THEME_PLUGIN_INDEX . 'css/m.css' ] = 0;
$arr_for_add_css[ EB_THEME_PLUGIN_INDEX . 'css/g.css' ] = 1;
//
//$arr_for_add_theme_css[ EB_THEME_URL . 'css/style.css' ] = 1;
if ( using_child_wgr_theme == 1 ) {
$arr_for_add_css[ EB_CHILD_THEME_URL . 'css/style.css' ] = 1;
$arr_for_add_css[ EB_CHILD_THEME_URL . 'css/mobile.css' ] = 1;
}
else {
$arr_for_add_css[ EB_THEME_URL . 'css/style.css' ] = 1;
// cho phiên bản mobile
//$arr_for_add_theme_css[ EB_THEME_URL . 'css/mobile.css' ] = 1;
$arr_for_add_css[ EB_THEME_URL . 'css/mobile.css' ] = 1;
// tối ưu cho màn hình đầu tiên
//$arr_for_add_css[ EB_THEME_URL . 'css/first_screen.css' ] = 1;
}
// mảng dùng để thông báo các module HTML được load ra
$arr_for_show_html_file_load = array();
//
//echo EB_THEME_PLUGIN_INDEX . '<br>';
// thư mục public_html hoặc www của web
//define( 'ABSPATH', dirname( dirname( dirname( __FILE__ ) ) ) . '/' );
//define( 'ABSPATH', ABSPATH );
//echo 'ABSPATH: ' . ABSPATH . '<br>';
// nếu thư mục content đã được khai báo -> lấy thư mục theo thông số này
if ( defined('WP_CONTENT_DIR') ) {
define( 'EB_DIR_CONTENT', basename( WP_CONTENT_DIR ) );
define( 'EB_THEME_CONTENT', WP_CONTENT_DIR . '/' );
}
// Không thì khai báo mặc định
else {
// tên thư mục chứa content
define( 'EB_DIR_CONTENT', 'wp-content' );
// thư mục đầy đủ của content
define( 'WP_CONTENT_DIR', ABSPATH . EB_DIR_CONTENT );
// define( 'EB_THEME_CONTENT', EB_WEB_PUBLIC_HTML . EB_DIR_CONTENT . '/' );
define( 'EB_THEME_CONTENT', WP_CONTENT_DIR . '/' );
}
//echo 'WP_CONTENT_DIR: ' . WP_CONTENT_DIR . '<br>';
//echo 'EB_WEB_PUBLIC_HTML: ' . EB_WEB_PUBLIC_HTML . '<br>';
//echo 'EB_THEME_CONTENT: ' . EB_THEME_CONTENT . '<br>';
//echo 'WP_CONTENT_DIR: ' . WP_CONTENT_DIR . '<br>';
//echo basename( EB_THEME_CONTENT ) . '<br>' . "\n";
//
/*
if ( ! defined('EB_THEME_PLUGIN_INDEX') ) {
define( 'EB_THEME_PLUGIN_INDEX', EB_THEME_CONTENT . 'echbaydotcom/' );
echo 'EB_THEME_PLUGIN_INDEX: ' . EB_THEME_PLUGIN_INDEX . '<br>';
}
*/
//define( 'EB_THEME_OUTSOURCE', EB_THEME_URL . 'outsource/' );
define( 'EB_THEME_OUTSOURCE', EB_THEME_PLUGIN_INDEX . 'outsource/' );
//echo 'EB_THEME_OUTSOURCE: ' . EB_THEME_OUTSOURCE . '<br>';
//define( 'EB_THEME_CORE', EB_THEME_URL . 'plugin/class/' );
define( 'EB_THEME_CORE', EB_THEME_PLUGIN_INDEX . 'class/' );
//echo 'EB_THEME_CORE: ' . EB_THEME_CORE . '<br>';
// thư mục các file code riêng của Ếch Bay (thuộc lớp quản trị viên)
//define( 'ECHBAY_PRI_CODE', EB_THEME_URL . 'plugin/echbay/' );
define( 'ECHBAY_PRI_CODE', EB_THEME_PLUGIN_INDEX . 'echbay/' );
//echo ECHBAY_PRI_CODE . '<br>';
/*
* theme
*/
// thư mục lưu trữ các file template html
define( 'EB_THEME_THEME', EB_THEME_URL );
//echo EB_THEME_THEME . '<br>';
// thư mục lưu trữ các file template html
define( 'EB_THEME_HTML', EB_THEME_THEME . 'html/' );
//echo EB_THEME_HTML . '<br>';
// thư mục lưu trữ các file php để chạy các trang tương ứng
define( 'EB_THEME_PHP', EB_THEME_THEME . 'php/' );
//echo EB_THEME_PHP . '<br>';
// URL tương đối
define( 'EB_URL_TUONG_DOI', EB_DIR_CONTENT . '/echbaydotcom/' );
// thư mục lưu trữ cache
define( 'EB_THEME_CACHE', EB_THEME_CONTENT . 'uploads/ebcache/' );
//echo EB_THEME_CACHE . '<br>';
// Định dang riêng cho post type blog
define( 'EB_BLOG_POST_TYPE', 'blog' );
define( 'EB_BLOG_POST_LINK', EB_BLOG_POST_TYPE . 's' );
//
$arr_to_add_menu = array(
'nav-for-mobile' => 'NAV for mobile',
'top-menu-01' => 'Top menu 01',
'top-menu-02' => 'Top menu 02',
'top-menu-03' => 'Top menu 03',
'top-menu-04' => 'Top menu 04',
'top-menu-05' => 'Top menu 05',
'top-menu-06' => 'Top menu 06',
'footer-menu-01' => 'Footer menu 01',
'footer-menu-02' => 'Footer menu 02',
'footer-menu-03' => 'Footer menu 03',
'footer-menu-04' => 'Footer menu 04',
'footer-menu-05' => 'Footer menu 05',
'footer-menu-06' => 'Footer menu 06',
'footer-menu-07' => 'Footer menu 07',
'footer-menu-08' => 'Footer menu 08',
'footer-menu-09' => 'Footer menu 09',
'footer-menu-10' => 'Footer menu 10'
);
// hệ thống ngôn ngữ mặc định -> các ngôn ngữ khác người dùng sẽ thay đổi trong cài đặt
include EB_THEME_CORE . 'lang.php';
// hệ thống function riêng
include EB_THEME_PLUGIN_INDEX . 'functions.php';
// hệ thống config riêng của Ếch Bay
include EB_THEME_CORE . 'database.php';
//
//include EB_THEME_PLUGIN_INDEX . 'jquery_load.php';
// thiết lập gửi email thông qua STMP
if ( $__cf_row ['cf_sys_email'] == 'smtp' || $__cf_row ['cf_sys_email'] == 'pepipost' ) {
// v1
// return _eb_send_mail_phpmailer ( $to_email, '', $title, $message, '', $bcc_email );
// v2
add_filter( 'phpmailer_init', 'EBE_configure_smtp' );
}
// Thiết lập gửi EMail với định dạng HTML
// https://developer.wordpress.org/reference/hooks/wp_mail_content_type/
/*
function WGR_set_html_mail_content_type() {
return 'text/html';
}
add_filter( 'wp_mail_content_type', 'WGR_set_html_mail_content_type' );
*/
// mảng danh sách các định dạng quảng cáo
$arr_eb_ads_status = array(
0 => '[ Không hiển thị ]',
1 => EBE_get_lang('ads_status1'),
4 => EBE_get_lang('ads_status4'),
5 => EBE_get_lang('ads_status5'),
6 => EBE_get_lang('ads_status6'),
7 => EBE_get_lang('ads_status7'),
8 => EBE_get_lang('ads_status8'),
9 => EBE_get_lang('ads_status9'),
10 => EBE_get_lang('ads_status10'),
11 => EBE_get_lang('ads_status11'),
12 => EBE_get_lang('ads_status12'),
13 => EBE_get_lang('ads_status13'),
14 => EBE_get_lang('ads_status14'),
15 => EBE_get_lang('ads_status15')
);
$arr_eb_product_status = array(
0 => EBE_get_lang('product_status0'),
1 => EBE_get_lang('product_status1'),
2 => EBE_get_lang('product_status2'),
3 => EBE_get_lang('product_status3'),
4 => EBE_get_lang('product_status4'),
5 => EBE_get_lang('product_status5'),
6 => EBE_get_lang('product_status6'),
7 => EBE_get_lang('product_status7'),
8 => EBE_get_lang('product_status8'),
9 => EBE_get_lang('product_status9'),
10 => EBE_get_lang('product_status10')
);
// nếu theme có hỗ trợ nhiều định dạng q.cáo khác -> add vào
if ( isset ( $arr_eb_ads_custom_status ) ) {
// print_r( $arr_eb_ads_custom_status );
foreach ( $arr_eb_ads_custom_status as $k => $v ) {
$arr_eb_ads_status[$k] = $v;
}
// print_r( $arr_eb_ads_status );
}
// cáu trúc chính của trang sản phẩm
//define( '__eb_thread_template', file_get_contents( EB_THEME_HTML . 'threadnode.html', 1 ) );
// Nếu có chọn file thiết kế -> sử dụng nguyên mẫu
$load_config_temp = $__cf_row['cf_threadnode_include_file'];
$__eb_thread_template = '';
if ( $load_config_temp != '' ) {
$__eb_thread_template = WGR_check_and_load_tmp_theme( $load_config_temp, 'threadnode' );
}
else {
$__eb_thread_template = EBE_get_page_template(
EBE_get_html_file_addon(
'thread_node',
$__cf_row['cf_cats_node_html']
)
);
}
// nếu chưa có cặp thẻ LI -> bổ sung cặp này vào -> tạo dữ liệu theo thẻ thống nhất
$__eb_thread_template = WGR_add_li_to_thread_node( $__eb_thread_template );
//
define( '__eb_thread_template', $__eb_thread_template );
// css phục vụ việc điều chỉnh kích thước LI -> load sau khi css của node được tải
//$arr_for_add_theme_css[ EB_THEME_PLUGIN_INDEX . 'css/thread_list.css' ] = 1;
$arr_for_add_css[ EB_THEME_PLUGIN_INDEX . 'css/thread_list.css' ] = 1;
/*
* EchBay plugin recommend wp-config
* Các thuộc tính khuyên khích sử dụng trong wp-config.php.
* Nếu người dùng không thiết lập trong wp-config -> sử dụng thiết lập khuyên dùng bởi EchBay
*/
// Tắt chức năng auto update, web ít dùng thì cần quái gì update, hay dùng thì nên update thủ công
if ( ! defined('WP_AUTO_UPDATE_CORE') ) {
if ( $__cf_row['cf_on_off_auto_update_wp'] == 1 ) {
define( 'WP_AUTO_UPDATE_CORE', true );
} else {
define( 'WP_AUTO_UPDATE_CORE', false );
}
}
// cấu hình URL dạng tĩnh -> khuyên dùng
if ( ! defined('WP_SITEURL') ) {
// if ( eb_web_protocol == 'https' ) {
define( 'WP_SITEURL', eb_web_protocol . '://' . $_SERVER['HTTP_HOST'] );
/*
}
else {
// define( 'WP_SITEURL', get_option ( 'siteurl' ) );
define( 'WP_SITEURL', _eb_get_option ( 'siteurl' ) );
}
*/
}
//echo WP_SITEURL . '<br>';
if ( ! defined('WP_HOME') ) {
define( 'WP_HOME', WP_SITEURL );
}
//echo WP_HOME . '<br>'; exit();
/*
* Host chỉ hỗ trợ up file qua FTP cho bảo mật hơn
*/
/*
if ( ! defined('FS_METHOD') ) {
define( 'FS_METHOD', 'ftpext' );
}
*/
if ( ! defined('FTP_HOST') ) {
// define( 'FTP_HOST', $_SERVER['HTTP_HOST'] );
define( 'FTP_HOST', $_SERVER['SERVER_ADDR'] );
}
/*
* Mặc định là không cho edit theme, plugin nếu sử dụng bản miễn phí
* Kích hoạt bằng cách set thủ công trong wp-config.php
*/
if ( ! defined('DISALLOW_FILE_EDIT') ) {
if ( $__cf_row['cf_alow_edit_plugin_theme'] != 1 ) {
define( 'DISALLOW_FILE_EDIT', true );
} else {
define( 'DISALLOW_FILE_EDIT', false );
}
}
/*
* Mặc định là không cho update, install theme, plugin nếu sử dụng bản miễn phí
* Kích hoạt bằng cách set thủ công trong wp-config.php
*/
if ( ! defined('DISALLOW_FILE_MODS') ) {
if ( $__cf_row['cf_alow_edit_plugin_theme'] != 1 ) {
define( 'DISALLOW_FILE_MODS', true );
} else {
define( 'DISALLOW_FILE_MODS', false );
}
}
/*
* Giới hạn số lần tối đa để lưu các bản nháp của bài viết, tự động xóa khi có quá 3 bài
*/
if ( ! defined('WP_POST_REVISIONS') ) {
define( 'WP_POST_REVISIONS', 3 );
}
/*
* Gán mặc định tham số cho thư mục của admin nếu chưa có
*/
if ( ! defined('WP_ADMIN_DIR') ) {
define( 'WP_ADMIN_DIR', 'wp-admin' );
}
//
define( 'admin_link', web_link . WP_ADMIN_DIR . '/' );
/*
* Mặc định là ẩn các menu quan trọng với tài khoản administrator
*/
/*
if ( ! defined('webgiare_dot_org_install') ) {
define( 'webgiare_dot_org_install', true );
}
*/
//
/*
if ( ! defined('WP_CACHE') ) {
define( 'WP_CACHE', true );
}
*/
//
//$url_for_static_file = esc_url( get_template_directory_uri() ) . '/';
//echo $url_for_static_file . '<br>';
//define( 'THEME_OUTSOURCE_URI', $url_for_static_file );
//echo THEME_OUTSOURCE_URI . '<br>';
//
/*
if ( defined('WP_SITEURL') ) {
$___eb_template_uri = WP_SITEURL . '/';
}
else if ( defined('WP_HOME') ) {
$___eb_template_uri = WP_HOME . '/';
}
else {
// $___eb_template_uri = get_template_directory_uri();
$___eb_template_uri = '//' . $_SERVER['HTTP_HOST'] . '/';
}
*/
$___eb_template_uri = web_link;
//echo $___eb_template_uri . ' -> aaaaaaaaaaaaaaaaaaaaaaa<br>' . "\n";
//define( 'EB_URL_OF_THEME', $___eb_template_uri . '/' );
define( 'EB_URL_OF_THEME', $___eb_template_uri . EB_DIR_CONTENT . '/themes/' . basename ( EB_THEME_URL ) . '/' );
//echo EB_URL_OF_THEME . '<br>' . "\n";
//define( 'EB_URL_OF_PLUGIN', esc_url( plugins_url() ) . '/echbaydotcom/' );
//define( 'EB_URL_OF_PLUGIN', dirname( dirname( $___eb_template_uri ) ) . '/echbaydotcom/' );
define( 'EB_URL_OF_PLUGIN', $___eb_template_uri . EB_DIR_CONTENT . '/echbaydotcom/' );
//echo EB_URL_OF_PLUGIN . '<br>' . "\n";
//echo '../../plugins/' . basename( EB_URL_OF_PLUGIN ) . '<br>';
/*
* Thiết kế lại giao diện trang login
*/
if ( mtv_id == 0 ) {
// Thay doi duong dan logo admin
function EBE_wpc_url_login(){
// duong dan vao website cua ban
return '//echbay.com/?utm_source=ebe_wp_theme&utm_campaign=wp_login&utm_term=copyright';
}
add_filter('login_headerurl', 'EBE_wpc_url_login');
// Thay doi logo admin wordpress
function EBE_login_css() {
/*
* Chỉnh lại URL của database nếu vẫn là URL demo
*/
global $wpdb;
//
if ( function_exists('_eb_q') ) {
/*
$sql = _eb_q("SELECT *
FROM
`" . $wpdb->options . "`
WHERE
option_name = 'siteurl'
OR option_name = 'home'
ORDER BY
option_id DESC");
// print_r( $sql );
//
$current_homeurl = '';
$current_siteurl = '';
foreach ( $sql as $v ) {
if ( $v->option_name == 'home' ) {
$current_homeurl = $v->option_value;
}
else if ( $v->option_name == 'siteurl' ) {
$current_siteurl = $v->option_value;
}
}
*/
$current_homeurl = _eb_get_option('home');
$current_siteurl = _eb_get_option('siteurl');
//
WGR_auto_update_link_for_demo ( $current_homeurl, $current_siteurl );
//
// echo $current_homeurl . '<br>' . "\n";
// echo $current_siteurl . '<br>' . "\n";
}
// duong dan den file css moi
$login_css = EB_URL_OF_PLUGIN . 'css/login.css?v=' . time();
// wp_enqueue_style( 'login_css', $login_css );
echo WGR_show_header_favicon( web_link . eb_default_vaficon ) . '
<link rel="stylesheet" href="' . $login_css . '" type="text/css" />
<script type="text/javascript">
setTimeout(function () {
document.getElementsByTagName("a")[0].setAttribute("target", "_blank");
}, 1200);
</script>';
}
add_filter('login_head', 'EBE_login_css');
}
// đăng ký kiểu bài viết, admin menu và các tham số khác
// taxonomy phải được đăng ký trước custom post type
include EB_THEME_CORE . 'custom/taxonomy.php';
include EB_THEME_CORE . 'custom/post-type.php';
include EB_THEME_CORE . 'custom/meta-box.php';
include EB_THEME_CORE . 'custom/user-meta.php';
//remove_filter( 'the_content', 'wpautop' );
//remove_filter( 'the_excerpt', 'wpautop' );
/*
* Nếu biến $content_width chưa có dữ liệu thì gán giá trị cho nó (full HD)
*/
if ( ! isset( $content_width ) ) {
$content_width = 1366;
}
//echo $content_width . '<br>';
//
define( 'id_default_for_get_sidebar', 'main_sidebar' );
/**
@ Thiết lập các chức năng sẽ được theme hỗ trợ
**/
function echbay_theme_setup() {
global $arr_to_add_menu;
global $__cf_row;
/*
* Thiết lập theme có thể dịch được
*/
// $language_folder = EB_THEME_URL . '/languages';
// load_theme_textdomain( 'echbay', $language_folder );
/*
* Tự chèn RSS Feed links trong <head>
*/
if ( $__cf_row['cf_on_off_feed'] == 1 ) {
add_theme_support( 'automatic-feed-links' );
}
/*
* Thêm chức năng post thumbnail
*/
add_theme_support( 'post-thumbnails' );
// Kế đến là cho đoạn sau vào để thêm một size ảnh thumbnail phù hợp với trang bán hàng (không crop)
// add_image_size( 'small', 160, 160, false );
/*
* Thêm chức năng title-tag để tự thêm <title>
* Kích hoạt khi người dùng tắt chức năng SEO của EchBay
*/
// if ( $__cf_row['cf_on_off_echbay_seo'] != 1 && ! is_404() ) {
// add_theme_support( 'title-tag' );
// }
/*
* Thêm chức năng post format
* https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'image',
'video',
'gallery',
'quote',
'link'
) );
/*
* Thêm chức năng custom background
*/
/*
add_theme_support( 'custom-background', array(
'default-color' => '#fff',
) );
*/
/*
* Tạo menu cho theme, cứ dựa theo giao diện, thứ tự menu từ trái -> phải, trên -> dưới
*/
foreach ( $arr_to_add_menu as $k => $v ) {
register_nav_menu ( $k, $v );
}
/*
* Tạo sidebar cho theme
*/
$arr_to_add_sidebar = array(
// main_sidebar
id_default_for_get_sidebar => 'Sidebar chính của website (dùng cho nhiều trang). Mặc định khi các sidebar khác không có dữ liệu thì side này sẽ được gọi ra để lấp chỗ trống.',
'home_sidebar' => 'Sidebar cho trang chủ (home)',
'home_content_top_sidebar' => 'Sidebar cho phần top nội dung của trang chủ (home)',
'home_content_sidebar' => 'Sidebar cho phần footer nội dung của trang chủ (home)',
'category_sidebar' => 'Sidebar cho trang danh sách sản phẩm (category)',
'category_top_content_sidebar' => 'Sidebar cho phần top của trang danh sách sản phẩm (category)',
'category_content_sidebar' => 'Sidebar cho phần nội dung của trang danh sách sản phẩm (category)',
'post_sidebar' => 'Sidebar cho trang chi tiết sản phẩm (post)',
'post_top_content_sidebar' => 'Sidebar cho phần top của trang chi tiết sản phẩm (post)',
'post_content_sidebar' => 'Sidebar cho phần nội dung của trang chi tiết sản phẩm (post)',
'blog_sidebar' => 'Sidebar cho trang tin tức (blog)',
'blog_content_sidebar' => 'Sidebar cho phần nội dung của trang tin tức (blog)',
'blog_details_sidebar' => 'Sidebar cho trang chi tiết tin (blog details)',
'blog_content_details_sidebar' => 'Sidebar cho phần nội dung của trang chi tiết tin (blog details)',
'page_sidebar' => 'Sidebar cho trang tĩnh (page)',
'page_content_sidebar' => 'Sidebar cho phần nội dung của trang tĩnh (page)',
'search_product_options' => 'Options cho phần tìm kiếm nâng cao',
'eb_top_global' => 'Sidebar cho phần TOP của website (* Sử dụng zEchBay Open/ zEchBay Close Tag Tag để tạo các bộ thẻ đóng mở cho từng khối HTML).',
'eb_footer_global' => 'Sidebar cho phần FOOTER của website (* Sử dụng zEchBay Open Tag/ zEchBay Close Tag để tạo các bộ thẻ đóng mở cho từng khối HTML).',
'eb_z1_custom_site' => 'Sidebar dự phòng cho một số site sử dụng module riêng',
// 'eb_z2_custom_site' => 'Sidebar dự phòng cho một số site sử dụng module riêng',
'eb_z1_recycle_bin' => 'Sidebar này gần như không bao giờ được gọi, nó làm nơi lưu trữ các widget đã được tạo ra, không muốn sử dụng nữa nhưng cũng không muốn xóa hẳn.',
);
// chạy vòng lặp add sidebat
foreach ( $arr_to_add_sidebar as $k => $v ) {
register_sidebar( array(
'name' => str_replace( '_', ' ', $k ),
'id' => $k,
'class' => $k,
'description' => $v,
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
// 'before_title' => '<div-for-replace class="' . $k . '-title">',
// 'after_title' => '</div-for-replace>'
'before_title' => $k . '-title',
) );
}
}
//
add_filter ( 'init', 'echbay_theme_setup');
/*
* Sắp xếp sản phẩm theo lựa chọn của người dùng
* https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
function eb_change_product_query ( $query ) {
global $__cf_row;
//
$current_order = isset ( $_GET ['orderby'] ) ? trim ( strtolower( $_GET ['orderby'] ) ) : '';
//
// print_r( $query );
// các post_type mặc định chỉ có 1 dạng sắp xếp
if( isset( $query->query_vars['post_type'] ) ) {
if( $query->query_vars['post_type'] == 'nav_menu_item'
|| $query->query_vars['post_type'] == EB_BLOG_POST_TYPE
|| $query->query_vars['post_type'] == 'ads' ) {
// đây là chỉ số sắp xếp riêng của wordpress
/*
if ( $current_order == 'title' || $current_order == 'date' ) {
}
// mặc định sắp xếp theo STT
else {
*/
if ( $current_order == '' ) {
if ( $query->query_vars['post_type'] == EB_BLOG_POST_TYPE ) {
// $query->set( 'orderby', array(
// 'menu_order' => 'DESC',
// 'date' => 'DESC'
// ) );
$query->set( 'orderby', 'menu_order ID' );
//
// if ( mtv_id == 1 ) print_r( $query );
}
else if ( $query->query_vars['post_type'] == 'ads' ) {
$query->set( 'orderby', 'menu_order ID' );
// $query->set( 'order', 'DESC' );
}
// $query->set( 'orderby', 'menu_order' );
// v1
// $query->set( 'orderby', 'menu_order' );
// $query->set( 'order', 'DESC' );
// $query->set( 'orderby', 'ID' );
// $query->set( 'order', 'DESC' );
}
//
return $query;
}
}
else {
// echo EB_BLOG_POST_LINK;
// print_r( $query );
// điều chỉnh số lượng post sẽ được hiển thị trên mỗi trang Blog
if ( $__cf_row['cf_blogs_per_page'] > 0 && isset( $query->query_vars[ EB_BLOG_POST_LINK ] ) ) {
// print_r( $query );
$query->set( 'posts_per_page', $__cf_row['cf_blogs_per_page'] );
}
}
/*
* Tìm nâng cao
*/
if ( isset( $_GET['search_advanced'] ) ) {
/*
* Tìm theo khoảng giá
*/
$price_in = isset ( $_GET ['price_in'] ) ? trim ( strtolower( $_GET ['price_in'] ) ) : '';
if ( $price_in != '' ) {
$price_in = explode( '-', $price_in );
// từ 0 đến min_price
if ( count( $price_in ) == 1 ) {
/*
$price_in = array(
'key' => '_eb_product_price',
'value' => $price_in[0],
'compare' => '<',
'type' => 'INT'
);
*/
$price_in = array(
'key' => '_eb_product_price',
// value should be array of (lower, higher) with BETWEEN
'value' => array( 0, $price_in[0] ),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
);
}
else if ( count( $price_in ) == 2 ) {
// từ max_price trở lên
if ( trim( $price_in[0] ) == '' ) {
$price_in = array(
'key' => '_eb_product_price',
'value' => $price_in[1],
'compare' => '>=',
'type' => 'NUMERIC'
);
}
// trong khoảng
else {
$price_in = array(
'key' => '_eb_product_price',
// value should be array of (lower, higher) with BETWEEN
'value' => array( $price_in[0], $price_in[1] ),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
);
}
}
else {
$price_in = NULL;
}
//
if ( $price_in != NULL ) {
// print_r($price_in);
$query->set( 'meta_query', array( $price_in ) );
}
}
/*
* Tìm theo phân nhóm
*/
/*
$seach_advanced_by_cats = isset ( $_GET ['filter_cats'] ) ? trim ( strtolower( $_GET ['filter_cats'] ) ) : '';
if ( $seach_advanced_by_cats != '' ) {
}
*/
/*
* Tìm kiếm nâng cao
*/
$tim_nang_cao = isset ( $_GET ['filter'] ) ? trim ( strtolower( $_GET ['filter'] ) ) : '';
$in_nang_cao = isset ( $_GET ['filter_in'] ) ? trim ( strtolower( $_GET ['filter_in'] ) ) : '';
if ( $tim_nang_cao != '' || $in_nang_cao != '' ) {
$tim_nang_cao = explode( ',', $tim_nang_cao );
$arr_ids = array();
$in_nang_cao = explode( ',', $in_nang_cao );
$arr_in_ids = array();
//
foreach ( $tim_nang_cao as $k => $v ) {
$v = trim( $v );
if ( $v != '' && is_numeric( $v ) ) {
$arr_ids[] = $v;
}
/*
if ( $v != '' && ! is_numeric( $v ) ) {
unset( $tim_nang_cao[$k] );
}
*/
}
//
foreach ( $in_nang_cao as $k => $v ) {
$v = trim( $v );
if ( $v != '' && is_numeric( $v ) ) {
$arr_in_ids[] = $v;
}
}
//
// $tim_nang_cao = implode( ',', $tim_nang_cao );
//
// $tim_nang_cao = explode( ',', $tim_nang_cao );
// AND
// if ( count( $tim_nang_cao ) > 0 ) {
if ( ! empty( $arr_ids ) ) {
$arr_ids = array(
'field' => 'term_id',
// 'terms' => $tim_nang_cao,
// 'terms' => $tim_nang_cao[0],
// 'terms' => $tim_nang_cao,
'terms' => $arr_ids,
// 'operator' => 'IN',
'operator' => 'AND',
'taxonomy' => 'post_options'
);
}
// IN
if ( ! empty( $arr_in_ids ) ) {
$arr_in_ids = array(
'field' => 'term_id',
// 'terms' => $tim_nang_cao,
// 'terms' => $tim_nang_cao[0],
// 'terms' => $tim_nang_cao,
'terms' => $arr_in_ids,
// 'operator' => 'IN',
// 'operator' => 'AND',
'taxonomy' => 'post_options'
);
}
//
if ( ! empty( $arr_ids ) && ! empty( $arr_in_ids ) ) {
$query->set( 'tax_query', array(
$arr_ids,
$arr_in_ids
) );
}
else if ( ! empty( $arr_ids ) ) {
$query->set( 'tax_query', array(
$arr_ids
) );
}
else if ( ! empty( $arr_in_ids ) ) {
$query->set( 'tax_query', array(
$arr_in_ids
) );
}
}
}
/*
* Sắp xếp sản phẩm
* https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
*/
switch ( $current_order ) {
// xem nhiều -> lượt xem giảm dần
case "view":
$query->set( 'meta_key', '_eb_product_views' );
$query->set( 'orderby', 'meta_value_num' );
// $query->set( 'order', 'DESC' );