알짜게시판

[그누보드] 훅을 통한 글쓰기, 댓글 알림

글, 댓글 작성시 텔레그램을 통해서 알려주는 소스입니다.
(훅을 이용하기 때문에 그누보드 5.4 이상 버전에서 사용 가능합니다.)

1. 메신저에 길호넷을 친구 추가해주세요.
(라인: @kilho / 텔레그램: @kilhobot)
kilho.png

2. 추가 후 채팅방에 "고유코드" 를 입력 후 받은 코드를 아래 고유코드에 수정 및 입력합니다.

3. 완성된 파일은 /extend/아무파일.php 로 저장하시면 됩니다.

[code]
/* 설명에 따라 설정값을 입력해주세요. */

/* 고유코드를 입력해주세요. */
$g5['chat_code'] = '고유코드';

/* 게시판에 새로운 글이 작성될 때 알림을 받고 싶으면 true, 아니면 false */
$g5['chat_notify_write'] = true;

/* 게시판에 새로운 코멘트가 작성될 때 알림을 받고 싶으면 true, 아니면 false */
$g5['chat_notify_write_comment'] = true;

/* 기능 구현 */
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

function kh_write_update_after($board, $wr_id, $w, $qstr, $redirect_url)
{
global $g5, $is_admin;

if(!$g5['chat_notify_write']) return;
if($is_admin == 'super') return;
if(in_array($w, array('u', 'cu'))) return;

$text = $w != 'c' ? '제목 : '.$_POST['wr_subject']."\n" : '댓글 : ';
$text .= cut_str(preg_replace('(\<(/?[^\>]+)\>)', "\n", $_POST['wr_content']), 80)."\n";
$text .= get_pretty_url($board['bo_table'], $wr_id);

SendMessage($g5['chat_code'], $text);
}
add_event('write_update_after', 'kh_write_update_after', G5_HOOK_DEFAULT_PRIORITY, 5);
add_event('comment_update_after', 'kh_write_update_after', G5_HOOK_DEFAULT_PRIORITY, 5);

function SendMessage($id, $text)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.kilho.net/chatbot');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('id'=>$id, 'text'=>$text)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
?>
[/code]
번호 제목 글쓴이 조회 날짜
게시물이 없습니다.
목록