You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
9.1 KiB

7 years ago
7 years ago
5 years ago
7 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
7 years ago
7 years ago
7 years ago
5 years ago
7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Board extends WB_Controller {
  4. function __construct()
  5. {
  6. parent::__construct();
  7. $this->load->library('boardlib');
  8. }
  9. /**
  10. * INDEX 페이지는 접근금지
  11. */
  12. function index()
  13. {
  14. alert(langs( 'board/msg/invalid_access' ));
  15. }
  16. /**
  17. * 게시판 보기 페이지
  18. * @param $brd_key
  19. * @param $post_idx
  20. */
  21. public function view($brd_key, $post_idx)
  22. {
  23. $this->board_common($brd_key, 'read');
  24. $this->boardlib->read_process($brd_key, $post_idx);
  25. }
  26. /**
  27. * 게시판 목록
  28. * @param $brd_key
  29. */
  30. public function lists($brd_key)
  31. {
  32. $this->board_common($brd_key, 'list');
  33. // 메타태그 설정
  34. $this->site->meta_title = $this->data['board']['brd_title'] . ' - ' . $this->data['page'] . '페이지'; // 이 페이지의 타이틀
  35. $this->site->meta_description = $this->data['board']['brd_description']; // 이 페이지의 요약 설명
  36. $this->site->meta_keywords = $this->data['board']['brd_keywords']; // 이 페이지에서 추가할 키워드 메타 태그
  37. $this->site->meta_image = ""; // 이 페이지에서 표시할 대표이미지
  38. // 레이아웃 & 뷰파일 설정
  39. $this->view = "list";
  40. $this->skin_type = "board/list";
  41. $this->skin = $this->data['board']['brd_skin_l'];
  42. }
  43. /**
  44. * 코멘트 등록/수정 처리
  45. * @param $brd_key
  46. * @param $post_idx
  47. * @param string $cmt_idx
  48. */
  49. public function comment($brd_key, $post_idx)
  50. {
  51. $this->board_common($brd_key,'comment');
  52. $this->boardlib->comment_process($brd_key, $post_idx);
  53. }
  54. /**
  55. * 코멘트 수정
  56. * @param string $cmt_idx
  57. */
  58. public function comment_modify($cmt_idx="")
  59. {
  60. if( ! $comment = $this->db->where('cmt_idx', $cmt_idx)->where('cmt_status', 'Y')->get('board_comment')->row_array() )
  61. {
  62. alert_close(langs('게시판/msg/invalid_comment'));
  63. exit;
  64. }
  65. $this->board_common($comment['brd_key']);
  66. $this->boardlib->comment_modify_form($cmt_idx,$comment);
  67. }
  68. /**
  69. * 댓글 삭제
  70. * @param $brd_key
  71. * @param $post_idx
  72. * @param $cmt_idx
  73. */
  74. public function comment_delete($brd_key, $post_idx, $cmt_idx)
  75. {
  76. $this->board_common($brd_key);
  77. $this->boardlib->comment_delete_process($brd_key, $post_idx, $cmt_idx);
  78. }
  79. /**********************************************************
  80. *
  81. * 게시판 암호 확인 페이지
  82. * @param string $brd_key
  83. * @param string $post_idx
  84. *
  85. *********************************************************/
  86. function password($brd_key="",$post_idx="")
  87. {
  88. $this->board_common($brd_key);
  89. // 폼검증 라이브러리 로드
  90. $this->load->library("form_validation");
  91. // 폼검증 규칙 설정
  92. $this->form_validation->set_rules("password", langs('게시판/form/password'), "trim|required|min_length[4]|max_length[16]");
  93. if( $this->form_validation->run() == FALSE )
  94. {
  95. $hidden = array("reurl"=>$this->input->get('reurl', TRUE));
  96. $action_url = base_url("board/{$brd_key}/password/{$post_idx}", SSL_VERFIY ? 'https':'http');
  97. $this->data['form_open'] = form_open($action_url,array("id"=>"form-post-password","data-form"=>"post-password-form"), $hidden);
  98. $this->data['form_close']= form_close();
  99. $this->view = "password";
  100. $this->skin_type = "board/view";
  101. $this->skin = $this->data['board']['brd_skin_v'];
  102. }
  103. else
  104. {
  105. $reurl = $this->input->post("reurl", TRUE, base_url("board/{$brd_key}/{$post_idx}") );
  106. $password = $this->input->post("password", TRUE);
  107. $post = $this->boardlib->get($brd_key, $post_idx);
  108. if( get_password_hash($password) == $post['mem_password'] )
  109. {
  110. $this->session->set_userdata('post_password_'.$post_idx, TRUE);
  111. redirect($reurl);
  112. exit;
  113. }
  114. else
  115. {
  116. alert( langs('게시판/msg/invalid_password') );
  117. exit;
  118. }
  119. }
  120. }
  121. /**
  122. * 글쓰기 페이지
  123. * @param $brd_key
  124. * @param string $post_idx
  125. */
  126. public function write($brd_key, $post_idx="")
  127. {
  128. $this->board_common($brd_key, 'write');
  129. $this->boardlib->write_process($brd_key, $post_idx);
  130. }
  131. /**
  132. * 첨부파일 다운로드 하기
  133. * @param $brd_key
  134. * @param $post_idx
  135. * @param $bmt_idx
  136. */
  137. public function download($brd_key, $post_idx, $att_idx)
  138. {
  139. if(empty($brd_key) OR empty($post_idx) OR empty($att_idx))
  140. {
  141. alert(langs( 'board/msg/invalid_access' ));
  142. }
  143. $this->board_common($brd_key, 'download');
  144. if(! $att = $this->db->where('att_idx', $att_idx)->where('att_target_type', 'BOARD')->where('att_target', $post_idx)->get('attach')->row_array())
  145. {
  146. alert(langs( 'board/msg/invalid_attach_file' ));
  147. exit;
  148. }
  149. $post = $this->boardlib->get_post($brd_key, $post_idx, TRUE);
  150. $this->point_process('brd_point_download', "POST_ATTACH_DOWNLOAD", "첨부파일 다운로드", $post_idx, ($post['reg_user'] == $this->member->info('idx')) );
  151. $this->db->where('att_idx', $att['att_idx'])->set('att_downloads', 'att_downloads + 1', FALSE)->update('attach');
  152. $this->load->helper('download');
  153. $data = file_get_contents(FCPATH.$att['att_filepath']);
  154. $name = urlencode($att['att_origin']);
  155. force_download($name, $data);
  156. }
  157. /**
  158. * 게시글 삭제
  159. * @param $brd_key
  160. * @param $post_idx
  161. */
  162. public function delete($brd_key, $post_idx)
  163. {
  164. $this->board_common($brd_key);
  165. $this->boardlib->_check_modify_auth($brd_key, $post_idx);
  166. $post = $this->boardlib->get($brd_key, $post_idx, FALSE);
  167. $len = strlen($post['post_reply']);
  168. if( $len < 0 ) $len = 0;
  169. $reply = substr($post['post_reply'], 0, $len);
  170. // 게시글에 답글이 달려있는경우 삭제할 수 없다
  171. $count = (int) $this->db->select('COUNT(*) AS cnt')
  172. ->where('post_idx <>', $post['post_idx'])
  173. ->where('post_num', $post['post_num'])
  174. ->where('brd_key', $post['brd_key'])
  175. ->like('post_reply', $reply, 'after')
  176. ->where_in('post_status',array('Y','B'))
  177. ->get('board_post')
  178. ->row(0)
  179. ->cnt;
  180. if( $count > 1 )
  181. {
  182. alert(langs('게시판/msg/cant_delete_because_child'));
  183. exit;
  184. }
  185. if( $this->db->where('post_idx', $post_idx)->set('post_status', 'N')->update('board_post') )
  186. {
  187. $this->boardlib->point_cancel("POST_WRITE", $post_idx, "게시글 삭제");
  188. alert( langs('게시판/msg/delete_success'), base_url("board/{$brd_key}") );
  189. exit;
  190. }
  191. else
  192. {
  193. alert( langs('게시판/msg/delete_failed') );
  194. exit;
  195. }
  196. }
  197. /**
  198. * 게시판마다 공통으로 불러오기
  199. * @param $brd_key
  200. * @param string $check_type
  201. */
  202. private function board_common($brd_key, $check_type="")
  203. {
  204. $this->boardlib->common_data($brd_key);
  205. if( $check_type && ! $this->data['board']['auth'][$check_type] )
  206. {
  207. $msg = langs('게시판/msg/list_unauthorize');;
  208. if( $check_type == 'write' ) $msg = langs('게시판/msg/write_unauthorize');
  209. else if ($check_type == 'view' || $check_type == 'read') $msg = langs('게시판/msg/read_unauthorize');
  210. else if ($check_type == 'download') $msg = langs('게시판/msg/download_unauthorize');
  211. else if ($check_type == 'reply') $msg = langs('게시판/msg/reply_unauthorize');
  212. else if ($check_type == 'comment') $msg = langs('게시판/msg/comment_unauthorize');
  213. alert($msg);
  214. exit;
  215. }
  216. $use_list = $check_type == 'list';
  217. $this->data['list'] = array(
  218. "list"=>array(),
  219. "total_count" => 0
  220. );
  221. $this->data['pagination'] = "";
  222. if( $use_list )
  223. {
  224. // 게시글 목록 가져오기
  225. $this->data['list'] = $this->boardlib->post_list($this->data['board'], $this->param);
  226. // 페이지네이션 세팅
  227. $paging['page'] = $this->param['page'];
  228. $paging['page_rows'] = $this->data['board']['brd_page_rows'];
  229. $paging['total_rows'] = $this->data['list']['total_count'];
  230. $paging['fixed_page_num'] = $this->data['board']['brd_fixed_num'];
  231. $this->load->library('paging', $paging);
  232. $this->data['pagination'] = $this->paging->create();
  233. }
  234. // 레이아웃 정의
  235. $this->theme = $this->site->get_layout();
  236. $this->skin_type = "board";
  237. $this->active = "board/".$this->data['board']['brd_key'];
  238. }
  239. }