/
KBoard.class.php
1025 lines (925 loc) · 26.2 KB
/
KBoard.class.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
/**
* KBoard 워드프레스 게시판 설정
* @link www.cosmosfarm.com
* @copyright Copyright 2021 Cosmosfarm. All rights reserved.
* @license http://www.gnu.org/licenses/gpl.html
*/
class KBoard {
private $fields;
var $id;
var $row;
var $content;
var $category;
var $category_row;
var $tree_category;
var $current_user;
var $meta;
public function __construct($id=''){
$this->row = new stdClass();
$this->meta = new KBoardMeta();
$this->fields = null;
$this->tree_category = new KBoardTreeCategory();
$this->current_user = wp_get_current_user();
$this->setID($id);
}
public function __get($name){
if(isset($this->row->{$name})){
return $this->row->{$name};
}
return '';
}
/**
* 게시판 아이디값을 입력받는다.
* @param int $id
* @return KBoard
*/
public function setID($id){
global $wpdb;
$id = intval($id);
if($id){
$this->row = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}kboard_board_setting` WHERE `uid`='$id'");
if(isset($this->row->uid) && $this->row->uid){
$this->id = $this->row->uid;
$this->meta = new KBoardMeta($this->row->uid);
$this->fields = new KBoardFields($this);
$this->tree_category = new KBoardTreeCategory($this->meta->tree_category);
return $this;
}
}
$this->id = 0;
$this->meta = new KBoardMeta();
$this->fields = null;
$this->tree_category = new KBoardTreeCategory();
$wpdb->flush();
return $this;
}
/**
* 게시판 아이디값을 반환한다.
* @return int
*/
public function getID(){
return intval($this->id);
}
/**
* 게시판 아이디값을 반환한다.
* @return int
*/
public function ID(){
return intval($this->id);
}
/**
* 게시판 이름을 반환한다.
* @return string
*/
public function getTitle(){
return $this->board_name;
}
/**
* 게시판 정보를 입력받는다.
* @param object $row
* @return KBoard
*/
public function initWithRow($row){
global $wpdb;
$this->row = $row;
if(isset($this->row->uid) && $this->row->uid){
$this->id = $this->row->uid;
$this->meta = new KBoardMeta($this->row->uid);
$this->fields = new KBoardFields($this);
$this->tree_category = new KBoardTreeCategory($this->meta->tree_category);
}
else{
$this->id = 0;
$this->meta = new KBoardMeta();
$this->fields = null;
$this->tree_category = new KBoardTreeCategory();
}
$wpdb->flush();
return $this;
}
/**
* 게시글이 등록된 게시판 정보를 초기화한다.
* @param int $content_uid
* @return KBoard
*/
public function initWithContentUID($content_uid){
global $wpdb;
$content_uid = intval($content_uid);
if($content_uid){
$this->row = $wpdb->get_row("SELECT `board`.* FROM `{$wpdb->prefix}kboard_board_content` AS `content` LEFT JOIN `{$wpdb->prefix}kboard_board_setting` AS `board` ON `content`.`board_id`=`board`.`uid` WHERE `content`.`uid`='{$content_uid}'");
if(isset($this->row->uid) && $this->row->uid){
$this->id = $this->row->uid;
$this->meta = new KBoardMeta($this->row->uid);
$this->fields = new KBoardFields($this);
$this->tree_category = new KBoardTreeCategory($this->meta->tree_category);
$wpdb->flush();
return $this;
}
}
$this->id = 0;
$this->meta = new KBoardMeta();
$this->fields = null;
$this->tree_category = new KBoardTreeCategory();
$wpdb->flush();
return $this;
}
/**
* 카테고리1 정보를 초기화 한다.
* @return string
*/
public function initCategory1(){
$category1_list = apply_filters('kboard_init_category1_list', $this->category1_list, $this);
$this->category = explode(',', $category1_list);
return $category1_list;
}
/**
* 카테코리2 정보를 초기화 한다.
* @return string
*/
public function initCategory2(){
$category2_list = apply_filters('kboard_init_category2_list', $this->category2_list, $this);
$this->category = explode(',', $category2_list);
return $category2_list;
}
/**
* 카테코리3 정보를 초기화 한다.
* @return string
*/
public function initCategory3(){
$category3_list = apply_filters('kboard_init_category2_list', $this->category3_list, $this);
$this->category = explode(',', $category3_list);
return $category3_list;
}
/**
* 카테코리4 정보를 초기화 한다.
* @return string
*/
public function initCategory4(){
$category4_list = apply_filters('kboard_init_category2_list', $this->category4_list, $this);
$this->category = explode(',', $category4_list);
return $category4_list;
}
/**
* 카테코리5 정보를 초기화 한다.
* @return string
*/
public function initCategory5(){
$category5_list = apply_filters('kboard_init_category2_list', $this->category5_list, $this);
$this->category = explode(',', $category5_list);
return $category5_list;
}
/**
* 다음 카테고리 정보를 반환한다.
* @return object
*/
public function hasNextCategory(){
if(!$this->category) $this->initCategory1();
$this->category_row = current($this->category);
if(!$this->category_row) unset($this->category);
else next($this->category);
return $this->category_row;
}
/**
* 카테고리 정보를 반환한다.
* @return string
*/
public function currentCategory(){
return sanitize_text_field($this->category_row);
}
/**
* 게시글의 댓글 폼과 리스트를 생성한다.
* @param int $content_uid
* @return string
*/
public function buildComment($content_uid){
if($this->id && $content_uid && $this->isComment()){
if($this->meta->comments_plugin_id && $this->meta->use_comments_plugin){
$template = new KBTemplate();
return $template->comments_plugin($this->meta);
}
else{
$args['board'] = $this;
$args['board_id'] = $this->id;
$args['content_uid'] = $content_uid;
$args['skin'] = $this->meta->comment_skin;
$args['permission_comment_write'] = $this->meta->permission_comment_write;
return kboard_comments_builder($args);
}
}
return '';
}
/**
* 글 읽기 권한이 있는 사용자인지 확인한다.
* @param int $user_id
* @param string $secret
* @return boolean
*/
public function isReader($user_id, $secret=''){
$is_reader = false;
if($this->permission_read == 'all' && !$secret){
$is_reader = true;
}
else if(is_user_logged_in()){
if($user_id == get_current_user_id()){
// 본인 허용
$is_reader = true;
}
else if($this->isAdmin()){
// 게시판 관리자 허용
$is_reader = true;
}
else if($this->permission_read == 'author' && !$secret){
// 로그인 사용자 허용
$is_reader = true;
}
else if($this->permission_read == 'roles' && !$secret){
// 선택된 역할의 사용자 허용
if(array_intersect($this->getReadRoles(), kboard_current_user_roles())){
$is_reader = true;
}
}
}
else if(get_option('kboard_allow_search_engines_always_read') && kboard_is_bot()){
// 검색엔진 검색로봇 허용
$is_reader = true;
}
return apply_filters('kboard_is_reader', $is_reader, $user_id, $secret, $this);
}
/**
* 글 쓰기 권한이 있는 사용자인지 확인한다.
* @return boolean
*/
public function isWriter(){
$is_writer = false;
if($this->permission_write == 'all'){
$is_writer = true;
}
else if(is_user_logged_in()){
if($this->isAdmin()){
// 게시판 관리자 허용
$is_writer = true;
}
else if($this->permission_write == 'author'){
// 로그인 사용자 허용
$is_writer = true;
}
else if($this->permission_write == 'roles'){
// 선택된 역할의 사용자 허용
if(array_intersect($this->getWriteRoles(), kboard_current_user_roles())){
$is_writer = true;
}
}
}
return apply_filters('kboard_is_writer', $is_writer, $this);
}
/**
* 글 수정 권한이 있는 사용자인지 확인한다.
* @param int $user_id
* @return boolean
*/
public function isEditor($user_id){
$is_editor = false;
$use_prevent_modify_delete = $this->meta->use_prevent_modify_delete;
if(is_user_logged_in()){
if(!$use_prevent_modify_delete && $user_id == get_current_user_id()){
// 본인 허용
$is_editor = true;
}
else if($this->isAdmin()){
// 게시판 관리자 허용
$is_editor = true;
}
}
return apply_filters('kboard_is_editor', $is_editor, $user_id, $use_prevent_modify_delete, $this);
}
/**
* 주문하기 권한이 있는 사용자인지 확인한다.
* @return boolean
*/
public function isOrder(){
$is_order = false;
if(!$this->meta->permission_order){
$is_order = true;
}
else if(is_user_logged_in()){
if($this->isAdmin()){
// 게시판 관리자 허용
$is_order = true;
}
else if($this->meta->permission_order == 'roles'){
// 선택된 역할의 사용자 허용
if(array_intersect($this->getOrderRoles(), kboard_current_user_roles())){
$is_order = true;
}
}
else{
// 로그인 사용자 허용
$is_order = true;
}
}
return apply_filters('kboard_is_order', $is_order, $this);
}
/**
* 답글쓰기 권한이 있는 사용자인지 확인한다.
* @return boolean
*/
public function isReply(){
$is_reply = false;
if(!$this->meta->permission_reply){
$is_reply = true;
}
else if(is_user_logged_in()){
if($this->isAdmin()){
// 게시판 관리자 허용
$is_reply = true;
}
else if($this->meta->permission_reply == 'roles'){
// 선택된 역할의 사용자 허용
if(array_intersect($this->getReplyRoles(), kboard_current_user_roles())){
$is_reply = true;
}
}
else{
// 로그인 사용자 허용
$is_reply = true;
}
}
return apply_filters('kboard_is_reply', $is_reply, $this);
}
public function isBuyer($user_id){
$is_buyer = false;
if(is_user_logged_in()){
if($user_id == get_current_user_id()){
// 본인 허용
$is_buyer = true;
}
else if($this->isAdmin()){
// 게시판 관리자 허용
$is_buyer = true;
}
}
return apply_filters('kboard_is_buyer', $is_buyer, $this);
}
/**
* 첨부파일 다운로드 권한이 있는 사용자인지 확인한다.
* @return boolean
*/
public function isAttachmentDownload(){
$is_attachment_download = false;
if(!$this->meta->permission_attachment_download){
$is_attachment_download = true;
}
else if(is_user_logged_in()){
if($this->isAdmin()){
// 게시판 관리자 허용
$is_attachment_download = true;
}
else if($this->meta->permission_attachment_download == 'roles'){
// 선택된 역할의 사용자 허용
if(array_intersect($this->getAttachmentDownloadRoles(), kboard_current_user_roles())){
$is_attachment_download = true;
}
}
else{
// 로그인 사용자 허용
$is_attachment_download = true;
}
}
return apply_filters('kboard_is_attachment_download', $is_attachment_download, $this);
}
/**
* 추천권한이 있는 사용자인지 확인한다.
* @return boolean
*/
public function isVote(){
$is_vote = false;
if(!$this->meta->permission_vote){
$is_vote = true;
}
else if(is_user_logged_in()){
if($this->isAdmin()){
// 게시판 관리자 허용
$is_vote = true;
}
else if($this->meta->permission_vote == 'roles'){
// 선택된 역할의 사용자 허용
if(array_intersect($this->getVoteRoles(), kboard_current_user_roles())){
$is_vote = true;
}
}
else{
// 로그인 사용자 허용
$is_vote = true;
}
}
return apply_filters('kboard_is_vote', $is_vote, $this);
}
/**
* 게시글 비밀번호와 일치하는지 확인한다.
* @param string $content_password
* @param int $content_uid
* @param boolean $reauth
* @return boolean
*/
public function isConfirm($content_password, $content_uid, $reauth=false){
$confirm = false;
$input_password = '';
$reauth = apply_filters('kboard_password_confirm_reauth', $reauth, $this);
if($content_password && $content_uid){
$input_password = isset($_POST['password']) ? sanitize_text_field($_POST['password']) : '';
if($reauth){
if($input_password == $content_password){
$_SESSION['kboard_confirm'][$content_uid] = $content_password;
$confirm = true;
}
}
else if(isset($_SESSION['kboard_confirm']) && isset($_SESSION['kboard_confirm'][$content_uid]) && $_SESSION['kboard_confirm'][$content_uid] == $content_password){
$confirm = true;
}
else if($input_password == $content_password){
$_SESSION['kboard_confirm'][$content_uid] = $content_password;
$confirm = true;
}
}
return apply_filters('kboard_password_confirm', $confirm, $input_password, $content_password, $content_uid, $reauth, $this);
}
/**
* 비밀번호 확인에 실패했는지 확인한다.
* @return boolean
*/
public function isConfirmFailed(){
$submitted_password = isset($_POST['password']) ? sanitize_text_field($_POST['password']) : '';
if($submitted_password){
return true;
}
return false;
}
/**
* 관리자인지 확인한다.
* @param int $user_id
* @return boolean
*/
public function isAdmin($user_id=''){
if($this->id && (is_user_logged_in() || $user_id)){
$admin_user = explode(',', $this->admin_user);
$admin_user = array_map('sanitize_text_field', $admin_user);
if($user_id){
$user = get_userdata($user_id);
}
else{
$user = $this->current_user;
}
if(in_array('administrator', kboard_current_user_roles($user_id))){
// 최고관리자 허용
return true;
}
else if(is_array($admin_user) && in_array($user->user_login, $admin_user)){
// 선택된 관리자 허용
return true;
}
else if(array_intersect($this->getAdminRoles(), kboard_current_user_roles($user_id))){
// 선택된 역할의 사용자 허용
return true;
}
}
return false;
}
/**
* 댓글 플러그인이 있고, 해당 게시판에서 댓글을 사용하는지 확인한다.
* @return boolean
*/
public function isComment(){
if(defined('KBOARD_COMMNETS_VERSION') && $this->use_comment) return true;
if($this->meta->comments_plugin_id && $this->meta->use_comments_plugin) return true;
return false;
}
/**
* 주문시 포인트를 사용할 수 있는지 확인한다.
* @return boolean
*/
public function isUsePointOrder(){
if(class_exists('myCRED_Core')){
return true;
}
return false;
}
public function isTreeCategoryActive(){
if($this->use_category && $this->meta->use_tree_category){
return true;
}
return false;
}
/**
* 읽기권한의 role을 반환한다.
* @return array
*/
public function getReadRoles(){
if($this->meta->permission_read_roles){
return unserialize($this->meta->permission_read_roles);
}
return array();
}
/**
* 쓰기권한의 role을 반환한다.
* @return array
*/
public function getWriteRoles(){
if($this->meta->permission_write_roles){
return unserialize($this->meta->permission_write_roles);
}
return array();
}
/**
* 답글쓰기권한의 role을 반환한다.
* @return array
*/
public function getReplyRoles(){
if($this->meta->permission_reply_roles){
return unserialize($this->meta->permission_reply_roles);
}
return array();
}
/**
* 댓글쓰기권한의 role을 반환한다.
* @return array
*/
public function getCommentRoles(){
if($this->meta->permission_comment_write_roles){
return unserialize($this->meta->permission_comment_write_roles);
}
return array();
}
/**
* 주문하기권한의 role을 반환한다.
* @return array
*/
public function getOrderRoles(){
if($this->meta->permission_order_roles){
return unserialize($this->meta->permission_order_roles);
}
return array();
}
/**
* 관리자권한의 role을 반환한다.
* @return array
*/
public function getAdminRoles(){
if($this->meta->permission_admin_roles){
return unserialize($this->meta->permission_admin_roles);
}
return array();
}
/**
* 첨부파일 다운로드 권한의 role을 반환한다.
* @return array
*/
public function getAttachmentDownloadRoles(){
if($this->meta->permission_attachment_download_roles){
return unserialize($this->meta->permission_attachment_download_roles);
}
return array();
}
/**
* 추천권한의 role을 반환한다.
* @return array
*/
public function getVoteRoles(){
if($this->meta->permission_vote_roles){
return unserialize($this->meta->permission_vote_roles);
}
return array();
}
/**
* 복사 방지 스크립트를 사용하는지 반환한다.
* @return int
*/
public function isUsePreventCopy(){
if($this->meta->prevent_copy){
return $this->meta->prevent_copy;
}
else{
return get_option('kboard_prevent_copy', '');
}
return '';
}
/**
* 게시글 표시 수 제외 옵션을 확인한다.
* @return int
*/
public function getExceptCountList(){
global $wpdb;
$results = '';
if($this->meta->except_count_type == '1'){//답변 제외
$results = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}kboard_board_content` WHERE `board_id`='$this->id' AND `parent_uid` = 0 AND `status`!='trash'");
return intval($results);
}
else if($this->meta->except_count_type == '2'){//공지사항 제외
$results = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}kboard_board_content` WHERE `board_id`='$this->id' AND `notice` != 'true' AND `status`!='trash'");
return intval($results);
}
else if($this->meta->except_count_type == '3'){//답변, 공지사항 제외
$results = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}kboard_board_content` WHERE `board_id`='$this->id' AND `parent_uid` = 0 AND `notice` != 'true' AND `status`!='trash'");
return intval($results);
}
else if($this->meta->except_count_type == '4'){//글 제목 키워드 설정 제외
if($this->meta->except_count_type_keyword){
$results = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}kboard_board_content` WHERE `board_id`='$this->id' AND `title` NOT LIKE '%{$this->meta->except_count_type_keyword}%' AND `status`!='trash'");
return intval($results);
}
else{
$results = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}kboard_board_content` WHERE `board_id`='$this->id' AND `status`!='trash'");
return intval($results);
}
}
return $results;
}
/**
* 게시판을 삭제한다.
* @param int $board_id
*/
public function delete($board_id=''){
$board_id = intval($board_id);
if($board_id){
$this->remove($board_id);
}
else if($this->id){
$this->remove($this->id);
}
}
/**
* 게시판을 삭제한다.
* @param int $board_id
*/
public function remove($board_id){
global $wpdb;
$board_id = intval($board_id);
if($board_id){
$list = new KBContentList($board_id);
$list->rpp(1000);
$list->initFirstList();
while($list->hasNextList()){
while($content = $list->hasNext()){
$content->delete(false);
}
$list->initFirstList();
}
$wpdb->query("DELETE FROM `{$wpdb->prefix}kboard_board_setting` WHERE `uid`='$board_id'");
$wpdb->query("DELETE FROM `{$wpdb->prefix}kboard_board_meta` WHERE `board_id`='$board_id'");
$wpdb->flush();
}
}
/**
* 모든 게시글을 삭제한다.
*/
public function truncate(){
if($this->id){
$list = new KBContentList($this->id);
$list->rpp(1000);
$list->initFirstList();
while($list->hasNextList()){
while($content = $list->hasNext()){
$content->delete(false);
}
$list->initFirstList();
}
$this->resetTotal();
}
}
/**
* 게시판에서 CAPTCHA 사용 여부를 확인한다.
* @return boolean
*/
public function useCAPTCHA(){
if(is_user_logged_in() || get_option('kboard_captcha_stop')){
return apply_filters('kboard_use_captcha', false, $this);
}
return apply_filters('kboard_use_captcha', true, $this);
}
/**
* 게시판에서 비로그인 작성자 입력 필드 보여줄지 확인한다.
* @return boolean
*/
public function viewUsernameField(){
if(!is_user_logged_in() || ($this->content->uid && !$this->content->member_uid)){
return true;
}
return false;
}
/**
* 게시판에 등록된 전체 게시글 숫자를 반환한다.
* @return int
*/
public function getTotal(){
global $wpdb;
if(!$this->id){
return 0;
}
if(!$this->meta->total || $this->meta->total<=0){
$this->meta->total = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}kboard_board_content` WHERE `board_id`='$this->id'");
}
return intval($this->meta->total);
}
/**
* 게시판 리스트에 표시되는 게시글 숫자를 반환한다.
* @return int
*/
public function getListTotal(){
global $wpdb;
if(!$this->id){
return 0;
}
if($this->meta->except_count_type){
return $this->getExceptCountList();
}
if(!$this->meta->list_total || $this->meta->list_total<=0){
$this->meta->list_total = $this->getTotal();
$results = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}kboard_board_content` WHERE `board_id`='$this->id' AND `status`='trash'");
$wpdb->flush();
foreach($results as $row){
$content = new KBContent();
$content->initWithRow($row);
$content->board = $this;
$content->moveReplyToTrash($content->uid);
}
}
// return intval(apply_filters('kboard_get_list_total', $this->meta->list_total, $this));
return intval($this->meta->list_total);
}
/**
* 게시글 숫자를 초기화한다.
*/
public function resetTotal(){
if($this->id){
$this->meta->total = 0;
$this->meta->list_total = 0;
}
}
/**
* 본인의 글만 보기로 설정한다.
*/
public function setPrivate(){
$this->row->private = true;
}
/**
* 본인의 글만 보기인지 확인한다.
*/
public function isPrivate(){
if(($this->meta->permission_list || (isset($this->row->private) && $this->row->private == true)) && !$this->isAdmin()){
return true;
}
return false;
}
/**
* 입력된 숫자를 통화 형식으로 반환한다.
* @param int $value
* @param string $format
* @return string
*/
public function currency($value, $format='%s원'){
return sprintf(apply_filters('kboard_currency_format', $format, $this), number_format($value));
}
/**
* 해당 카테고리에 등록된 게시글 숫자를 반환한다.
* @param array|string $category
* @return int
*/
public function getCategoryCount($category){
global $wpdb;
if($this->id && $category){
$where = array();
$where[] = "`board_id`='{$this->id}'";
if(is_array($category)){
if(isset($category['category1']) && $category['category1']){
$category1 = esc_sql($category['category1']);
$where[] = "`category1`='{$category1}'";
}
if(isset($category['category2']) && $category['category2']){
$category2 = esc_sql($category['category2']);
$where[] = "`category2`='{$category2}'";
}
}
else{
$category = esc_sql($category);
$where[] = "(`category1`='{$category}' OR `category2`='{$category}')";
}
// 휴지통에 없는 게시글만 불러온다.
$get_list_status_query = kboard_get_list_status_query($this->id);
if($get_list_status_query){
$where[] = $get_list_status_query;
}
$count = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}kboard_board_content` WHERE " . implode(' AND ', $where));
$wpdb->flush();
return intval($count);
}
return 0;
}
/**
* 사용자가 작성한 개시글 숫자를 반환한다.
* @param int $user_id
* @return int
*/
public function getUserCount($user_id){
global $wpdb;
$user_id = intval($user_id);
if($this->id && $user_id){
$where = array();
$where[] = "`board_id`='{$this->id}'";
$where[] = "`member_uid`='{$user_id}'";
// 휴지통에 없는 게시글만 불러온다.
$get_list_status_query = kboard_get_list_status_query($this->id);
if($get_list_status_query){
$where[] = $get_list_status_query;
}
$count = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}kboard_board_content` WHERE " . implode(' AND ', $where));
$wpdb->flush();
return intval($count);
}
return 0;
}
/**
* 사용자가 작성한 마지막 글을 반환한다.
* @param int $user_id
* @return KBContent
*/
public function getLastContentByUser($user_id){
global $wpdb;
$content = new KBContent();
$user_id = intval($user_id);
if($this->id && $user_id){
$where = array();
$where[] = "`board_id`='{$this->id}'";
$where[] = "`member_uid`='{$user_id}'";
// 휴지통에 없는 게시글만 불러온다.
$get_list_status_query = kboard_get_list_status_query($this->id);
if($get_list_status_query){
$where[] = $get_list_status_query;
}
$uid = $wpdb->get_var("SELECT `uid` FROM `{$wpdb->prefix}kboard_board_content` WHERE " . implode(' AND ', $where) . " ORDER BY `date` DESC LIMIT 1");
$wpdb->flush();
if($uid){
$content->initWithUID($uid);
}
}
return $content;
}
/**
* 동일한 아이피로 작성된 마지막 글을 반환한다.
* @param string $ip
* @return KBContent
*/
public function getLastContentByIP($ip){
global $wpdb;
$content = new KBContent();
$ip = esc_sql(sanitize_text_field($ip));
if($this->id && $ip){
$where = array();
$where[] = "`content`.`board_id`='{$this->id}'";
$where[] = "`option`.`option_key`='ip'";
$where[] = "`option`.`option_value`='{$ip}'";
// 휴지통에 없는 게시글만 불러온다.
$get_list_status_query = kboard_get_list_status_query($this->id, 'content');
if($get_list_status_query){
$where[] = $get_list_status_query;
}
$uid = $wpdb->get_var("SELECT `content`.`uid` FROM `{$wpdb->prefix}kboard_board_content` AS `content` LEFT JOIN `{$wpdb->prefix}kboard_board_option` AS `option` ON `content`.`uid`=`option`.`content_uid` WHERE " . implode(' AND ', $where) . " ORDER BY `content`.`date` DESC LIMIT 1");
$wpdb->flush();
if($uid){
$content->initWithUID($uid);
}
}
return $content;
}
/**
* 인기글 이름 정보를 반환한다.
* @return string
*/
public function getPopularName(){
$popular_name = '';
if(!$this->meta->popular_name){
$popular_name = '인기글';
}
else{