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

페이지 정보

shadow2fox shadow2fox 3,878 4 2 2018.12.11 14:35:15

평점

  • 평점 : 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
  • 012i1052u
    내사랑
  • skyfield4u
    하늘구장
shadow2fox
10
shadow2fox - 회원등급 : 자연/Level 147 - 포인트 : 2,613,648
레벨 147
경험치 3,240,032

Progress Bar 47.02%

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

댓글4

하늘구장님의 댓글

skyfield4u
하늘구장 2018.12.11 20:08
와!! 대박 감사합니다 늘 이건 부러운 기능이였는데 이제서야 감격

shadow2fox님의 댓글

1/26
shadow2fox
shadow2fox 글쓴이 @하늘구장 2018.12.11 20:20
모두가 하나씩 발전했으면 좋겠습니다 서로가 윈윈

내사랑님의 댓글

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

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

shadow2fox님의 댓글

1/26
shadow2fox
shadow2fox 글쓴이 @내사랑 2018.12.11 20:20
잘 사용하세요

Total 24239 페이지

제목 글쓴이 날짜 조회 추천
이윰  🏆 이윰빌더 최신글 본문 추출시 엔터, 띄어쓰기 태그를 스페이스(한 칸 띄우기)로 바꾸기 shadow2fox 2018.07.12 2,168 0
이윰  🏆 이윰 조건문 변수 모음 루루아빠 2015.04.23 2,937 0
이윰  🏆 EBL Respond·Memo·Connect 최신글 스킨 배포 루루아빠 2015.05.23 3,010 0
이윰  🏆 이윰빌더 1.1.4 패치 루루아빠 2015.06.08 3,511 0
이윰  🏆 사운드클라우드와 게시글 정보와의 간격 조정 루루아빠 2015.06.28 3,882 0
이윰  댓글+1🏆 게시판 본문 보기시 제목 글자 수 늘리기 루루아빠 2015.08.06 3,238 0
이윰  🏆 SNS 아이콘 툴팁 추가와 효과 바꾸기 루루아빠 2015.10.01 3,812 0
이윰  댓글+1🏆 이미지 리사이징 기능 끄기 (큰 이미지가 커졌다가 작아지는 문제 해결) 루루아빠 2015.12.18 4,327 0
이윰  댓글+1🏆 SELF-HOSTED로 Jwplayer7.x 사용시 외부 링크(jwpcdn.com)에서 스킨 가져오는 문제 루루아빠 2016.05.11 4,218 0
이윰  🏆 INDEX 화면을 특정 게시판으로 변경하기 루루아빠 2016.11.06 4,098 0
이윰  🏆 Eyoom Builder 1.3.2 패치 루루아빠 2017.11.21 2,755 0
이윰  🏆 Eyoom Builder 1.3.14 패치 루루아빠 2017.12.17 3,677 0
이윰  🏆 최신 브라우저에서 푸시 사운드 문제 해결하기 shadow2fox 2018.07.20 2,191 0
이윰  댓글+1🏆 Eyoom Builder 1.1.1 패치 루루아빠 2015.05.24 3,052 0
이윰  댓글+1🏆 게시판 리스트에 무한스크롤 기능 패치 루루아빠 2015.06.08 4,740 0
이윰  댓글+1🏆 최신글 랜덤으로 뽑기 루루아빠 2015.06.29 3,643 0
이윰  댓글+1🏆 카테고리를 사용하는 게시판에서 무한스크롤 사용시 루루아빠 2015.08.07 3,330 0
이윰  🏆 syntaxhighlighter 관련 오류 수정 및 테마 변경 루루아빠 2015.10.01 3,451 0
이윰  🏆 Eyoom Builder 1.2.0 패치 루루아빠 2015.12.21 3,169 0
이윰  🏆 게시글 본문에 태그가 포함된 경우 검색시 그대로 노출되는 문제 해결 루루아빠 2016.05.13 2,616 0
이윰  🏆 블로그 스킨(masonry)에서 Lazy Load(unveil) 사용시 목록 올바르게 보여 주기 루루아빠 2016.11.16 2,840 0
이윰  🏆 Eyoom Builder 1.3.3 패치 루루아빠 2017.11.21 2,499 0
이윰  🏆 Eyoom Builder 1.3.15 패치 루루아빠 2018.01.05 2,698 0
이윰  🏆 유튜브 재생목록(플레이리스트)이 적용되지 않는다면 shadow2fox 2018.07.29 2,351 0
이윰  🏆 메인일때만 사이드 레이아웃을 없애기 루루아빠 2015.04.24 2,817 0
이윰  댓글+1🏆 게시글 제목과 상단과의 간격 조정 루루아빠 2015.05.27 2,852 0
이윰  🏆 짧은 글 주소에 댓글에 표시되지 않는 버그 패치 루루아빠 2015.06.08 3,657 0
이윰  🏆 Eyoom Builder 1.1.7 패치 루루아빠 2015.07.06 3,189 0
이윰  🏆 댓글에 이미지가 추가된 댓글을 수정할 경우 이미지가 삭제되는 버그 패치 루루아빠 2015.08.07 3,095 0
이윰  🏆 Eyoom Builder 1.1.10 패치 루루아빠 2015.10.06 3,101 0