[이윰] 새로고침 없이 댓글을 달거나 삭제할 수 있는 ajax 댓글 시스템으로 교체하기

페이지 정보

shadow2fox 3,377 4 2 2018.12.11 14:35

평점

  • - 평점 : 5점 (2명 참여)

본문

새로고침 없이 댓글을 달거나 삭제할 수 있는 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
  • 내사랑
  • 하늘구장
10
shadow2fox - 회원등급 : 자연/Level 142 - 포인트 : 2,533,033
레벨 142
경험치 3,022,296

Progress Bar 45%

- 가입일 : 2015-03-10 12:21:44
- 서명 : 인간에게 가장 큰 선물은 자기 자신에게 기회를 주는 것이다. - 크리스 가드너, Chris Gardner -
- 자기소개 : There's never a shortcut to happiness.

댓글4

하늘구장님의 댓글

하늘구장 2018.12.11 20:08

와!! 대박 감사합니다 늘 이건 부러운 기능이였는데 이제서야 감격

shadow2fox님의 댓글

shadow2fox 글쓴이 @하늘구장 2018.12.11 20:20

모두가 하나씩 발전했으면 좋겠습니다 서로가 윈윈

내사랑님의 댓글

내사랑 2018.12.11 14:42

좀 전에 댓글을 달고서 보니 뭔가 달라졌다 싶었는데 이런 고급 정보가 감사 감사 베리 감사요 저녁에 수정해야겠어요 룰루랄라

축하합니다. 첫 댓글로 74경험치를 획득하였습니다.

shadow2fox님의 댓글

shadow2fox 글쓴이 @내사랑 2018.12.11 20:20

잘 사용하세요

Total 7431238 페이지
제목 글쓴이 날짜 조회 추천
JavaScript  🏆 현재창 아이프레임 유무 확인 shadow2fox 2018.12.26 1,670 0
그누•영카트  🏆 영카트 5.3.2.2 shadow2fox 2018.12.18 2,023 0
그누•영카트  🏆 그누보드 5.3.2.2 shadow2fox 2018.12.18 1,895 0
그누•영카트  🏆 영카트 5.3.2.1 패치 shadow2fox 2018.12.11 2,121 0
그누•영카트  🏆 그누보드 5.3.2.1 패치 shadow2fox 2018.12.11 1,865 0
jQuery  🏆 클릭 함수가 더블 클릭시에만 작동된다면 shadow2fox 2018.12.11 1,723 0
이윰  댓글+4🏆 🚩 새로고침 없이 댓글을 달거나 삭제할 수 있는 ajax 댓글 시스템으로 교체하기 shadow2fox 2018.12.11 3,378 2
이윰  댓글+2🏆 회원 프로필 사진 변경시 바로 갱신하여 보여 주기 shadow2fox 2018.12.04 2,365 0
이윰  🏆 마우스 오버시 이전글 다음글에 제목을 띄우기 shadow2fox 2018.11.27 2,008 0
그누•영카트  🏆 영카트 5.3.2.0 패치 shadow2fox 2018.11.22 1,893 0
그누•영카트  🏆 그누보드 5.3.2.0 패치 shadow2fox 2018.11.22 1,760 0
PHP  🏆 PHP Warning: Invalid argument supplied for foreach() 해결책 shadow2fox 2018.11.11 1,615 0
그누•영카트  🏆 영카트 5.3.1.9 패치 shadow2fox 2018.10.19 1,887 0
그누•영카트  🏆 그누보드 5.3.1.9 패치 shadow2fox 2018.10.19 5,496 0
이윰  🏆 Eyoom Builder 3.0.7 패치 shadow2fox 2018.10.15 2,205 0
그누•영카트  🏆 영카트 5.3.1.8 패치 shadow2fox 2018.10.15 2,121 0
그누•영카트  🏆 그누보드 5.3.1.8 패치 shadow2fox 2018.10.15 1,907 0
이윰  🏆 이윰빌더 시즌1 → 시즌4 업그레이드 가이드 shadow2fox 2018.10.05 2,323 0
이윰  🏆 Eyoom Builder 3.0.6 패치 shadow2fox 2018.09.18 2,222 0
그누•영카트  🏆 영카트 5.3.1.7 패치 shadow2fox 2018.09.18 2,070 0