[이윰] 새로고침 없이 댓글을 달거나 삭제할 수 있는 ajax 댓글 시스템으로 교체하기
페이지 정보
shadow2fox
4,136 4 2
2018.12.11 14:35:15
짧은주소
-
https://yadolee.com/tip/602 주소복사
본문
새로고침 없이 댓글을 달거나 삭제할 수 있는 ajax 댓글 시스템으로 교체하기
| ajax 댓글 플러그인 v1.0 | https://sir.kr/g5_plugin/4972 |
상기 그누보드 링크를 참고해서 수정하였다.
1. 그누보드5/eyoom/user_program/board/delete_comment.skin.php 파일을 열어 다음과 수정한다.
만약 delete_comment.skin.php 파일이 없다면 UTF-8(BOM 없음) 인코딩으로 만들어서 진행한다.
수정 전
<?php
if (!defined('_GNUBOARD_')) exit;
// Your Program - Start
// Your Program - End
// 변수 할당하기 - /eyoom/inc/tpl.assign.php 파일 참조
$tpl->assign(array(
));
?>
수정 후
<?php
if (!defined('_GNUBOARD_')) exit;
// Your Program - Start
delete_cache_latest($bo_table);
echo G5_HTTP_BBS_URL.'/board.php?bo_table='.$bo_table.'&wr_id='.$write['wr_parent'];
exit;
// Your Program - End
// 변수 할당하기 - /eyoom/inc/tpl.assign.php 파일 참조
$tpl->assign(array(
));
?>
2. 그누보드5/eyoom/user_program/board/write_comment_update.skin.php 파일을 열어 다음과 수정한다.
만약 write_comment_update.skin.php 파일이 없다면 UTF-8(BOM 없음) 인코딩으로 만들어서 진행한다.
수정 전
<?php
if (!defined('_GNUBOARD_')) exit;
// Your Program - Start
// Your Program - End
// 변수 할당하기 - /eyoom/inc/tpl.assign.php 파일 참조
$tpl->assign(array(
));
?>
수정 후
<?php
if (!defined('_GNUBOARD_')) exit;
// Your Program - Start
delete_cache_latest($bo_table);
echo G5_HTTP_BBS_URL.'/board.php?bo_table='.$bo_table.'&wr_id='.$wr['wr_parent'].'#c_'.$comment_id;
exit;
// Your Program - End
// 변수 할당하기 - /eyoom/inc/tpl.assign.php 파일 참조
$tpl->assign(array(
));
?>
3. ajax 댓글 시스템을 사용할 스킨 폴더에 view_comment.skin.html 파일을 열어 다음과 같이 수정한다.
① onclick="return comment_delete();" 을 검색하여 다음과 같이 수정한다.
수정 전
onclick="return comment_delete();"
수정 후
onclick="return comment_delete(this);"
② <div class="view-comment"> 를 검색하여 다음과 같이 수정한다.
수정 전
<div class="view-comment">
수정 후
<div class="view-comment">
<ajaxcomment>
③ <!--{? eyoom_board.bo_use_cmt_infinite == '1'}--> 를 검색하여 다음과 같이 수정한다.
수정 전
<!--{? eyoom_board.bo_use_cmt_infinite == '1'}-->
수정 후
</ajaxcomment>
<!--{? eyoom_board.bo_use_cmt_infinite == '1'}-->
④ document.getElementById("btn_submit").disabled = "disabled"; 를 검색하여 다음과 같이 수정한다.
수정 전
document.getElementById("btn_submit").disabled = "disabled";
return true;
}
수정 후
document.getElementById("btn_submit").disabled = "disabled";
// ajax comment system
$.ajax({
url: f.action,
type: 'POST',
data: $(f).serialize(),
dataType: 'html',
})
.done(function(str) {
var tempDom = $('<output>').append($.parseHTML(str))
var title = $('title', tempDom).text()
if (title === '') {
// 1. commentBox 원위치
comment_box('', 'c')
// 2. commentBox Form 리셋
f.reset()
// 3. 코멘트 출력
$.ajax({
url: str,
type: 'GET',
dataType: 'html'
})
.done(function(str2) {
var tempDom2 = $('<output>').append($.parseHTML(str2))
$('ajaxcomment').replaceWith($('ajaxcomment', tempDom2))
})
}
<?php if ($is_guest) { ?>
// 4. 캡차 리로드
$('#captcha_reload').trigger('click')
<?php } ?>
document.getElementById("btn_submit").disabled = ""
})
return false;
}
⑤ function comment_delete() 를 검색하여 다음과 같이 수정한다.
수정 전
function comment_delete()
{
return confirm("이 댓글을 삭제하시겠습니까?");
}
수정 후
function comment_delete(that)
{
if (confirm('이 댓글을 삭제하시겠습니까?')) {
// ajax comment system
$.ajax({
url: that.href,
type: 'GET',
dataType: 'html',
})
.done(function(str) {
var tempDom = $('<output>').append($.parseHTML(str))
var title = $('title', tempDom).text()
if (title === '') {
// 1. commentBox 원위치
comment_box('', 'c')
// 2. 코멘트 출력
$.ajax({
url: str,
type: 'GET',
dataType: 'html'
})
.done(function(str2) {
var tempDom2 = $('<output>').append($.parseHTML(str2))
$('ajaxcomment').replaceWith($('ajaxcomment', tempDom2))
})
}
<?php if ($is_guest) { ?>
// 4. 캡차 리로드
$('#captcha_reload').trigger('click')
<?php } ?>
})
}
return false
}
추천인 2
레벨 149
경험치 3,343,659
Progress Bar 80.23%
- 가입일 : 2015-03-10 12:21:44
- 서명 : 인간에게 가장 큰 선물은
자기 자신에게 기회를 주는 것이다.
- 크리스 가드너, Chris Gardner -
- 자기소개 : There's never a shortcut to happiness.


댓글4
하늘구장님의 댓글
shadow2fox님의 댓글
내사랑님의 댓글
축하합니다. 첫 댓글로 74경험치를 획득하였습니다.
shadow2fox님의 댓글