-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.php
1864 lines (1628 loc) · 62.4 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: KBoard : 게시판
Plugin URI: https://www.cosmosfarm.com/products/kboard
Description: 워드프레스 KBoard 게시판 플러그인 입니다.
Version: 5.5.1
Author: 코스모스팜 - Cosmosfarm
Author URI: https://www.cosmosfarm.com/
*/
if(!defined('ABSPATH')) exit;
if(!session_id()) session_start();
define('KBOARD_VERSION', '5.5.1');
define('KBOARD_PAGE_TITLE', __('KBoard : 게시판', 'kboard'));
define('KBOARD_WORDPRESS_ROOT', substr(ABSPATH, 0, -1));
define('KBOARD_WORDPRESS_APP_ID', '083d136637c09572c3039778d8667b27');
define('KBOARD_DIR_PATH', dirname(__FILE__));
define('KBOARD_URL_PATH', plugins_url('', __FILE__));
define('KBOARD_DASHBOARD_PAGE', admin_url('admin.php?page=kboard_dashboard'));
define('KBOARD_LIST_PAGE', admin_url('admin.php?page=kboard_list'));
define('KBOARD_NEW_PAGE', admin_url('admin.php?page=kboard_new'));
define('KBOARD_SETTING_PAGE', admin_url('admin.php?page=kboard_list'));
define('KBOARD_LATESTVIEW_PAGE', admin_url('admin.php?page=kboard_latestview'));
define('KBOARD_LATESTVIEW_NEW_PAGE', admin_url('admin.php?page=kboard_latestview_new'));
define('KBOARD_BACKUP_PAGE', admin_url('admin.php?page=kboard_backup'));
define('KBOARD_CONTENT_LIST_PAGE', admin_url('admin.php?page=kboard_content_list'));
if(!defined('KBOARD_STORE_AUTH')){
define('KBOARD_STORE_AUTH', true);
}
if(!defined('KBOARD_CONNECT_COSMOSFARM')){
define('KBOARD_CONNECT_COSMOSFARM', true);
}
include_once 'class/KBContent.class.php';
include_once 'class/KBContentList.class.php';
include_once 'class/KBContentMedia.class.php';
include_once 'class/KBCommentMedia.class.php';
include_once 'class/KBContentOption.class.php';
include_once 'class/KBController.class.php';
include_once 'class/KBoard.class.php';
include_once 'class/KBoardBuilder.class.php';
include_once 'class/KBoardFields.class.php';
include_once 'class/KBoardList.class.php';
include_once 'class/KBoardMeta.class.php';
include_once 'class/KBoardSkin.class.php';
include_once 'class/KBoardTreeCategory.class.php';
include_once 'class/KBOrder.class.php';
include_once 'class/KBOrderHistory.class.php';
include_once 'class/KBOrderItem.class.php';
include_once 'class/KBOrderSales.class.php';
include_once 'class/KBStore.class.php';
include_once 'class/KBTemplate.class.php';
include_once 'class/KBUrl.class.php';
include_once 'class/KBUpgrader.class.php';
include_once 'class/KBRouter.class.php';
include_once 'class/KBLatestview.class.php';
include_once 'class/KBLatestviewList.class.php';
include_once 'class/KBFileHandler.class.php';
include_once 'class/KBVote.class.php';
include_once 'helper/Pagination.helper.php';
include_once 'helper/Security.helper.php';
include_once 'helper/Functions.helper.php';
/*
* 애드온 파일 로딩
*/
foreach(glob(KBOARD_DIR_PATH . '/addons/*.php') as $filename){
include_once $filename;
}
/*
* KBoard 게시판 시작
*/
add_action('init', 'kboard_init', 5);
function kboard_init(){
// 언어 파일 추가
load_plugin_textdomain('kboard', false, dirname(plugin_basename(__FILE__)) . '/languages');
// 게시판 페이지 이동
$router = new KBRouter();
$router->process();
// 컨트롤러 시작
$controller = new KBController();
// 템플릿 시작
$template = new KBTemplate();
$template->route();
$kboard_list_sort = isset($_GET['kboard_list_sort']) ? sanitize_text_field($_GET['kboard_list_sort']) : '';
$kboard_list_sort_remember = isset($_GET['kboard_list_sort_remember']) ? intval($_GET['kboard_list_sort_remember']) : '';
if($kboard_list_sort && $kboard_list_sort_remember){
if(!in_array($kboard_list_sort, array('newest', 'best', 'viewed', 'updated'))){
$kboard_list_sort = '';
}
if($kboard_list_sort){
$_COOKIE["kboard_list_sort_{$kboard_list_sort_remember}"] = $kboard_list_sort;
setcookie("kboard_list_sort_{$kboard_list_sort_remember}", $kboard_list_sort, strtotime('+1 year'), COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true);
}
else{
$_COOKIE["kboard_list_sort_{$kboard_list_sort_remember}"] = '';
setcookie("kboard_list_sort_{$kboard_list_sort_remember}", '', strtotime('-1 year'), COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true);
}
}
// 스킨의 functions.php 파일을 실행한다.
$skin = KBoardSkin::getInstance();
foreach($skin->getActiveList() as $skin_name){
$skin->loadFunctions($skin_name);
}
}
/*
* 테마 헤더에 정보 출력
*/
add_action('get_header', 'kboard_get_header', 999);
function kboard_get_header(){
// SEO 시작
include_once 'class/KBSeo.class.php';
$seo = new KBSeo();
}
/*
* KBoard 관리자 페이지 기능 실행
*/
add_action('admin_init', 'kboard_admin_init');
function kboard_admin_init(){
// 게시판 관리
$page = isset($_GET['page'])?$_GET['page']:'';
if($page == 'kboard_list' && (!isset($_GET['board_id']) || !$_GET['board_id'])){
$wp_list_table = _get_list_table('WP_Posts_List_Table');
if(isset($_POST['board_id']) && $wp_list_table->current_action() == 'reset_total'){
set_time_limit(0);
ini_set('memory_limit', '-1');
foreach($_POST['board_id'] as $key=>$board_id){
$board = new KBoard($board_id);
$board->resetTotal();
}
}
else if(isset($_POST['board_id']) && $wp_list_table->current_action() == 'truncate'){
set_time_limit(0);
ini_set('memory_limit', '-1');
foreach($_POST['board_id'] as $key=>$board_id){
$board = new KBoard($board_id);
$board->truncate();
}
}
else if(isset($_POST['board_id']) && $wp_list_table->current_action() == 'delete'){
set_time_limit(0);
ini_set('memory_limit', '-1');
foreach($_POST['board_id'] as $key=>$board_id){
$board = new KBoard($board_id);
$board->delete();
}
}
}
// 관리자 컨트롤러 시작
include_once KBOARD_DIR_PATH . '/class/KBAdminController.class.php';
$admin_controller = new KBAdminController();
// 사용자 프로필 필드 추가
include_once KBOARD_DIR_PATH . '/class/KBUserProfileFields.class.php';
$user_profile_fields = new KBUserProfileFields();
}
/*
* 글쓰기 에디터에 미디어 추가하기 버튼을 추가한다.
*/
function kboard_editor_button($context){
$context .= ' <button type="button" class="button" onclick="kboard_editor_open_media()">'.__('KBoard Add Media', 'kboard').'</button> ';
return $context;
}
/*
* 글쓰기 에디터에 미디어 버튼을 등록한다.
*/
function kboard_register_media_button($buttons){
array_push($buttons, 'kboard_media');
return $buttons;
}
/*
* 글쓰기 에디터에 미디어 버튼을 추가한다.
*/
function kboard_add_media_button($plugin_array){
if(!is_admin() || kboard_view_iframe()){
$plugin_array['kboard_media_button_script'] = plugins_url('/template/js/editor_media_button.js', __FILE__);
}
return $plugin_array;
}
/*
* 플러그인 페이지 링크
*/
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'kboard_settings_link');
function kboard_settings_link($links){
return array_merge($links, array('kboard-new'=>'<a href="'.admin_url('admin.php?page=kboard_new').'">'.__('New Forum', 'kboard').'</a>'));
}
/*
* 워드프레스 관리자 웰컴 패널에 KBoard 패널을 추가한다.
*/
add_action('welcome_panel', 'kboard_welcome_panel');
function kboard_welcome_panel(){
echo '<script>jQuery(document).ready(function(){jQuery("div.welcome-panel-content").eq(0).hide();});</script>';
include_once 'pages/welcome.php';
}
/*
* 관리자메뉴에 추가
*/
add_action('admin_menu', 'kboard_settings_menu');
function kboard_settings_menu(){
global $wpdb, $_wp_last_object_menu;
// KBoard 메뉴 등록
$_wp_last_object_menu++;
add_menu_page(KBOARD_PAGE_TITLE, 'KBoard', 'manage_options', 'kboard_dashboard', 'kboard_dashboard', plugins_url('kboard/images/icon.png'), $_wp_last_object_menu);
add_submenu_page('kboard_dashboard', KBOARD_PAGE_TITLE, __('대시보드', 'kboard'), 'manage_options', 'kboard_dashboard');
add_submenu_page('kboard_dashboard', KBOARD_PAGE_TITLE, __('게시판 목록 및 관리', 'kboard'), 'manage_options', 'kboard_list', 'kboard_list');
add_submenu_page('kboard_dashboard', KBOARD_PAGE_TITLE, __('게시판 생성', 'kboard'), 'manage_options', 'kboard_new', 'kboard_new');
add_submenu_page('kboard_dashboard', KBOARD_PAGE_TITLE, __('최신글 모아보기', 'kboard'), 'manage_options', 'kboard_latestview', 'kboard_latestview');
add_submenu_page('kboard_dashboard', KBOARD_PAGE_TITLE, __('최신글 모아보기 생성', 'kboard'), 'manage_options', 'kboard_latestview_new', 'kboard_latestview_new');
add_submenu_page('kboard_dashboard', KBOARD_PAGE_TITLE, __('백업 및 복구', 'kboard'), 'manage_options', 'kboard_backup', 'kboard_backup');
if(KBOARD_CONNECT_COSMOSFARM){
add_submenu_page('kboard_dashboard', KBOARD_PAGE_TITLE, __('업데이트', 'kboard'), 'manage_options', 'kboard_updates', 'kboard_updates');
// 스토어 메뉴 등록
$_wp_last_object_menu++;
add_menu_page(__('스토어', 'kboard'), __('스토어', 'kboard'), 'manage_options', 'kboard_store', 'kboard_store', plugins_url('kboard/images/icon.png'), $_wp_last_object_menu);
add_submenu_page('kboard_store', __('스토어', 'kboard'), __('스토어', 'kboard'), 'manage_options', 'kboard_store');
}
add_submenu_page('kboard_dashboard', KBOARD_PAGE_TITLE, __('전체 게시글', 'kboard'), 'manage_options', 'kboard_content_list', 'kboard_content_list');
// 댓글 플러그인 활성화면 댓글 리스트 페이지를 보여준다.
if(defined('KBOARD_COMMNETS_VERSION') && KBOARD_COMMNETS_VERSION >= '1.3' && KBOARD_COMMNETS_VERSION < '3.3'){
add_submenu_page('kboard_dashboard', KBOARD_COMMENTS_PAGE_TITLE, __('전체 댓글', 'kboard'), 'administrator', 'kboard_comments_list', 'kboard_comments_list');
}
else if(defined('KBOARD_COMMNETS_VERSION') && KBOARD_COMMNETS_VERSION >= '3.3'){
kboard_comments_settings_menu();
}
// 메뉴 액션 실행
do_action('kboard_admin_menu');
$result = $wpdb->get_results("SELECT `meta`.`board_id`, `setting`.`board_name` FROM `{$wpdb->prefix}kboard_board_meta` AS `meta` LEFT JOIN `{$wpdb->prefix}kboard_board_setting` AS `setting` ON `meta`.`board_id`=`setting`.`uid` WHERE `meta`.`key`='add_menu_page'");
foreach($result as $row){
add_submenu_page('kboard_dashboard', KBOARD_PAGE_TITLE, $row->board_name, 'manage_options', "kboard_admin_view_{$row->board_id}", 'kboard_admin_view');
}
}
/*
* 스토어 상품 리스트 페이지
*/
function kboard_store(){
KBStore::productsList();
}
/*
* 게시판 대시보드 페이지
*/
function kboard_dashboard(){
include_once 'pages/kboard_dashboard.php';
}
/*
* 게시판 목록 페이지
*/
function kboard_list(){
if(isset($_GET['board_id']) && $_GET['board_id']){
kboard_setting();
}
else{
include_once 'class/KBoardListTable.class.php';
$table = new KBoardListTable();
/*
if(isset($_POST['board_id']) && $table->current_action() == 'delete'){
foreach($_POST['board_id'] as $key=>$value){
$table->board->delete($value);
}
}
*/
$table->prepare_items();
include_once 'pages/kboard_list.php';
}
}
/*
* 새로운 게시판 생성
*/
function kboard_new(){
$board = new KBoard();
$meta = $board->meta;
$skin = KBoardSkin::getInstance();
if(defined('KBOARD_COMMNETS_VERSION')){
include_once WP_CONTENT_DIR.'/plugins/kboard-comments/class/KBCommentSkin.class.php';
$comment_skin = KBCommentSkin::getInstance();
}
wp_enqueue_script('nested-sortable', KBOARD_URL_PATH . '/assets/nested-sortable/jquery.mjs.nestedSortable.js', array('jquery', 'jquery-ui-sortable'), '2.1a');
include_once 'pages/kboard_setting.php';
}
/*
* 게시판 목록 페이지
*/
function kboard_setting(){
$board_id = isset($_GET['board_id'])?$_GET['board_id']:'';
$board = new KBoard($board_id);
$meta = $board->meta;
$skin = KBoardSkin::getInstance();
if(defined('KBOARD_COMMNETS_VERSION')){
include_once WP_CONTENT_DIR.'/plugins/kboard-comments/class/KBCommentSkin.class.php';
$comment_skin = KBCommentSkin::getInstance();
}
wp_enqueue_script('nested-sortable', KBOARD_URL_PATH . '/assets/nested-sortable/jquery.mjs.nestedSortable.js', array('jquery', 'jquery-ui-sortable'), '2.1a');
include_once 'pages/kboard_setting.php';
}
/*
* 최신글 뷰
*/
function kboard_latestview(){
if(isset($_GET['latestview_uid']) && $_GET['latestview_uid']){
$skin = KBoardSkin::getInstance();
$latestview = new KBLatestview();
$latestview->initWithUID($_GET['latestview_uid']);
$linked_board = $latestview->getLinkedBoard();
$board_list = new KBoardList();
include_once 'pages/kboard_latestview_setting.php';
}
else{
include_once 'class/KBLatestviewListTable.class.php';
$table = new KBLatestviewListTable();
if(isset($_POST['latestview_uid']) && $table->current_action() == 'delete'){
$latestview = new KBLatestview();
foreach($_POST['latestview_uid'] as $key=>$latestview_uid){
$latestview->initWithUID($latestview_uid);
$latestview->delete();
}
}
$table->prepare_items();
include_once 'pages/kboard_latestview.php';
}
}
/*
* 최신글 뷰 생성
*/
function kboard_latestview_new(){
$skin = KBoardSkin::getInstance();
$latestview = new KBLatestview();
$linked_board = $latestview->getLinkedBoard();
$board_list = new KBoardList();
include_once 'pages/kboard_latestview_setting.php';
}
/*
* 게시판 백업 및 복구 페이지
*/
function kboard_backup(){
include_once 'pages/kboard_backup.php';
}
/*
* 플러그인 업데이트 페이지
*/
function kboard_updates(){
$action = isset($_GET['action'])?kboard_htmlclear($_GET['action']):'';
$download_url = isset($_GET['download_url'])?kboard_htmlclear($_GET['download_url']):'';
$download_version = isset($_GET['download_version'])?kboard_htmlclear($_GET['download_version']):'';
$form_url = wp_nonce_url(admin_url("admin.php?page=kboard_updates&action={$action}" . ($download_url?"&download_url=$download_url":'') . ($download_version?"&download_version=$download_version":'')), 'kboard_updates');
$upgrader = KBUpgrader::getInstance();
if($action == 'kboard'){
if(!$upgrader->credentials($form_url, WP_CONTENT_DIR . KBUpgrader::$TYPE_PLUGINS)) exit;
echo "<h1>KBoard 게시판 플러그인 설치</h1>";
@ob_flush();
@flush();
echo "<p>다운로드 중입니다. 기다려주세요.</p>";
@ob_flush();
@flush();
$download_file = $upgrader->getKBoard();
echo "<p>다운로드를 완료했습니다.</p>";
@ob_flush();
@flush();
$install_result = $upgrader->install($download_file, KBUpgrader::$TYPE_PLUGINS);
echo "<p>설치를 완료했습니다.</p>";
@ob_flush();
@flush();
echo "<p>KBoard 게시판 플러그인 설치가 완료 되었습니다.</p>";
@ob_flush();
@flush();
echo "<p><a href=\"" . admin_url('admin.php?page=kboard_updates') . "\" class=\"button\">업데이트 메뉴로 이동</a></p>";
@ob_flush();
@flush();
exit;
}
if($action == 'kboard-noskins'){
if(!$upgrader->credentials($form_url, WP_CONTENT_DIR . KBUpgrader::$TYPE_PLUGINS)) exit;
echo "<h1>KBoard 게시판 플러그인 설치</h1>";
@ob_flush();
@flush();
echo "<p>다운로드 중입니다. 기다려주세요.</p>";
@ob_flush();
@flush();
$download_file = $upgrader->getKBoardNoSkins();
echo "<p>다운로드를 완료했습니다.</p>";
@ob_flush();
@flush();
$install_result = $upgrader->install($download_file, KBUpgrader::$TYPE_PLUGINS);
echo "<p>설치를 완료했습니다.</p>";
@ob_flush();
@flush();
echo "<p>KBoard 게시판 플러그인 설치가 완료 되었습니다.</p>";
@ob_flush();
@flush();
echo "<p><a href=\"" . admin_url('admin.php?page=kboard_updates') . "\" class=\"button\">업데이트 메뉴로 이동</a></p>";
@ob_flush();
@flush();
exit;
}
else if($action == 'comments'){
if(!$upgrader->credentials($form_url, WP_CONTENT_DIR . KBUpgrader::$TYPE_PLUGINS)) exit;
echo "<h1>KBoard 댓글 플러그인 설치</h1>";
@ob_flush();
@flush();
echo "<p>다운로드 중입니다. 기다려주세요.</p>";
@ob_flush();
@flush();
$download_file = $upgrader->getComments();
echo "<p>다운로드를 완료했습니다.</p>";
@ob_flush();
@flush();
$install_result = $upgrader->install($download_file, KBUpgrader::$TYPE_PLUGINS);
echo "<p>설치를 완료했습니다.</p>";
@ob_flush();
@flush();
echo "<p>KBoard 댓글 플러그인 설치가 완료 되었습니다.</p>";
@ob_flush();
@flush();
echo "<p><a href=\"" . admin_url('admin.php?page=kboard_updates') . "\" class=\"button\">업데이트 메뉴로 이동</a></p>";
@ob_flush();
@flush();
exit;
}
else if($action == 'comments-noskins'){
if(!$upgrader->credentials($form_url, WP_CONTENT_DIR . KBUpgrader::$TYPE_PLUGINS)) exit;
echo "<h1>KBoard 댓글 플러그인 설치</h1>";
@ob_flush();
@flush();
echo "<p>다운로드 중입니다. 기다려주세요.</p>";
@ob_flush();
@flush();
$download_file = $upgrader->getCommentsNoSkins();
echo "<p>다운로드를 완료했습니다.</p>";
@ob_flush();
@flush();
$install_result = $upgrader->install($download_file, KBUpgrader::$TYPE_PLUGINS);
echo "<p>설치를 완료했습니다.</p>";
@ob_flush();
@flush();
echo "<p>KBoard 댓글 플러그인 설치가 완료 되었습니다.</p>";
@ob_flush();
@flush();
echo "<p><a href=\"" . admin_url('admin.php?page=kboard_updates') . "\" class=\"button\">업데이트 메뉴로 이동</a></p>";
@ob_flush();
@flush();
exit;
}
else if($action == 'plugin'){
if(!$upgrader->credentials($form_url, WP_CONTENT_DIR . KBUpgrader::$TYPE_PLUGINS)) exit;
echo "<h1>플러그인 설치</h1>";
@ob_flush();
@flush();
echo "<p>다운로드 중입니다. 기다려주세요.</p>";
@ob_flush();
@flush();
$download_file = $upgrader->download($download_url, $download_version, KBStore::getAccessToken());
echo "<p>다운로드를 완료했습니다.</p>";
@ob_flush();
@flush();
$install_result = $upgrader->install($download_file, KBUpgrader::$TYPE_PLUGINS);
echo "<p>설치를 완료했습니다.</p>";
@ob_flush();
@flush();
echo "<p>플러그인 설치가 완료 되었습니다. 플러그인을 활성화해주세요.</p>";
@ob_flush();
@flush();
echo "<p><a href=\"" . admin_url('plugins.php') . "\" class=\"button\">플러그인 메뉴로 이동</a></p>";
@ob_flush();
@flush();
exit;
}
else if($action == 'theme'){
if(!$upgrader->credentials($form_url, WP_CONTENT_DIR . KBUpgrader::$TYPE_THEMES)) exit;
echo "<h1>테마 설치</h1>";
@ob_flush();
@flush();
echo "<p>다운로드 중입니다. 기다려주세요.</p>";
@ob_flush();
@flush();
$download_file = $upgrader->download($download_url, $download_version, KBStore::getAccessToken());
echo "<p>다운로드를 완료했습니다.</p>";
@ob_flush();
@flush();
$install_result = $upgrader->install($download_file, KBUpgrader::$TYPE_THEMES);
echo "<p>설치를 완료했습니다.</p>";
@ob_flush();
@flush();
echo "<p>테마 설치가 완료 되었습니다. 테마를 선택해주세요.</p>";
@ob_flush();
@flush();
echo "<p><a href=\"" . admin_url('themes.php') . "\" class=\"button\">테마 메뉴로 이동</a></p>";
@ob_flush();
@flush();
exit;
}
else if($action == 'kboard-skin'){
if(!$upgrader->credentials($form_url, WP_CONTENT_DIR . KBUpgrader::$TYPE_KBOARD_SKIN)) exit;
echo "<h1>KBoard 게시판 스킨 설치</h1>";
@ob_flush();
@flush();
echo "<p>다운로드 중입니다. 기다려주세요.</p>";
@ob_flush();
@flush();
$download_file = $upgrader->download($download_url, $download_version, KBStore::getAccessToken());
echo "<p>다운로드를 완료했습니다.</p>";
@ob_flush();
@flush();
$install_result = $upgrader->install($download_file, KBUpgrader::$TYPE_KBOARD_SKIN);
echo "<p>설치를 완료했습니다.</p>";
@ob_flush();
@flush();
echo "<p>게시판 스킨 설치가 완료 되었습니다. <code>KBoard -> 게시판 목록 -> 게시판 선택 -> 게시판 관리</code> 페이지에서 스킨을 선택해주세요.</p>";
@ob_flush();
@flush();
echo "<p><a href=\"" . admin_url('admin.php?page=kboard_store') . "\" class=\"button\">스토어 메뉴로 이동</a></p>";
@ob_flush();
@flush();
exit;
}
else if($action == 'comments-skin'){
if(!$upgrader->credentials($form_url, WP_CONTENT_DIR . KBUpgrader::$TYPE_COMMENTS_SKIN)) exit;
echo "<h1>KBoard 댓글 스킨 설치</h1>";
@ob_flush();
@flush();
echo "<p>다운로드 중입니다. 기다려주세요.</p>";
@ob_flush();
@flush();
$download_file = $upgrader->download($download_url, $download_version, KBStore::getAccessToken());
echo "<p>다운로드를 완료했습니다.</p>";
@ob_flush();
@flush();
$install_result = $upgrader->install($download_file, KBUpgrader::$TYPE_COMMENTS_SKIN);
echo "<p>설치를 완료했습니다.</p>";
@ob_flush();
@flush();
echo "<p>댓글 스킨 설치가 완료 되었습니다. <code>KBoard -> 게시판 목록 -> 게시판 선택 -> 게시판 관리</code> 페이지에서 스킨을 선택해주세요.</p>";
@ob_flush();
@flush();
echo "<p><a href=\"" . admin_url('admin.php?page=kboard_store') . "\" class=\"button\">스토어 메뉴로 이동</a></p>";
@ob_flush();
@flush();
exit;
}
$upgrader->flush();
$version = $upgrader->getLatestVersion();
include_once 'pages/kboard_updates.php';
}
/*
* 전체 게시글 리스트
*/
function kboard_content_list(){
include_once 'class/KBContentListTable.class.php';
$table = new KBContentListTable();
if(isset($_POST['uid'])){
$action = $table->current_action();
$content = new KBContent();
if($action == 'delete'){
foreach($_POST['uid'] as $key=>$value){
$content->initWithUID($value);
$content->remove();
}
}
else if($action == 'trash'){
foreach($_POST['uid'] as $key=>$value){
$content->initWithUID($value);
$content->status = 'trash';
$content->updateContent();
}
}
else if($action == 'published'){
foreach($_POST['uid'] as $key=>$value){
$content->initWithUID($value);
$content->status = '';
$content->updateContent();
}
}
}
$table->prepare_items();
wp_enqueue_style('jquery-flick-style', KBOARD_URL_PATH.'/template/css/jquery-ui.css', array(), '1.12.1');
wp_enqueue_style('jquery-timepicker', KBOARD_URL_PATH.'/template/css/jquery.timepicker.css', array(), KBOARD_VERSION);
include_once 'pages/kboard_content_list.php';
}
/*
* 관리자 페이지에서 게시판 보기
*/
function kboard_admin_view(){
$screen = get_current_screen();
$board_id = intval(str_replace('kboard_page_kboard_admin_view_', '', $screen->id));
$board = new KBoard($board_id);
include_once 'pages/kboard_admin_view.php';
}
/*
* 게시판 디비 변경
*/
add_action('kboard_switch_to_blog', 'kboard_switch_to_blog', 0, 1);
function kboard_switch_to_blog($args=array()){
if(isset($args['blog']) && $args['blog']){
switch_to_blog($args['blog']);
}
else if(isset($_SESSION['kboard_switch_to_blog']) && $_SESSION['kboard_switch_to_blog']){
switch_to_blog($_SESSION['kboard_switch_to_blog']);
}
}
/*
* 게시판 디비 복구
*/
add_action('kboard_restore_current_blog', 'kboard_restore_current_blog', 9999, 1);
function kboard_restore_current_blog($args=array()){
if(isset($args['blog']) && $args['blog']){
restore_current_blog();
}
else if(isset($_SESSION['kboard_switch_to_blog']) && $_SESSION['kboard_switch_to_blog']){
restore_current_blog();
}
}
/*
* 게시판 생성 숏코드
*/
add_shortcode('kboard', 'kboard_builder');
function kboard_builder($args){
if(!isset($args['id']) || !$args['id']) return 'KBoard 알림 :: id=null, 아이디값은 필수입니다.';
if(isset($args['blog']) && $args['blog']){
$_SESSION['kboard_switch_to_blog'] = $args['blog'];
do_action('kboard_switch_to_blog', $args);
}
else{
$_SESSION['kboard_switch_to_blog'] = '';
}
$board = new KBoard();
$board->setID($args['id']);
if($board->id){
$builder = new KBoardBuilder($board->id);
$builder->board = $board;
$builder->setSkin($board->skin);
$builder->setRpp($board->page_rpp);
if(isset($args['category1']) && $args['category1']){
$builder->category1 = $args['category1'];
}
if(isset($args['category2']) && $args['category2']){
$builder->category2 = $args['category2'];
}
$kboard = $builder->create();
if(isset($args['blog']) && $args['blog']){
do_action('kboard_restore_current_blog', $args);
}
return $kboard;
}
else{
if(isset($args['blog']) && $args['blog']){
do_action('kboard_restore_current_blog', $args);
}
return 'KBoard 알림 :: id='.$args['id'].', 생성되지 않은 게시판입니다.';
}
}
/*
* 선택된 페이지에 자동으로 게시판 생성
*/
add_filter('the_content', 'kboard_auto_builder');
function kboard_auto_builder($content){
global $post, $wpdb;
if(isset($post->ID) && is_page($post->ID) && !post_password_required()){
$board_id = $wpdb->get_var("SELECT `board_id` FROM `{$wpdb->prefix}kboard_board_meta` WHERE `key`='auto_page' AND `value`='$post->ID'");
if($board_id) return $content . kboard_builder(array('id'=>$board_id));
}
return $content;
}
/*
* 최신글 생성 숏코드
*/
add_shortcode('kboard_latest', 'kboard_latest_shortcode');
function kboard_latest_shortcode($args){
if(!isset($args['id']) || !$args['id']) return 'KBoard 알림 :: id=null, 아이디값은 필수입니다.';
if(!isset($args['url']) || !$args['url']) return 'KBoard 알림 :: url=null, 페이지 주소는 필수입니다.';
if(!isset($args['rpp']) || !$args['rpp']) $args['rpp'] = 5;
if(isset($args['blog']) && $args['blog']){
do_action('kboard_switch_to_blog', $args);
}
$board = new KBoard();
$board->setID($args['id']);
if($board->id){
$builder = new KBoardBuilder($board->id, true);
$builder->board = $board;
$builder->setSkin($board->skin);
$builder->setRpp($args['rpp']);
$builder->setURL($args['url']);
if(isset($args['sort']) && $args['sort']){
if(strpos($args['sort'], '|') !== false){
$sort = explode('|', $args['sort']);
$args['sort'] = reset($sort);
}
$builder->setSorting($args['sort']);
}
if(isset($args['category1']) && $args['category1']){
$builder->category1 = $args['category1'];
}
else{
$builder->category1 = '';
}
if(isset($args['category2']) && $args['category2']){
$builder->category2 = $args['category2'];
}
else{
$builder->category2 = '';
}
$with_notice = true;
if(isset($args['with_notice']) && $args['with_notice'] == 'false'){
$with_notice = false;
}
if(isset($args['dayofweek']) && $args['dayofweek']){
if(strpos($args['dayofweek'], '|') !== false){
$dayofweek = explode('|', $args['dayofweek']);
$args['dayofweek'] = reset($dayofweek);
}
$builder->setDayOfWeek($args['dayofweek']);
}
if(isset($args['within_days']) && $args['within_days']){
$within_days = intval($args['within_days']);
$builder->setWithinDays($within_days);
}
if(isset($args['random']) && $args['random'] == 'true'){
$builder->setRandom(true);
}
$args['type'] = 'latest';
$latest = $builder->createLatest($with_notice, $args);
if(isset($args['blog']) && $args['blog']){
do_action('kboard_restore_current_blog', $args);
}
return $latest;
}
else{
if(isset($args['blog']) && $args['blog']){
do_action('kboard_restore_current_blog', $args);
}
return 'KBoard 알림 :: id='.$args['id'].', 생성되지 않은 게시판입니다.';
}
}
/*
* 최신글 모아보기 생성 숏코드
*/
add_shortcode('kboard_latestview', 'kboard_latestview_shortcode');
function kboard_latestview_shortcode($args){
if(!isset($args['id']) || !$args['id']) return 'KBoard 알림 :: id=null, 아이디값은 필수입니다.';
if(isset($args['blog']) && $args['blog']){
do_action('kboard_switch_to_blog', $args);
}
$latestview = new KBLatestview($args['id']);
if($latestview->uid){
$builder = new KBoardBuilder($latestview->getLinkedBoard(), true);
$builder->board = new KBoard();
$builder->setSkin($latestview->skin);
$builder->setRpp($latestview->rpp);
$builder->setSorting($latestview->sort);
if(isset($args['category1']) && $args['category1']){
$builder->category1 = $args['category1'];
}
else{
$builder->category1 = '';
}
if(isset($args['category2']) && $args['category2']){
$builder->category2 = $args['category2'];
}
else{
$builder->category2 = '';
}
$with_notice = true;
if(isset($args['with_notice']) && $args['with_notice'] == 'false'){
$with_notice = false;
}
if(isset($args['dayofweek']) && $args['dayofweek']){
if(strpos($args['dayofweek'], '|') !== false){
$dayofweek = explode('|', $args['dayofweek']);
$args['dayofweek'] = reset($dayofweek);
}
$builder->setDayOfWeek($args['dayofweek']);
}
if(isset($args['within_days']) && $args['within_days']){
$within_days = intval($args['within_days']);
$builder->setWithinDays($within_days);
}
if(isset($args['random']) && $args['random'] == 'true'){
$builder->setRandom(true);
}
$args['type'] = 'latestview';
$latest = $builder->createLatest($with_notice, $args);
if(isset($args['blog']) && $args['blog']){
do_action('kboard_restore_current_blog', $args);
}
return $latest;
}
else{
if(isset($args['blog']) && $args['blog']){
do_action('kboard_restore_current_blog', $args);
}
return 'KBoard 알림 :: id='.$args['id'].', 생성되지 않은 최신글 뷰 입니다.';
}
}
/*
* 비동기 게시판 빌더
*/
add_action('wp_ajax_kboard_ajax_builder', 'kboard_ajax_builder');
add_action('wp_ajax_nopriv_kboard_ajax_builder', 'kboard_ajax_builder');
function kboard_ajax_builder(){
check_ajax_referer('kboard_ajax_security', 'security');
if(isset($_SESSION['kboard_board_id']) && $_SESSION['kboard_board_id']){
$board_id = intval($_SESSION['kboard_board_id']);
}
if(isset($_REQUEST['board_id']) && $_REQUEST['board_id']){
$board_id = intval($_REQUEST['board_id']);
}
$board = new KBoard();
$board->setID($board_id);
if($board->id){
$builder = new KBoardBuilder($board->id);
$builder->mod = 'list';
$builder->board = $board;
$builder->is_ajax = true;
$builder->view_iframe = $board->meta->view_iframe;
if(isset($_REQUEST['view_iframe'])){
$builder->view_iframe = $_REQUEST['view_iframe'] ? '1' : '';
}
if(isset($_REQUEST['rpp']) && $_REQUEST['rpp']){
$builder->setRpp($_REQUEST['rpp']);
}
else{
$builder->setRpp($board->page_rpp);
}
if(isset($_REQUEST['sort']) && $_REQUEST['sort']){
$sort = sanitize_key($_REQUEST['sort']);
$builder->setSorting($sort);
}
if(isset($_REQUEST['base_url']) && $_REQUEST['base_url']){
$builder->setURL($_REQUEST['base_url']);
}
else{
$builder->setURL(wp_get_referer());
}
if(isset($_REQUEST['skin']) && $_REQUEST['skin']){
$skin = sanitize_key($_REQUEST['skin']);
$builder->setSkin($skin);
}
else{
$builder->setSkin($board->skin);
}
$ajax_builder_type = 'array';
if(isset($_REQUEST['ajax_builder_type']) && in_array($_REQUEST['ajax_builder_type'], array('array', 'html'))){
$ajax_builder_type = $_REQUEST['ajax_builder_type'];
}
if($ajax_builder_type == 'array'){
wp_send_json(array('result'=>'success', 'data'=>$builder->getListArray()));
}
else if($ajax_builder_type == 'html'){
wp_send_json(array('result'=>'success', 'data'=>$builder->getListHTML()));
}
}