글 추천 시 댓글입력 하려면
본문
글 추천 시 댓글이 달리게 하고싶은데
/bbs/good.php에 내용을 추가하면 될것같은데
아무리해도 작동을 안하네요..
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 = '이 글을 추천합니다.',
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 {$g5['write_prefix']}{$bo_table} set wr_{$good} = wr_{$good} + 1 where wr_id = '{$wr_id}' ");
// 내역 생성
sql_query(" insert {$g5['board_good_table']} set bo_table = '{$bo_table}', wr_id = '{$wr_id}', mb_id = '{$member['mb_id']}', bg_flag = '{$good}', bg_datetime = '".G5_TIME_YMDHIS."' ");
$sql = " select wr_{$good} as count from {$g5['write_prefix']}{$bo_table} where wr_id = '$wr_id' ";
$row = sql_fetch($sql);
$count = $row['count'];
run_event('bbs_increase_good_json', $bo_table, $wr_id, $good);
print_result($error, $count);
이렇게 입력하였습니다.
답변 4
good.tail.skin.php
아래와 같이 생성 후 업로드하고 테스트해보세요.
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if ($good == 'good') {
$wr_write = get_write($write_table, $wr_id);
$wr_write_password = sql_password($g5['server_time']);
$wr_write_mbid = $member['mb_id'];
$mb = get_member($member['mb_id']);
$sql = " insert into $write_table
set ca_name = '$wr_write[ca_name]',
wr_num = '$wr_write[wr_num]',
wr_parent = '$wr_id',
wr_is_comment = '1',
wr_comment = '1',
wr_content = '이 글을 추천합니다.',
mb_id = '$wr_write_mbid',
wr_password = '$wr_write_password',
wr_name = '".$mb['mb_nick']."',
wr_datetime = '".G5_TIME_YMDHIS."',
wr_ip = '000.000.000.000' ";
sql_query($sql);
// 원글에 코멘트수 증가
sql_query(" update $write_table set wr_comment = wr_comment + 1 where wr_id = '$wr_id' ");
// 코멘트 1 증가
sql_query(" update $g5[board_table] set bo_count_comment = bo_count_comment + 1 where bo_table = '$bo_table' ");
}
?>
등록은 잘될겁니다.
문제는 그누보드 원본이 추천시 페이지 새로고침이 안되므로 새로고침 해야 댓글이 보입니다. !-->
// 내역 생성 부분에서
해당 테이블에 댓글이 저장되도록 하시면 될듯 합니다.
write_update.php 에 댓글 저장 부분을 참고 하시면 됩니다.
다음과 같은 방법으로 시도해 볼 수 있을 것 같습니다.
참고하셔서 원하시는 형태로 구현하시면 되지 않을까 합니다.
function add_comment_on_good($bo_table, $wr_id, $mb_id = "", $wr_name = "") {
global $g5, $config, $member;
$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; // 글이 존재하지 않음
}
// 댓글 내용 설정
$wr_content = '이 글을 추천합니다.'; // 댓글 내용을 원하는 내용으로 변경
// 댓글 데이터 삽입
$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_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 {$g5['write_prefix']}{$bo_table} SET wr_good = wr_good + 1 WHERE wr_id = '$wr_id'");
// 내역 생성
sql_query("INSERT INTO {$g5['board_good_table']} SET bo_table = '{$bo_table}', wr_id = '{$wr_id}', mb_id = '{$member['mb_id']}', bg_flag = 'good', bg_datetime = '".G5_TIME_YMDHIS."'");
// 추천(찬성) 수 조회
$sql = "SELECT wr_good AS count FROM {$g5['write_prefix']}{$bo_table} WHERE wr_id = '$wr_id'";
$row = sql_fetch($sql);
$count = $row['count'];
run_event('bbs_increase_good_json', $bo_table, $wr_id, 'good');
return $count;
}
// 함수를 호출하여 글 추천과 댓글 추가 수행
$bo_table = 'your_board_table'; // 게시판 테이블명 설정
$wr_id = 123; // 글 ID 설정
$mb_id = 'user123'; // 사용자 아이디 설정
$wr_name = 'User Name'; // 사용자 이름 설정
$good_count = add_comment_on_good($bo_table, $wr_id, $mb_id, $wr_name);
if ($good_count > 0) {
echo "글 추천과 댓글이 성공적으로 추가되었습니다. 추천 수: $good_count";
} else {
echo "글 추천 및 댓글 추가에 실패했습니다.";
}
쿼리문제겠네요
DB에 안들어간다는걸테니까
쿼리부분 하나씩 찍어보면서 빈값 채우면 들어갈거같습니다.