게시물 코멘트 등록함수 정보
게시물 코멘트 등록함수본문
이전에 작성한 게시판 파싱후 글등록 처리 함수 에 연결된 팁입니다.
코멘트 등록함수 입니다. 작성자 아이디와, 작성자 이름이 unknown 으로 들어갑니다.
특정 사용자로 작성자를 지정할려면 함수 호출시 파라메타로 넘겨주세요.
/**
* 그누보드 게시물 코멘트 등록 함수.
* 그누보드의 게시판 코멘트 등록파일(write_comment_update.php) 로직을 참고하였습니다.
* depth 처리는 없습니다. 0단계만 적용
* @param $bo_table 게시판판명 ex)humor
* @param $wr_id 게시물 번호
* @param $wr_content 코멘트 내용
* @param string $mb_id 코멘트 작성자 아이디
* @param string $wr_name 코멘트 작성자명
* @return int|string 등록완료시 등록된 코멘트아이디, 코멘트 등록실패시 0
*/
function board_comment_write($bo_table, $wr_id, $wr_content, $mb_id="", $wr_name = "") {
global $g5, $config;
$write_table = "g5_write_{$bo_table}";
if(!$mb_id) $mb_id = "unknown";
if(!$wr_name) $wr_name = "unknown";
$wr_email = "";
$wr = get_write($write_table, $wr_id);
if (empty($wr['wr_id'])) {
return 0;
}
// 090710
if (substr_count($wr_content, "") > 50) {
return 0;
}
$sql = " select max(wr_comment) as max_comment from $write_table
where wr_parent = '$wr_id' and wr_is_comment = 1 ";
$row = sql_fetch($sql);
//$row[max_comment] -= 1;
$row['max_comment'] += 1;
$tmp_comment = $row['max_comment'];
$tmp_comment_reply = '';
$sql = " insert into $write_table
set ca_name = '{$wr['ca_name']}',
wr_option = '',
wr_num = '{$wr['wr_num']}',
wr_reply = '',
wr_parent = '$wr_id',
wr_is_comment = 1,
wr_comment = '$tmp_comment',
wr_comment_reply = '$tmp_comment_reply',
wr_subject = '',
wr_content = '$wr_content',
mb_id = '$mb_id',
wr_password = '',
wr_name = '$wr_name',
wr_email = '$wr_email',
wr_datetime = '".G5_TIME_YMDHIS."',
wr_last = '',
wr_ip = '0.0.0.0'
";
sql_query($sql);
$comment_id = sql_insert_id();
// 원글에 댓글수 증가 & 마지막 시간 반영
sql_query(" update $write_table set wr_comment = wr_comment + 1, wr_last = '".G5_TIME_YMDHIS."' where wr_id = '$wr_id' ");
// 새글 INSERT
sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '$bo_table', '$comment_id', '$wr_id', '".G5_TIME_YMDHIS."', '{$member['mb_id']}' ) ");
// 댓글 1 증가
sql_query(" update {$g5['board_table']} set bo_count_comment = bo_count_comment + 1 where bo_table = '$bo_table' ");
delete_cache_latest($bo_table);
return $comment_id;
}
함수 호출 예제
$comment = "테스트입니다. time : ".date("H:m:s");
$comment_id = board_comment_write("humor", 100, $comment);
echo $comment. " , comment_id = $comment_id <br>";
추천
3
3
댓글 5개
유익한 정보 감사합니다.
감사합니다
감사합니다.
늦었지만 감사드려요 ^-^
추천 꾹 누르고 갈게요오~!
추천 꾹 누르고 갈게요오~!
안녕하세요! 좋은 코드 너무 감사드립니다! 궁금한 점이 있어요. 데이터를 크롤링하여 게시글에 저장하는 함수를 만들고 있습니다. 이 때 작성한 파이썬 코드파일을 그누보드에 실행하려면 주피터 노트북에서는 불가능하겠죠..? FTP로 해당 코드파일을 전송한 다음에 실행시켜야 하는건가요..? 그누보드가 처음이라 실행 방법을 모르겠습니다..ㅠㅠ